Skip to content

Commit 75ffd4f

Browse files
committed
check sketch is not a directory
1 parent 5503c56 commit 75ffd4f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arduino/builder/sketch.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
103103
sketchFolder = sketchPath
104104
mainSketchFile = filepath.Join(sketchPath, stat.Name()+".ino")
105105
// in the case a dir was passed, ensure the main file exists and is readable
106-
info, err := os.Stat(mainSketchFile)
106+
f, err := os.Open(mainSketchFile)
107107
if err != nil {
108108
return nil, errors.Wrap(err, "unable to find the main sketch file")
109109
}
110+
f.Close()
111+
// ensure it is not a directory
112+
info, err := os.Stat(mainSketchFile)
113+
if err != nil {
114+
return nil, errors.Wrap(err, "unable to check the main sketch file")
115+
}
110116
if info.IsDir() {
111-
return nil, errors.Wrap(errors.New(mainSketchFile), "sketch must be a file")
117+
return nil, errors.Wrap(errors.New(mainSketchFile), "sketch must not be a directory")
112118
}
113119
} else {
114120
sketchFolder = filepath.Dir(sketchPath)

0 commit comments

Comments
 (0)