@@ -22,6 +22,7 @@ import (
22
22
"path/filepath"
23
23
"regexp"
24
24
"strings"
25
+ "fmt"
25
26
26
27
"github.com/arduino/arduino-cli/arduino/globals"
27
28
"github.com/arduino/arduino-cli/arduino/sketch"
@@ -59,7 +60,7 @@ func SketchSaveItemCpp(item *sketch.Item, destPath string) error {
59
60
}
60
61
61
62
// SimpleLocalWalk locally replaces filepath.Walk and/but goes through symlinks
62
- func SimpleLocalWalk (root string , walkFn func (path string , info os.FileInfo , err error ) error ) error {
63
+ func SimpleLocalWalkRecursive (root string , maxDepth int , walkFn func (path string , info os.FileInfo , err error ) error ) error {
63
64
64
65
info , err := os .Stat (root )
65
66
@@ -73,10 +74,14 @@ func SimpleLocalWalk(root string, walkFn func(path string, info os.FileInfo, err
73
74
}
74
75
75
76
if info .IsDir () {
77
+ if maxDepth <= 0 {
78
+ return walkFn (root , info , errors .New ("Filesystem bottom is too deep (directory recursion or filesystem really deep): " + root ))
79
+ }
80
+ maxDepth --
76
81
files , err := ioutil .ReadDir (root )
77
82
if err == nil {
78
83
for _ , file := range files {
79
- err = SimpleLocalWalk (root + string (os .PathSeparator )+ file .Name (), walkFn )
84
+ err = SimpleLocalWalkRecursive (root + string (os .PathSeparator )+ file .Name (), maxDepth , walkFn )
80
85
if err == filepath .SkipDir {
81
86
return nil
82
87
}
@@ -87,6 +92,11 @@ func SimpleLocalWalk(root string, walkFn func(path string, info os.FileInfo, err
87
92
return nil
88
93
}
89
94
95
+ func SimpleLocalWalk (root string , walkFn func (path string , info os.FileInfo , err error ) error ) error {
96
+ // see discussion in https://github.com/arduino/arduino-cli/pull/421
97
+ return SimpleLocalWalkRecursive (root , 40 , walkFn )
98
+ }
99
+
90
100
// SketchLoad collects all the files composing a sketch.
91
101
// The parameter `sketchPath` holds a path pointing to a single sketch file or a sketch folder,
92
102
// the path must be absolute.
@@ -124,6 +134,12 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) {
124
134
// collect all the sketch files
125
135
var files []string
126
136
err = SimpleLocalWalk (sketchFolder , func (path string , info os.FileInfo , err error ) error {
137
+
138
+ if err != nil {
139
+ fmt .Printf ("\n error: %+v\n \n " , err )
140
+ return filepath .SkipDir ;
141
+ }
142
+
127
143
// ignore hidden files and skip hidden directories
128
144
if strings .HasPrefix (info .Name (), "." ) {
129
145
if info .IsDir () {
0 commit comments