From 23fe33fbd340bb15f3c7f43d5413a9660003fa6d Mon Sep 17 00:00:00 2001 From: Seednode Date: Sun, 31 Dec 2023 15:50:13 -0600 Subject: [PATCH] Add support for configurable ignore-file name --- README.md | 9 ++++++--- cmd/errors.go | 1 + cmd/files.go | 6 ++---- cmd/root.go | 9 +++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b2a3c65..64520fe 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You can restrict access to certain functionality by prepending a secret string t For example, providing the `--admin-prefix=abc123` flag will register the index rebuild path as `/abc123/index/rebuild`. -The affected paths are: +The restricted paths are: - `/debug/pprof/` - `/debug/pprof/cmdline` - `/debug/pprof/profile` @@ -54,7 +54,7 @@ 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. +If the `--ignore` flag is passed, any directory containing a file named `.roulette_ignore` (configurable with `--ignore-file`) will be skipped during the scanning stage. ## Indexing If the `-i|--indexing` flag is passed, all specified paths will be indexed on start. @@ -65,6 +65,8 @@ The index can be regenerated at any time by accessing the `/index/rebuild` endpo If `--index-file` is set, the index will be loaded from the specified file on start, and written to the file whenever it is re-generated. +The index file consists of [zstd](https://pkg.go.dev/github.com/klauspost/compress/zstd)-compressed [gobs](https://pkg.go.dev/encoding/gob). + ## Info If the `-i|--info` flag is passed, six additional endpoints are registered. @@ -150,7 +152,8 @@ 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 + --ignore skip all directories containing a specified filename + --ignore-file string filename used to indicate directory to be skipped (default ".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/errors.go b/cmd/errors.go index c6502b2..00e20b8 100644 --- a/cmd/errors.go +++ b/cmd/errors.go @@ -20,6 +20,7 @@ var ( ErrInvalidConcurrency = errors.New("concurrency limit must be between 1 and 8192 inclusive") ErrInvalidFileCountRange = errors.New("maximum file count limit must be greater than or equal to minimum file count limit") ErrInvalidFileCountValue = errors.New("file count limits must be non-negative integers no greater than 2147483647") + ErrInvalidIgnoreFile = errors.New("ignore filename must match the pattern " + ignoreFilePattern) ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive") ErrNoMediaFound = errors.New("no supported media formats found which match all criteria") ) diff --git a/cmd/files.go b/cmd/files.go index eed8c14..455cb17 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -22,9 +22,7 @@ import ( "seedno.de/seednode/roulette/types" ) -const ( - ignoreFileName string = `.roulette_ignore` -) +const ignoreFilePattern string = `^[A-z0-9.]+$` type regexes struct { alphanumeric *regexp.Regexp @@ -249,7 +247,7 @@ func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels, if node.IsDir() { directories++ } else { - if Ignore && node.Name() == ignoreFileName { + if Ignore && node.Name() == IgnoreFile { skipDir = true } diff --git a/cmd/root.go b/cmd/root.go index 81d42af..97baa8a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,13 +7,14 @@ package cmd import ( "log" "math" + "regexp" "strings" "github.com/spf13/cobra" ) const ( - ReleaseVersion string = "3.4.3" + ReleaseVersion string = "3.5.0" ) var ( @@ -33,6 +34,7 @@ var ( Fun bool Handlers bool Ignore bool + IgnoreFile string Images bool Index bool IndexFile string @@ -77,6 +79,8 @@ var ( return ErrInvalidPort case Concurrency < 1 || Concurrency > 8192: return ErrInvalidConcurrency + case Ignore && !regexp.MustCompile(ignoreFilePattern).MatchString(IgnoreFile): + return ErrInvalidIgnoreFile case strings.Contains(AdminPrefix, "/"): return ErrInvalidAdminPrefix case AdminPrefix != "": @@ -119,7 +123,8 @@ 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(&Ignore, "ignore", false, "skip all directories containing a specified filename") + rootCmd.Flags().StringVar(&IgnoreFile, "ignore-file", ".roulette-ignore", "filename used to indicate directory to be skipped") 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")