From a2fbb31f909b2c719909ed3446e43933f9eb0020 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Thu, 26 Mar 2026 00:41:47 +0800 Subject: [PATCH] fix: use fspath.Base to strip Windows paths on SSH remote drag-drop When drag-dropping a local Windows file (e.g. D:\package\AA.tar) to an SSH remote, filepath.Base was called on the remote (Linux) side, which does not recognise backslashes as separators and kept the full Windows path as the filename. Replace with fspath.Base, which converts backslashes to forward slashes before extracting the basename. Fixes #3079 Signed-off-by: majiayu000 <1835304752@qq.com> --- pkg/remote/fileshare/fspath/fspath_test.go | 21 +++++++++++++++++++++ pkg/wshrpc/wshremote/wshremote_file.go | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 pkg/remote/fileshare/fspath/fspath_test.go diff --git a/pkg/remote/fileshare/fspath/fspath_test.go b/pkg/remote/fileshare/fspath/fspath_test.go new file mode 100644 index 0000000000..c634f665ce --- /dev/null +++ b/pkg/remote/fileshare/fspath/fspath_test.go @@ -0,0 +1,21 @@ +package fspath + +import "testing" + +func TestBase(t *testing.T) { + tests := []struct { + path string + want string + }{ + {`D:\package\AA.tar`, "AA.tar"}, + {`D:/package/AA.tar`, "AA.tar"}, + {"/home/user/file.txt", "file.txt"}, + {"file.txt", "file.txt"}, + } + for _, tt := range tests { + got := Base(tt.path) + if got != tt.want { + t.Errorf("Base(%q) = %q, want %q", tt.path, got, tt.want) + } + } +} diff --git a/pkg/wshrpc/wshremote/wshremote_file.go b/pkg/wshrpc/wshremote/wshremote_file.go index 845fb64ac4..3589cc998c 100644 --- a/pkg/wshrpc/wshremote/wshremote_file.go +++ b/pkg/wshrpc/wshremote/wshremote_file.go @@ -18,6 +18,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/panichandler" "github.com/wavetermdev/waveterm/pkg/remote/connparse" + "github.com/wavetermdev/waveterm/pkg/remote/fileshare/fspath" "github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs" "github.com/wavetermdev/waveterm/pkg/util/fileutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" @@ -156,7 +157,7 @@ func (impl *ServerImpl) RemoteFileCopyCommand(ctx context.Context, data wshrpc.C return false, fmt.Errorf("file %q size %d exceeds transfer limit of %d bytes", data.SrcUri, srcFileInfo.Size, RemoteFileTransferSizeLimit) } - destFilePath, err := prepareDestForCopy(destPathCleaned, filepath.Base(srcConn.Path), destHasSlash, opts.Overwrite) + destFilePath, err := prepareDestForCopy(destPathCleaned, fspath.Base(srcConn.Path), destHasSlash, opts.Overwrite) if err != nil { return false, err }