Skip to content

Commit 7fa00dc

Browse files
committed
incus/file: Properly handle relative source paths
When going through either .Split() or .Base(), a source path of ".." is incorrectly treated as an empty source directory and so processed the same as ".". This is obviously incorect behavior which then leads to files landing in the wrong directory on the server side. I couldn't find a good way with pure filepath calls to handle this, so instead we've got to hardcode the logic for the parent paths. Any path containing a separator (/) are handled correctly though. Closes #1808 Signed-off-by: Stéphane Graber <[email protected]>
1 parent 36e1756 commit 7fa00dc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cmd/incus/file.go

+6
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,15 @@ func (c *cmdFile) recursivePullFile(sftpConn *sftp.Client, p string, targetDir s
11801180

11811181
func (c *cmdFile) recursivePushFile(sftpConn *sftp.Client, source string, target string) error {
11821182
source = filepath.Clean(source)
1183+
11831184
sourceDir, _ := filepath.Split(source)
11841185
sourceLen := len(sourceDir)
11851186

1187+
// Special handling for relative paths.
1188+
if source == ".." {
1189+
sourceLen = 1
1190+
}
1191+
11861192
sendFile := func(p string, fInfo os.FileInfo, err error) error {
11871193
if err != nil {
11881194
return fmt.Errorf(i18n.G("Failed to walk path for %s: %s"), p, err)

0 commit comments

Comments
 (0)