From a0d157d45c5b4c63afc2cfc82bde3ae3207bc455 Mon Sep 17 00:00:00 2001 From: Bernhard Guillon Date: Tue, 7 Jul 2026 09:03:31 +0200 Subject: 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 --- main.go | 55 +------------------------------------------------------ 1 file changed, 1 insertion(+), 54 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 570890d..ffee7e4 100644 --- a/main.go +++ b/main.go @@ -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() } -- cgit v1.2.3