Add --ignore, to skip directories

This commit is contained in:
Seednode 2023-12-07 10:34:19 -06:00
parent 57e5b7dff2
commit eaed4f11ef
3 changed files with 18 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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")