Skip to content

Commit ca67a8a

Browse files
authored
refactor(filesystem): change symlink err handling (#2941)
1 parent 2f7a0d0 commit ca67a8a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/sources/filesystem/filesystem.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
109109
}
110110

111111
if err != nil && !errors.Is(err, io.EOF) {
112-
logger.Info("error scanning filesystem", "error", err)
112+
if !errors.Is(err, skipSymlinkErr) {
113+
logger.Error(err, "error scanning filesystem")
114+
}
113115
}
114116
}
115117

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

153+
var skipSymlinkErr = errors.New("skipping symlink")
154+
151155
func (s *Source) scanFile(ctx context.Context, path string, chunksChan chan *sources.Chunk) error {
152156
logger := ctx.Logger().WithValues("path", path)
153157
fileStat, err := os.Lstat(path)
154158
if err != nil {
155159
return fmt.Errorf("unable to stat file: %w", err)
156160
}
157161
if fileStat.Mode()&os.ModeSymlink != 0 {
158-
return fmt.Errorf("skipping symlink")
162+
return skipSymlinkErr
159163
}
160164

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

262-
if scanErr != nil && scanErr != io.EOF {
263-
logger.Info("error scanning filesystem", "error", scanErr)
266+
if scanErr != nil && !errors.Is(scanErr, io.EOF) {
267+
if !errors.Is(scanErr, skipSymlinkErr) {
268+
logger.Error(scanErr, "error scanning filesystem")
269+
}
264270
return reporter.ChunkErr(ctx, scanErr)
265271
}
266272
return nil

0 commit comments

Comments
 (0)