From eaed4f11efe602448c38850e13c0aad5893a8c8f Mon Sep 17 00:00:00 2001 From: Seednode Date: Thu, 7 Dec 2023 10:34:19 -0600 Subject: [PATCH] Add --ignore, to skip directories --- README.md | 4 ++++ cmd/files.go | 12 +++++++++++- cmd/root.go | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b44bb0c..0000260 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ You can combine these two parameters, with exclusions taking priority over inclu Both filtering parameters ignore the file extension and full path; they only compare against the bare filename. +## Ignoring directories +Any directory containing a file named `.roulette_ignore` will be skipped during the scanning stage. + ## Indexing If the `-i|--indexing` flag is passed, all specified paths will be indexed on start. @@ -124,6 +127,7 @@ Flags: --fun add a bit of excitement to your day --handlers display registered handlers (for debugging) -h, --help help for roulette + --ignore skip all directories containing a file named .roulette_ignore --images enable support for image files --index generate index of supported file paths at startup --index-file string path to optional persistent index file diff --git a/cmd/files.go b/cmd/files.go index 05efdc1..250abb8 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -22,6 +22,10 @@ import ( "seedno.de/seednode/roulette/types" ) +const ( + ignoreFileName string = `.roulette_ignore` +) + type regexes struct { alphanumeric *regexp.Regexp filename *regexp.Regexp @@ -233,17 +237,23 @@ func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels, var directories, files = 0, 0 + var skipDir = false + for _, node := range nodes { if node.IsDir() { directories++ } else { + if Ignore && node.Name() == ignoreFileName { + skipDir = true + } + files++ } } var skipFiles = false - if files <= MaxFileCount && files >= MinFileCount { + if files <= MaxFileCount && files >= MinFileCount && !skipDir { stats.directoriesMatched <- 1 } else { stats.filesSkipped <- files diff --git a/cmd/root.go b/cmd/root.go index bd0ddb5..968a2a8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( ) const ( - ReleaseVersion string = "3.2.10" + ReleaseVersion string = "3.3.0" ) var ( @@ -29,6 +29,7 @@ var ( Flash bool Fun bool Handlers bool + Ignore bool Images bool Index bool IndexFile string @@ -96,6 +97,7 @@ func init() { rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)") rootCmd.Flags().BoolVar(&Fun, "fun", false, "add a bit of excitement to your day") rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)") + rootCmd.Flags().BoolVar(&Ignore, "ignore", false, "skip all directories containing a file named .roulette_ignore") rootCmd.Flags().BoolVar(&Images, "images", false, "enable support for image files") rootCmd.Flags().BoolVar(&Index, "index", false, "generate index of supported file paths at startup") rootCmd.Flags().StringVar(&IndexFile, "index-file", "", "path to optional persistent index file")