Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walk directories in filesystem source enumeration #2313

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/sources/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ func (s *Source) scanFile(ctx context.Context, path string, chunksChan chan *sou
// filepath or a directory.
func (s *Source) Enumerate(ctx context.Context, reporter sources.UnitReporter) error {
for _, path := range s.paths {
fileInfo, err := os.Stat(filepath.Clean(path))
if err != nil {
if err := reporter.UnitErr(ctx, err); err != nil {
return err
}
continue
}
if fileInfo.IsDir() {
return fs.WalkDir(os.DirFS(path), ".", func(relativePath string, d fs.DirEntry, err error) error {
if err != nil || relativePath == "." {
return nil
}
fullPath := filepath.Join(path, relativePath)
item := sources.CommonSourceUnit{ID: fullPath}
if err := reporter.UnitOk(ctx, item); err != nil {
mcastorina marked this conversation as resolved.
Show resolved Hide resolved
return err
}
return nil
})
}
item := sources.CommonSourceUnit{ID: path}
if err := reporter.UnitOk(ctx, item); err != nil {
return err
Expand Down
Loading