]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
remote: support syncing Files without all path components
authorSimon Ruderich <simon@ruderich.org>
Thu, 23 Oct 2025 06:02:47 +0000 (08:02 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 25 Oct 2025 07:28:31 +0000 (09:28 +0200)
safcm normally creates Files for all path components (i.e. syncing
"/foo/bar" creates Files for "/", "/foo" and "/foo/bar"). However, other
programs using safcm as library might want to simply sync "/foo/bar"
without setting (and possibly changing) the other path components.
Support this behavior.

remote/sync/files_test.go
remote/sync/triggers.go

index adc3f28b7e5150e839b6a87d21466263f5b5bbcb..7a1046e5b945ec5f0f9b5e272c63219f45765d50 100644 (file)
@@ -792,6 +792,54 @@ func TestSyncFiles(t *testing.T) {
                        },
                        nil,
                },
+
+               {
+                       "triggers: missing path component",
+                       false,
+                       safcm.MsgSyncReq{
+                               Files: map[string]*safcm.File{
+                                       "dir": {
+                                               OrigGroup: "group",
+                                               Path:      "dir",
+                                               Mode:      fs.ModeDir | 0755,
+                                               Uid:       -1,
+                                               Gid:       -1,
+                                       },
+                               },
+                       },
+                       nil,
+                       nil,
+                       []ft.File{
+                               root,
+                               {
+                                       Path: "dir",
+                                       Mode: fs.ModeDir | 0755,
+                               },
+                       },
+                       safcm.MsgSyncResp{
+                               FileChanges: []safcm.FileChange{
+                                       {
+                                               Path:    "dir",
+                                               Created: true,
+                                               New: safcm.FileChangeInfo{
+                                                       Mode:  fs.ModeDir | 0755,
+                                                       User:  user,
+                                                       Uid:   uid,
+                                                       Group: group,
+                                                       Gid:   gid,
+                                               },
+                                       },
+                               },
+                       },
+                       []string{
+                               `4: files: "dir" (group): will create`,
+                               `3: files: "dir" (group): creating`,
+                               `4: files: "dir" (group): creating directory`,
+                               `4: files: "dir" (group): chmodding drwxr-xr-x`,
+                               fmt.Sprintf(`4: files: "dir" (group): chowning %d/%d`, uid, gid),
+                       },
+                       nil,
+               },
        }
 
        for _, tc := range tests {
index 9a5be18fa25b6403dc20f54a7489873af9852f1a..8470e4cb33d2cf30e283b12368c1dd55aaf3b022 100644 (file)
@@ -15,7 +15,8 @@ import (
 // queueTriggers queues all triggers applying to file.
 func (s *Sync) queueTriggers(file *safcm.File) {
        for _, path := range triggerPaths(file.Path) {
-               if s.req.Files[path].TriggerCommands == nil {
+               if s.req.Files[path] == nil ||
+                       s.req.Files[path].TriggerCommands == nil {
                        continue
                }
                // Queue each trigger only once