From: Simon Ruderich Date: Wed, 2 Jun 2021 05:57:09 +0000 (+0200) Subject: remote: permit syncing relative paths with leading dot X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=commitdiff_plain;h=ca3a64ec7f80ee21f167fd2b1b3de03349c65028 remote: permit syncing relative paths with leading dot These are normally not used by safcm but the remote should still support them. --- diff --git a/remote/sync/files.go b/remote/sync/files.go index 937f0e1..a11b77e 100644 --- a/remote/sync/files.go +++ b/remote/sync/files.go @@ -548,9 +548,12 @@ func OpenParentDirectoryNoSymlinks(path string) (int, string, error) { } dir = ".." parts = []string{filepath.Base(wd)} - } else if parts[0] != "." { + } else { // Relative path: start at the current directory dir = "." + if parts[0] == "." { + parts = parts[1:] + } } dirFd, err := unix.Openat(unix.AT_FDCWD, dir, openReadonlyFlags, 0) diff --git a/remote/sync/files_test.go b/remote/sync/files_test.go index 3d19e7f..34751ae 100644 --- a/remote/sync/files_test.go +++ b/remote/sync/files_test.go @@ -2207,6 +2207,59 @@ func TestSyncFile(t *testing.T) { fmt.Errorf("symlink not permitted in path: \"dir\""), }, + // Border cases + + { + "relative path with leading dot", + safcm.MsgSyncReq{}, + &safcm.File{ + Path: "./dir/file", + Mode: 0644, + Uid: -1, + Gid: -1, + OrigGroup: "group", + Data: []byte("content"), + }, + func() { + ft.CreateDirectory("dir", 0755) + }, + true, + []ft.File{ + root, + { + Path: "dir", + Mode: fs.ModeDir | 0755, + }, + { + Path: "dir/file", + Mode: 0644, + Data: []byte("content"), + }, + }, + safcm.MsgSyncResp{ + FileChanges: []safcm.FileChange{ + { + Path: "./dir/file", + Created: true, + New: safcm.FileChangeInfo{ + Mode: 0644, + User: user, + Uid: uid, + Group: group, + Gid: gid, + }, + }, + }, + }, + []string{ + `4: files: "./dir/file" (group): will create`, + `3: files: "./dir/file" (group): creating`, + `4: files: "./dir/file" (group): creating temporary file "dir/.file*"`, + `4: files: "./dir/file" (group): renaming "dir/.fileRND"`, + }, + nil, + }, + // Diffs {