diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2026-07-06 21:54:00 +0200 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2026-07-06 21:54:00 +0200 |
| commit | 5a2d70be3ce8524c366f4dd303b950974f05aa7c (patch) | |
| tree | f2a8507b287738043f50098f20fc74a0259fa3de /watcher.go | |
| parent | eb87e0acea1f3f3bb31eb8a32fb1de1fc4d3bc7a (diff) | |
| download | sourcewatch-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.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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) } |
