From 4ac4cd8778d21f9b35e50dd6b59a65b6ee4b07cc Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 23 Oct 2025 08:02:47 +0200 Subject: [PATCH] remote: support syncing Files without all path components 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 | 48 +++++++++++++++++++++++++++++++++++++++ remote/sync/triggers.go | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/remote/sync/files_test.go b/remote/sync/files_test.go index adc3f28..7a1046e 100644 --- a/remote/sync/files_test.go +++ b/remote/sync/files_test.go @@ -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 { diff --git a/remote/sync/triggers.go b/remote/sync/triggers.go index 9a5be18..8470e4c 100644 --- a/remote/sync/triggers.go +++ b/remote/sync/triggers.go @@ -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 -- 2.49.1