diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2026-07-07 09:03:31 +0200 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2026-07-07 09:03:31 +0200 |
| commit | a0d157d45c5b4c63afc2cfc82bde3ae3207bc455 (patch) | |
| tree | c6152cf56c437945359a3b80fc16b76e9ba7332a /main.go | |
| parent | e4c2f78abe427d9fdbfb46bb205f2210a03704fa (diff) | |
| download | sourcewatch-a0d157d45c5b4c63afc2cfc82bde3ae3207bc455.tar.gz sourcewatch-a0d157d45c5b4c63afc2cfc82bde3ae3207bc455.zip | |
Add Windows native watcher with Unix socket IPC
Architecture:
- Windows binary: watches files via ReadDirectoryChangesW (fsnotify),
sends events as newline-delimited JSON over Unix domain socket
- Container: performs initial sync, then listens on socket for events
from Windows watcher
New files:
- cmd_windows.go: Windows serve command (watcher + socket server)
- cmd_linux.go: Linux socket client + event listener
- types.go: shared FileEvent, FileMeta, Manifest types
- watcher_test_helper.go: inotify-based watcher for integration tests
Changes:
- main.go: simplified to just call run()
- watcher.go: removed fsnotify dependency, extracted Watcher interface
- sync.go: removed duplicate type definitions
- watcher_test.go: uses watchForTests() helper
Usage:
sourcewatch.exe -dir C:\myproject -socket D:\sourcewatch.sock
docker run -v D:\sourcewatch.sock:/run/sourcewatch.sock \
-v C:\myproject:/host:ro -v mydata:/data sourcewatch
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 55 |
1 files changed, 1 insertions, 54 deletions
@@ -1,58 +1,5 @@ package main -import ( - "context" - "flag" - "log" - "os" - "os/signal" - "syscall" -) - -var ( - hostDir = flag.String("host", "/host", "Host source directory (read-only)") - dataDir = flag.String("data", "/data", "Data destination directory") - verbose = flag.Bool("verbose", false, "Enable verbose logging (shorthand for -log-level debug)") - logLevel = flag.String("log-level", "info", "Log level: debug, info, warn, error, none") - dryRun = flag.Bool("dry-run", false, "Preview what would be synced without copying") -) - func main() { - flag.Parse() - - if *verbose { - *logLevel = "debug" - } - - level, err := ParseLogLevel(*logLevel) - if err != nil { - log.Fatal(err) - } - SetLogLevel(level) - - log.SetFlags(0) - log.SetOutput(nil) - - stack := NewGitignoreStack(*hostDir) - - manifest, err := initialSync(*hostDir, *dataDir, stack, *dryRun) - if err != nil { - logErrorf("initial sync failed: %v", err) - os.Exit(1) - } - - if *dryRun { - logInfo("dry-run complete, exiting") - return - } - - logInfo("watcher: ready, monitoring for changes ...") - - ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) - defer cancel() - - if err := watch(ctx, *hostDir, *dataDir, manifest, stack, *dryRun); err != nil { - logErrorf("watcher failed: %v", err) - os.Exit(1) - } + run() } |
