Skip to content

Commit 94e3d7b

Browse files
committed
Use a local Walk function
Because arduino-cli segfaults when sketchDir is a symbolic link, a simple walk function is introduced with a twofold effect: - fix the segfault - allow to use symlinks ref: https://www.google.com/search?q=golang+Walk+does+not+follow+symbolic+links
1 parent 8f73b78 commit 94e3d7b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

arduino/builder/sketch.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ func SketchSaveItemCpp(item *sketch.Item, destPath string) error {
5858
return nil
5959
}
6060

61+
func SimpleLocalWalk(root string, walkFn func(path string, info os.FileInfo, err error) error) error {
62+
info, err := os.Stat(root)
63+
64+
if err != nil {
65+
return walkFn(root, nil, err)
66+
}
67+
68+
err = walkFn(root, info, err)
69+
if err == filepath.SkipDir {
70+
return nil
71+
}
72+
73+
if info.IsDir() {
74+
files, err := ioutil.ReadDir(root)
75+
if err == nil {
76+
for _, file := range files {
77+
err = SimpleLocalWalk(root + string(os.PathSeparator) + file.Name(), walkFn)
78+
if err == filepath.SkipDir {
79+
return nil
80+
}
81+
}
82+
}
83+
}
84+
85+
return nil
86+
}
87+
6188
// SketchLoad collects all the files composing a sketch.
6289
// The parameter `sketchPath` holds a path pointing to a single sketch file or a sketch folder,
6390
// the path must be absolute.
@@ -86,7 +113,8 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
86113

87114
// collect all the sketch files
88115
var files []string
89-
err = filepath.Walk(sketchFolder, func(path string, info os.FileInfo, err error) error {
116+
err = SimpleLocalWalk(sketchFolder, func(path string, info os.FileInfo, err error) error {
117+
90118
// ignore hidden files and skip hidden directories
91119
if strings.HasPrefix(info.Name(), ".") {
92120
if info.IsDir() {

0 commit comments

Comments
 (0)