From 5836a31edb944f44f50d2f421b8cac7e5c87b46a Mon Sep 17 00:00:00 2001 From: Bernhard Guillon Date: Tue, 7 Jul 2026 19:48:40 +0200 Subject: Add -dump flag to export whitelist/blacklist to file --- cmd_windows.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'cmd_windows.go') 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 +} -- cgit v1.2.3