Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmd/wsh/cmd/wshcmd-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,6 @@ func fileCpRun(cmd *cobra.Command, args []string) error {

func fileMvRun(cmd *cobra.Command, args []string) error {
src, dst := args[0], args[1]
recursive, err := cmd.Flags().GetBool("recursive")
if err != nil {
return err
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
Expand All @@ -435,9 +431,9 @@ func fileMvRun(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("unable to parse dest path: %w", err)
}
log.Printf("Moving %s to %s; recursive: %v, force: %v", srcPath, destPath, recursive, force)
log.Printf("Moving %s to %s; force: %v", srcPath, destPath, force)
rpcOpts := &wshrpc.RpcOpts{Timeout: TimeoutYear}
err = wshclient.FileMoveCommand(RpcClient, wshrpc.CommandFileCopyData{SrcUri: srcPath, DestUri: destPath, Opts: &wshrpc.FileCopyOpts{Overwrite: force, Timeout: TimeoutYear, Recursive: recursive}}, rpcOpts)
err = wshclient.FileMoveCommand(RpcClient, wshrpc.CommandFileCopyData{SrcUri: srcPath, DestUri: destPath, Opts: &wshrpc.FileCopyOpts{Overwrite: force, Timeout: TimeoutYear}}, rpcOpts)
if err != nil {
return fmt.Errorf("moving file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/store/wshclientapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class RpcApiType {
}

// command "remotefilecopy" [call]
RemoteFileCopyCommand(client: WshClient, data: CommandFileCopyData, opts?: RpcOpts): Promise<void> {
RemoteFileCopyCommand(client: WshClient, data: CommandFileCopyData, opts?: RpcOpts): Promise<boolean> {
return client.wshRpcCall("remotefilecopy", data, opts);
}

Expand Down
14 changes: 9 additions & 5 deletions frontend/app/view/preview/directorypreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type FileCopyStatus = {

declare module "@tanstack/react-table" {
interface TableMeta<TData extends RowData> {
updateName: (path: string) => void;
updateName: (path: string, isDir: boolean) => void;
newFile: () => void;
newDirectory: () => void;
}
Expand Down Expand Up @@ -291,7 +291,7 @@ function DirectoryTable({

const setEntryManagerProps = useSetAtom(entryManagerOverlayPropsAtom);

const updateName = useCallback((path: string) => {
const updateName = useCallback((path: string, isDir: boolean) => {
const fileName = path.split("/").at(-1);
setEntryManagerProps({
entryManagerType: EntryManagerType.EditName,
Expand All @@ -304,8 +304,12 @@ function DirectoryTable({
console.log(`replacing ${fileName} with ${newName}: ${path}`);
fireAndForget(async () => {
try {
let srcuri = await model.formatRemoteUri(path, globalStore.get);
if (isDir) {
srcuri += "/";
}
await RpcApi.FileMoveCommand(TabRpcClient, {
srcuri: await model.formatRemoteUri(path, globalStore.get),
srcuri,
desturi: await model.formatRemoteUri(newPath, globalStore.get),
opts: {
recursive: true,
Expand Down Expand Up @@ -547,7 +551,7 @@ function TableBody({
{
label: "Rename",
click: () => {
table.options.meta.updateName(finfo.path);
table.options.meta.updateName(finfo.path, finfo.isdir);
},
},
{
Expand Down Expand Up @@ -854,7 +858,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
});

const handleDropCopy = useCallback(
async (data: CommandFileCopyData, isDir) => {
async (data: CommandFileCopyData, isDir: boolean) => {
try {
await RpcApi.FileCopyCommand(TabRpcClient, data, { timeout: data.opts.timeout });
setCopyStatus(null);
Expand Down
1 change: 0 additions & 1 deletion frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ declare global {
// wshrpc.FileCopyOpts
type FileCopyOpts = {
overwrite?: boolean;
recursive?: boolean;
merge?: boolean;
timeout?: number;
};
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/wavetermdev/htmltoken v0.2.0
golang.org/x/crypto v0.33.0
golang.org/x/mod v0.23.0
golang.org/x/sync v0.11.0
Comment thread
esimkowitz marked this conversation as resolved.
golang.org/x/sys v0.30.0
golang.org/x/term v0.29.0
google.golang.org/api v0.221.0
Expand Down Expand Up @@ -95,7 +96,6 @@ require (
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/oauth2 v0.26.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.10.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
Expand Down
18 changes: 6 additions & 12 deletions pkg/remote/fileshare/fileshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,11 @@ func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error {
return fmt.Errorf("error creating fileshare client, could not parse destination connection %s", data.DestUri)
}
if srcConn.Host != destConn.Host {
finfo, err := srcClient.Stat(ctx, srcConn)
if err != nil {
return fmt.Errorf("cannot stat %q: %w", data.SrcUri, err)
}
recursive := data.Opts != nil && data.Opts.Recursive
if finfo.IsDir && data.Opts != nil && !recursive {
return fmt.Errorf("cannot move directory %q to %q without recursive flag", data.SrcUri, data.DestUri)
}
err = destClient.CopyRemote(ctx, srcConn, destConn, srcClient, data.Opts)
srcIsDir, err := destClient.CopyRemote(ctx, srcConn, destConn, srcClient, data.Opts)
if err != nil {
return fmt.Errorf("cannot copy %q to %q: %w", data.SrcUri, data.DestUri, err)
}
return srcClient.Delete(ctx, srcConn, recursive)
return srcClient.Delete(ctx, srcConn, srcIsDir)
} else {
return srcClient.MoveInternal(ctx, srcConn, destConn, data.Opts)
}
Expand All @@ -158,9 +150,11 @@ func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error {
return fmt.Errorf("error creating fileshare client, could not parse destination connection %s", data.DestUri)
}
if srcConn.Host != destConn.Host {
return destClient.CopyRemote(ctx, srcConn, destConn, srcClient, data.Opts)
_, err := destClient.CopyRemote(ctx, srcConn, destConn, srcClient, data.Opts)
return err
} else {
return srcClient.CopyInternal(ctx, srcConn, destConn, data.Opts)
_, err := srcClient.CopyInternal(ctx, srcConn, destConn, data.Opts)
return err
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/remote/fileshare/fstype/fstype.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type FileShareClient interface {
Mkdir(ctx context.Context, conn *connparse.Connection) error
// Move moves the file within the same connection
MoveInternal(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) error
// Copy copies the file within the same connection
CopyInternal(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) error
// CopyRemote copies the file between different connections
CopyRemote(ctx context.Context, srcConn, destConn *connparse.Connection, srcClient FileShareClient, opts *wshrpc.FileCopyOpts) error
// Copy copies the file within the same connection. Returns whether the copy source was a directory
CopyInternal(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) (bool, error)
// CopyRemote copies the file between different connections. Returns whether the copy source was a directory
CopyRemote(ctx context.Context, srcConn, destConn *connparse.Connection, srcClient FileShareClient, opts *wshrpc.FileCopyOpts) (bool, error)
// Delete deletes the entry at the given path
Delete(ctx context.Context, conn *connparse.Connection, recursive bool) error
// Join joins the given parts to the connection path
Expand Down
Loading