Skip to content

Commit 6cf55a6

Browse files
committed
Added symlinks loop-filtering subroutine
1 parent 973dee8 commit 6cf55a6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: internal/arduino/sketch/sketch.go

+16
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,26 @@ func (s *Sketch) supportedFiles() (paths.PathList, error) {
174174
return err == nil
175175
}
176176

177+
var loopErr error
178+
explored := map[string]bool{}
179+
filterLoops := func(p *paths.Path) bool {
180+
dir := p.Canonical().String()
181+
if explored[dir] {
182+
loopErr = errors.New("directories symlink loop detected")
183+
return false
184+
}
185+
explored[dir] = true
186+
return true
187+
}
188+
177189
files, err := s.FullPath.ReadDirRecursiveFiltered(
178190
paths.AndFilter(
179191
paths.OrFilter(
180192
filterValidExtensions,
181193
filterOutBrokenLinks,
182194
),
183195
filterOutBuildPaths,
196+
filterLoops,
184197
),
185198
paths.AndFilter(
186199
paths.FilterOutPrefixes("."),
@@ -191,6 +204,9 @@ func (s *Sketch) supportedFiles() (paths.PathList, error) {
191204
if err != nil {
192205
return nil, err
193206
}
207+
if loopErr != nil {
208+
return nil, loopErr
209+
}
194210
return files, nil
195211
}
196212

0 commit comments

Comments
 (0)