Add support for configurable ignore-file name
This commit is contained in:
parent
afd2c8acd7
commit
23fe33fbd3
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue