mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2026-07-22 03:15:41 +02:00
refactor(watch): extract testable maybeBackfillExistingArchives helper
Co-authored-by: Belphemur <197810+Belphemur@users.noreply.github.com>
This commit is contained in:
co-authored by
Belphemur
parent
1d981be21b
commit
d7782fdb25
@@ -115,9 +115,7 @@ func WatchCommand(_ *cobra.Command, args []string) error {
|
||||
if err := addRecursiveWatch(watcher, path); err != nil {
|
||||
return fmt.Errorf("failed to watch path %s: %w", path, err)
|
||||
}
|
||||
if backfill {
|
||||
backfillExistingArchives(path, debouncer.Trigger)
|
||||
}
|
||||
maybeBackfillExistingArchives(backfill, path, debouncer.Trigger)
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -208,6 +206,17 @@ func backfillExistingArchives(rootPath string, process func(path string)) {
|
||||
}
|
||||
}
|
||||
|
||||
// maybeBackfillExistingArchives runs backfillExistingArchives against
|
||||
// rootPath only when enabled is true. It exists as its own function (rather
|
||||
// than inlining the `if` check at the call site) so the gating decision used
|
||||
// by WatchCommand can be exercised directly in tests.
|
||||
func maybeBackfillExistingArchives(enabled bool, rootPath string, process func(path string)) {
|
||||
if !enabled {
|
||||
return
|
||||
}
|
||||
backfillExistingArchives(rootPath, process)
|
||||
}
|
||||
|
||||
func shouldProcessWatchEvent(event fsnotify.Event) bool {
|
||||
return event.Has(fsnotify.Create) || event.Has(fsnotify.Write) || event.Has(fsnotify.Rename)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user