diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-12 23:11:32 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-12 23:11:32 +0530 |
| commit | ca40035398c16abfc78a14e52e3f8640f4eac37c (patch) | |
| tree | d5c736e39974c908b493845591c3b42019323105 /internal/scanner | |
| parent | 1ae0b97b73e6ffb1303bcf9043a7d28d158ad791 (diff) | |
| download | galleryd-ca40035398c16abfc78a14e52e3f8640f4eac37c.tar.xz galleryd-ca40035398c16abfc78a14e52e3f8640f4eac37c.zip | |
feat(scanner): skip hidden directories
fix(code): fix misc. code in scanner and walker
Diffstat (limited to 'internal/scanner')
| -rw-r--r-- | internal/scanner/filter.go | 7 | ||||
| -rw-r--r-- | internal/scanner/scanner.go | 7 | ||||
| -rw-r--r-- | internal/scanner/walker.go | 14 |
3 files changed, 19 insertions, 9 deletions
diff --git a/internal/scanner/filter.go b/internal/scanner/filter.go new file mode 100644 index 0000000..bc0494a --- /dev/null +++ b/internal/scanner/filter.go @@ -0,0 +1,7 @@ +package scanner + +import "strings" + +func shouldSkipDir(name string) bool { + return strings.HasPrefix(name, ".") && name != "." +} diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index cf5490a..68ef4ba 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -1,6 +1,9 @@ package scanner -import "context" +import ( + "context" + "path/filepath" +) type Scanner struct { roots []string @@ -32,5 +35,5 @@ func (s *Scanner) Scan(ctx context.Context) ([]File, error) { files = append(files, discovered...) } - return nil, nil + return files, nil } diff --git a/internal/scanner/walker.go b/internal/scanner/walker.go index c1de97a..ad37679 100644 --- a/internal/scanner/walker.go +++ b/internal/scanner/walker.go @@ -6,10 +6,10 @@ import ( "path/filepath" ) -func (s* Scanner) walk(ctx context.Context, root string) ([]File, error) { +func (s *Scanner) walk(ctx context.Context, root string) ([]File, error) { files := make([]File, 0) - err := filepath:WalkDir(root, func(path string, d fs.DirEntry, err error) error { + err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { select { case <-ctx.Done(): return ctx.Err() @@ -21,6 +21,10 @@ func (s* Scanner) walk(ctx context.Context, root string) ([]File, error) { } if d.IsDir() { + if shouldSkipDir(d.Name()) { + return filepath.SkipDir + } + return nil } @@ -28,11 +32,7 @@ func (s* Scanner) walk(ctx context.Context, root string) ([]File, error) { return nil } - info, err != nil { - return err - } - - rel, err := d.Info() + info, err := d.Info() if err != nil { return err } |