mirror of
https://github.com/filebrowser/filebrowser.git
synced 2026-01-23 02:35:10 +00:00
feat: add hide dotfiles param (#1148)
This commit is contained in:
parent
dcbc3286e2
commit
10e399b3c3
8 changed files with 55 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -18,6 +19,12 @@ type Rule struct {
|
|||
Regexp *Regexp `json:"regexp"`
|
||||
}
|
||||
|
||||
// MatchHidden matches paths with a basename
|
||||
// that begins with a dot.
|
||||
func MatchHidden(path string) bool {
|
||||
return strings.HasPrefix(filepath.Base(path), ".")
|
||||
}
|
||||
|
||||
// Matches matches a path against a rule.
|
||||
func (r *Rule) Matches(path string) bool {
|
||||
if r.Regex {
|
||||
|
|
|
|||
23
rules/rules_test.go
Normal file
23
rules/rules_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package rules
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMatchHidden(t *testing.T) {
|
||||
cases := map[string]bool{
|
||||
"/": false,
|
||||
"/src": false,
|
||||
"/src/": false,
|
||||
"/.circleci": true,
|
||||
"/a/b/c/.docker.json": true,
|
||||
".docker.json": true,
|
||||
"Dockerfile": false,
|
||||
"/Dockerfile": false,
|
||||
}
|
||||
|
||||
for path, want := range cases {
|
||||
got := MatchHidden(path)
|
||||
if got != want {
|
||||
t.Errorf("MatchHidden(%s)=%v; want %v", path, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue