Add support for configurable ignore-file name

This commit is contained in:
Seednode 2023-12-31 15:50:13 -06:00
parent afd2c8acd7
commit 23fe33fbd3
4 changed files with 16 additions and 9 deletions

View File

@ -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`. 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/`
- `/debug/pprof/cmdline` - `/debug/pprof/cmdline`
- `/debug/pprof/profile` - `/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. Both filtering parameters ignore the file extension and full path; they only compare against the bare filename.
## Ignoring directories ## 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 ## Indexing
If the `-i|--indexing` flag is passed, all specified paths will be indexed on start. 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. 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 ## Info
If the `-i|--info` flag is passed, six additional endpoints are registered. 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 --fun add a bit of excitement to your day
--handlers display registered handlers (for debugging) --handlers display registered handlers (for debugging)
-h, --help help for roulette -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 --images enable support for image files
--index generate index of supported file paths at startup --index generate index of supported file paths at startup
--index-file string path to optional persistent index file --index-file string path to optional persistent index file

View File

@ -20,6 +20,7 @@ var (
ErrInvalidConcurrency = errors.New("concurrency limit must be between 1 and 8192 inclusive") 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") 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") 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") 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") ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
) )

View File

@ -22,9 +22,7 @@ import (
"seedno.de/seednode/roulette/types" "seedno.de/seednode/roulette/types"
) )
const ( const ignoreFilePattern string = `^[A-z0-9.]+$`
ignoreFileName string = `.roulette_ignore`
)
type regexes struct { type regexes struct {
alphanumeric *regexp.Regexp alphanumeric *regexp.Regexp
@ -249,7 +247,7 @@ func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels,
if node.IsDir() { if node.IsDir() {
directories++ directories++
} else { } else {
if Ignore && node.Name() == ignoreFileName { if Ignore && node.Name() == IgnoreFile {
skipDir = true skipDir = true
} }

View File

@ -7,13 +7,14 @@ package cmd
import ( import (
"log" "log"
"math" "math"
"regexp"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const ( const (
ReleaseVersion string = "3.4.3" ReleaseVersion string = "3.5.0"
) )
var ( var (
@ -33,6 +34,7 @@ var (
Fun bool Fun bool
Handlers bool Handlers bool
Ignore bool Ignore bool
IgnoreFile string
Images bool Images bool
Index bool Index bool
IndexFile string IndexFile string
@ -77,6 +79,8 @@ var (
return ErrInvalidPort return ErrInvalidPort
case Concurrency < 1 || Concurrency > 8192: case Concurrency < 1 || Concurrency > 8192:
return ErrInvalidConcurrency return ErrInvalidConcurrency
case Ignore && !regexp.MustCompile(ignoreFilePattern).MatchString(IgnoreFile):
return ErrInvalidIgnoreFile
case strings.Contains(AdminPrefix, "/"): case strings.Contains(AdminPrefix, "/"):
return ErrInvalidAdminPrefix return ErrInvalidAdminPrefix
case AdminPrefix != "": 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(&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(&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(&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(&Images, "images", false, "enable support for image files")
rootCmd.Flags().BoolVar(&Index, "index", false, "generate index of supported file paths at startup") 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") rootCmd.Flags().StringVar(&IndexFile, "index-file", "", "path to optional persistent index file")