aboutsummaryrefslogtreecommitdiffstats
path: root/cmd_windows.go
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-07 19:48:40 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-07 19:48:40 +0200
commit5836a31edb944f44f50d2f421b8cac7e5c87b46a (patch)
tree6a2f0dd7568426305d161977fac28ac9f1c0e810 /cmd_windows.go
parentd664a05e06742513c7dbdeb860bbd89a2a12edb7 (diff)
downloadsourcewatch-5836a31edb944f44f50d2f421b8cac7e5c87b46a.tar.gz
sourcewatch-5836a31edb944f44f50d2f421b8cac7e5c87b46a.zip
Add -dump flag to export whitelist/blacklist to file
Diffstat (limited to 'cmd_windows.go')
-rw-r--r--cmd_windows.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/cmd_windows.go b/cmd_windows.go
index 23f75bd..59df307 100644
--- a/cmd_windows.go
+++ b/cmd_windows.go
@@ -22,6 +22,7 @@ var (
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)")
+ dumpFile = flag.String("dump", "", "Dump whitelist/blacklist to file and exit")
)
func run() {
@@ -46,6 +47,15 @@ func run() {
logInfo("watcher: found %d files", len(manifest.Files))
+ if *dumpFile != "" {
+ if err := dumpRules(*sourceDir, stack, *dumpFile); err != nil {
+ logErrorf("dump: %v", err)
+ os.Exit(1)
+ }
+ logInfo("dump: written to %s", *dumpFile)
+ return
+ }
+
watcher, err := fsnotify.NewWatcher()
if err != nil {
logErrorf("watcher: %v", err)
@@ -472,3 +482,61 @@ func addWatchersRecursively(watcher *fsnotify.Watcher, root string, stack *Gitig
logInfo("watcher: watching %d directories, skipped %d ignored, %d failed (buffer=%dKB)", count, skippedCount, failCount, *bufSizeKB)
return err
}
+
+func dumpRules(root string, stack *GitignoreStack, outPath string) error {
+ f, err := os.Create(outPath)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ var whitelist, blacklist []string
+
+ filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return nil
+ }
+
+ relPath, err := filepath.Rel(root, path)
+ if err != nil {
+ return nil
+ }
+
+ if relPath == "." {
+ return nil
+ }
+
+ if isGitDir(relPath) {
+ if info.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ }
+
+ // push gitignore layers as we walk deeper
+ if info.IsDir() && hasGitignore(path) {
+ stack.Push(path)
+ }
+
+ normalized := filepath.ToSlash(relPath)
+ if stack.IsIgnored(relPath) {
+ blacklist = append(blacklist, normalized)
+ } else {
+ whitelist = append(whitelist, normalized)
+ }
+
+ return nil
+ })
+
+ fmt.Fprintf(f, "# WHITELIST (%d entries) — files/folders that ARE watched\n", len(whitelist))
+ for _, p := range whitelist {
+ fmt.Fprintln(f, p)
+ }
+
+ fmt.Fprintf(f, "\n# BLACKLIST (%d entries) — files/folders that are IGNORED\n", len(blacklist))
+ for _, p := range blacklist {
+ fmt.Fprintln(f, p)
+ }
+
+ return nil
+}