Skip to content

Commit 0b29c49

Browse files
authored
fix: use fspath.Base to strip Windows paths on SSH remote drag-drop (#3118)
Fixes #3079 ## Summary When dragging a local file from Windows to an SSH remote connection, the full Windows path (e.g. `D:\package\AA.tar`) was being passed to `filepath.Base` on the remote (Linux) side. Since `filepath.Base` on Linux does not recognize backslashes as separators, the full path was used as the destination filename. - In `RemoteFileCopyCommand` (`wshremote_file.go:159`), replace `filepath.Base(srcConn.Path)` with `fspath.Base(srcConn.Path)` - `fspath.Base` calls `ToSlash` before `path.Base`, converting backslashes to forward slashes first, so `D:\package\AA.tar` correctly yields `AA.tar` on any OS - Same-host copies at line 86 use `filepath.Base(srcPathCleaned)` and are unaffected — those run on the same OS where `filepath.Base` is correct ## Test Plan - Added `pkg/remote/fileshare/fspath/fspath_test.go` with table-driven tests for `fspath.Base`: - Windows path with backslashes: `D:\package\AA.tar` → `AA.tar` - Windows path with forward slashes: `D:/package/AA.tar` → `AA.tar` - Unix path: `/home/user/file.txt` → `file.txt` - Filename only: `file.txt` → `file.txt` - `go test ./pkg/remote/fileshare/fspath/...` passes Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 101d09b commit 0b29c49

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package fspath
2+
3+
import "testing"
4+
5+
func TestBase(t *testing.T) {
6+
tests := []struct {
7+
path string
8+
want string
9+
}{
10+
{`D:\package\AA.tar`, "AA.tar"},
11+
{`D:/package/AA.tar`, "AA.tar"},
12+
{"/home/user/file.txt", "file.txt"},
13+
{"file.txt", "file.txt"},
14+
}
15+
for _, tt := range tests {
16+
got := Base(tt.path)
17+
if got != tt.want {
18+
t.Errorf("Base(%q) = %q, want %q", tt.path, got, tt.want)
19+
}
20+
}
21+
}

pkg/wshrpc/wshremote/wshremote_file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/wavetermdev/waveterm/pkg/panichandler"
2020
"github.com/wavetermdev/waveterm/pkg/remote/connparse"
21+
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/fspath"
2122
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs"
2223
"github.com/wavetermdev/waveterm/pkg/util/fileutil"
2324
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
@@ -156,7 +157,7 @@ func (impl *ServerImpl) RemoteFileCopyCommand(ctx context.Context, data wshrpc.C
156157
return false, fmt.Errorf("file %q size %d exceeds transfer limit of %d bytes", data.SrcUri, srcFileInfo.Size, RemoteFileTransferSizeLimit)
157158
}
158159

159-
destFilePath, err := prepareDestForCopy(destPathCleaned, filepath.Base(srcConn.Path), destHasSlash, opts.Overwrite)
160+
destFilePath, err := prepareDestForCopy(destPathCleaned, fspath.Base(srcConn.Path), destHasSlash, opts.Overwrite)
160161
if err != nil {
161162
return false, err
162163
}

0 commit comments

Comments
 (0)