Skip to content

Commit dadb144

Browse files
Ignore invalid symlinks for files that would be skipped anyway
Previously, SketchLoad would error out on *any* error during file enumeration, including broken symlinks (where `os.Stat` returns `ErrNotExist`), even when that symlink would not be loaded (i.e. no valid extension) anyway. Now, `ErrNotExist` errors are ignored and a broken symlink is processed as normal. This changes the code to assume broken symlinks are not directories and to use the `path` value instead of the `info.Name()`, since the latter is not available when the `Stat()` call failed. If, based on the name of the broken symlink, the file would be skipped, processing continues as normal. If the file would be loaded, then the existing `os.Open()` call fails (and since the previous commit, returns an error like before for all broken symlinks).
1 parent d4c259f commit dadb144

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: arduino/builder/sketch.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
154154
var files []string
155155
rootVisited := false
156156
err = simpleLocalWalk(sketchFolder, maxFileSystemDepth, func(path string, info os.FileInfo, err error) error {
157-
if err != nil {
157+
// Ignore ErrNotExist (broken symlinks), which will be
158+
// reported by os.Open below if the file would not be
159+
// skipped based on the name
160+
if err != nil && !errors.Is(err, os.ErrNotExist) {
158161
feedback.Errorf("Error during sketch processing: %v", err)
159162
os.Exit(errorcodes.ErrGeneric)
160163
}
161164

162-
if info.IsDir() {
165+
if info != nil && info.IsDir() {
163166
// Filters in this if-block are NOT applied to the sketch folder itself.
164167
// Since the sketch folder is the first one processed by simpleLocalWalk,
165168
// we can set the `rootVisited` guard to exclude it.
@@ -182,7 +185,7 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
182185
}
183186

184187
// ignore hidden files
185-
if strings.HasPrefix(info.Name(), ".") {
188+
if strings.HasPrefix(filepath.Base(path), ".") {
186189
return nil
187190
}
188191

0 commit comments

Comments
 (0)