Skip to content

Commit

Permalink
refactor(filesystem): change symlink err handling (#2941)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz committed Jun 10, 2024
1 parent 2f7a0d0 commit ca67a8a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/sources/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
}

if err != nil && !errors.Is(err, io.EOF) {
logger.Info("error scanning filesystem", "error", err)
if !errors.Is(err, skipSymlinkErr) {
logger.Error(err, "error scanning filesystem")
}
}
}

Expand Down Expand Up @@ -148,14 +150,16 @@ func (s *Source) scanDir(ctx context.Context, path string, chunksChan chan *sour
})
}

var skipSymlinkErr = errors.New("skipping symlink")

func (s *Source) scanFile(ctx context.Context, path string, chunksChan chan *sources.Chunk) error {
logger := ctx.Logger().WithValues("path", path)
fileStat, err := os.Lstat(path)
if err != nil {
return fmt.Errorf("unable to stat file: %w", err)
}
if fileStat.Mode()&os.ModeSymlink != 0 {
return fmt.Errorf("skipping symlink")
return skipSymlinkErr
}

inputFile, err := os.Open(path)
Expand Down Expand Up @@ -259,8 +263,10 @@ func (s *Source) ChunkUnit(ctx context.Context, unit sources.SourceUnit, reporte
}
}

if scanErr != nil && scanErr != io.EOF {
logger.Info("error scanning filesystem", "error", scanErr)
if scanErr != nil && !errors.Is(scanErr, io.EOF) {
if !errors.Is(scanErr, skipSymlinkErr) {
logger.Error(scanErr, "error scanning filesystem")
}
return reporter.ChunkErr(ctx, scanErr)
}
return nil
Expand Down

0 comments on commit ca67a8a

Please sign in to comment.