aboutsummaryrefslogtreecommitdiffstats
path: root/watcher.go
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-06 21:54:00 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-06 21:54:00 +0200
commit5a2d70be3ce8524c366f4dd303b950974f05aa7c (patch)
treef2a8507b287738043f50098f20fc74a0259fa3de /watcher.go
parenteb87e0acea1f3f3bb31eb8a32fb1de1fc4d3bc7a (diff)
downloadsourcewatch-5a2d70be3ce8524c366f4dd303b950974f05aa7c.tar.gz
sourcewatch-5a2d70be3ce8524c366f4dd303b950974f05aa7c.zip
Add symlink watcher support with tests
- syncCreate: remove existing file before creating symlink - syncWrite: handle symlink target changes (remove + recreate) - Added 4 new tests: - CreateSymlink: new symlink synced to /data - UpdateSymlinkTarget: symlink target change updates /data - RemoveSymlink: symlink removal synced - ModifySymlinkTargetFile: target file change preserves symlink - 39 tests passing
Diffstat (limited to 'watcher.go')
-rw-r--r--watcher.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/watcher.go b/watcher.go
index 192b61b..d2a98e9 100644
--- a/watcher.go
+++ b/watcher.go
@@ -138,6 +138,7 @@ func syncCreate(srcPath, destPath, relPath string, manifest *Manifest, stack *Gi
}
os.MkdirAll(filepath.Dir(destPath), 0755)
+ os.Remove(destPath)
if linkTarget != "" {
if err := os.Symlink(linkTarget, destPath); err != nil {
@@ -166,10 +167,16 @@ func syncWrite(srcPath, destPath, relPath string, manifest *Manifest, dryRun, ve
return
}
+ linkTarget := ""
+ if info.Mode()&os.ModeSymlink != 0 {
+ linkTarget, _ = os.Readlink(srcPath)
+ }
+
manifest.Files[relPath] = FileMeta{
Size: info.Size(),
Mode: info.Mode(),
ModTime: info.ModTime(),
+ Symlink: linkTarget,
}
if dryRun {
@@ -177,6 +184,15 @@ func syncWrite(srcPath, destPath, relPath string, manifest *Manifest, dryRun, ve
return
}
+ os.Remove(destPath)
+
+ if linkTarget != "" {
+ if err := os.Symlink(linkTarget, destPath); err != nil {
+ log.Printf("error creating symlink %s: %v", relPath, err)
+ }
+ return
+ }
+
if err := copyFile(srcPath, destPath, info.Mode()); err != nil {
log.Printf("error copying %s: %v", relPath, err)
}