]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
remote: permit syncing relative paths with leading dot
authorSimon Ruderich <simon@ruderich.org>
Wed, 2 Jun 2021 05:57:09 +0000 (07:57 +0200)
committerSimon Ruderich <simon@ruderich.org>
Wed, 2 Jun 2021 05:57:09 +0000 (07:57 +0200)
These are normally not used by safcm but the remote should still support
them.

remote/sync/files.go
remote/sync/files_test.go

index 937f0e1f2df8820381d55951630a7c422e5dbb9d..a11b77e8107d8265ed33dac5acfeaf8aa89a4e6e 100644 (file)
@@ -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)
index 3d19e7f9a3b950e180326f7930efd7d019d57369..34751ae360e6fb09f09b860ef690274790c81ca0 100644 (file)
@@ -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
 
                {