Skip to content

Commit d6301d8

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 d6301d8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cmd/incus/file.go

+7
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,16 @@ 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+
sourceDir = ".."
1190+
sourceLen = 1
1191+
}
1192+
11861193
sendFile := func(p string, fInfo os.FileInfo, err error) error {
11871194
if err != nil {
11881195
return fmt.Errorf(i18n.G("Failed to walk path for %s: %s"), p, err)

0 commit comments

Comments
 (0)