aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-07 18:33:03 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-07 18:33:03 +0200
commit4b592f3a3b59eeb81591d868599886c6d7b34b00 (patch)
tree7ca62ddb6cb0314f1533bef3ccd37e108f57a63d
parent9b5066ab6e055ed4431ec8f45060ee236998bbb8 (diff)
downloadsourcewatch-4b592f3a3b59eeb81591d868599886c6d7b34b00.tar.gz
sourcewatch-4b592f3a3b59eeb81591d868599886c6d7b34b00.zip
Add -bufsize flag, resilient walk, and diagnostic logging for Windows watcher
-rw-r--r--cmd_windows.go43
1 files changed, 32 insertions, 11 deletions
diff --git a/cmd_windows.go b/cmd_windows.go
index ef06227..f728182 100644
--- a/cmd_windows.go
+++ b/cmd_windows.go
@@ -18,15 +18,16 @@ import (
)
var (
- sourceDir = flag.String("dir", "", "Source directory to watch (required)")
- connect = flag.String("connect", "localhost:5151", "TCP address of the container to connect to")
+ sourceDir = flag.String("dir", "", "Source directory to watch (required)")
+ connect = flag.String("connect", "localhost:5151", "TCP address of the container to connect to")
+ bufSizeKB = flag.Int("bufsize", 256, "ReadDirectoryChangesW buffer size in KB per directory (default 256)")
)
func run() {
flag.Parse()
if *sourceDir == "" {
- fmt.Fprintln(os.Stderr, "Usage: sourcewatch.exe -dir <source> [-connect host:port]")
+ fmt.Fprintln(os.Stderr, "Usage: sourcewatch.exe -dir <source> [-connect host:port] [-bufsize KB]")
os.Exit(1)
}
@@ -157,19 +158,28 @@ func watchLoop(ctx context.Context, conn net.Conn, watcher *fsnotify.Watcher, ma
srcPath := filepath.Join(*sourceDir, relPath)
info, err := os.Lstat(srcPath)
if err == nil && info.IsDir() {
+ bufBytes := *bufSizeKB * 1024
if hasGitignore(srcPath) {
stack.Push(srcPath)
}
- if err := watcher.Add(srcPath); err != nil {
+ if err := watcher.AddWith(srcPath, fsnotify.WithBufferSize(bufBytes)); err != nil {
logErrorf("watch %s: %v", relPath, err)
}
+ var added int
filepath.Walk(srcPath, func(path string, info os.FileInfo, err error) error {
if err != nil || !info.IsDir() || path == srcPath {
return nil
}
- watcher.Add(path)
+ if err := watcher.AddWith(path, fsnotify.WithBufferSize(bufBytes)); err != nil {
+ logDebug("watch sub %s: %v", path, err)
+ } else {
+ added++
+ }
return nil
})
+ if added > 0 {
+ logDebug("added %d sub-watchers for %s", added, relPath)
+ }
}
}
@@ -378,15 +388,18 @@ func sendEvent(conn net.Conn, evt FileEvent) error {
}
func addWatchersRecursively(watcher *fsnotify.Watcher, root string, stack *GitignoreStack) error {
- count := 0
+ var count, failCount, skippedCount int
+ bufBytes := *bufSizeKB * 1024
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
- return err
+ logDebug("walk error: %v", err)
+ return nil // continue walking even if we can't stat a path
}
relPath, err := filepath.Rel(root, path)
if err != nil {
- return err
+ logDebug("rel error: %v", err)
+ return nil
}
if isGitDir(relPath) {
@@ -401,16 +414,24 @@ func addWatchersRecursively(watcher *fsnotify.Watcher, root string, stack *Gitig
stack.Push(path)
}
if !stack.IsIgnored(relPath) {
- if err := watcher.Add(path); err != nil {
- logErrorf("watch %s: %v", relPath, err)
+ if err := watcher.AddWith(path, fsnotify.WithBufferSize(bufBytes)); err != nil {
+ failCount++
+ if failCount <= 10 {
+ logErrorf("watch %s: %v", relPath, err)
+ }
} else {
count++
}
+ } else {
+ skippedCount++
}
}
return nil
})
- logInfo("watcher: watching %d directories", count)
+ if failCount > 10 {
+ logErrorf("watcher: %d additional watch failures (suppressed)", failCount-10)
+ }
+ logInfo("watcher: watching %d directories, skipped %d ignored, %d failed (buffer=%dKB)", count, skippedCount, failCount, *bufSizeKB)
return err
}