-
-
Notifications
You must be signed in to change notification settings - Fork 398
Use a local Walk function #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
94e3d7b
Use a local Walk function
d-a-v 7186d73
tabs
d-a-v 23f0204
style
d-a-v fad3aa5
comment
d-a-v 7403a39
retrigger CI
d-a-v 9c82aad
retrigger CI
d-a-v aac3d81
Merge branch 'master' of github.com:arduino/arduino-cli
d-a-v 38c71e9
style
d-a-v 5503c56
check sketch for being a file
d-a-v 75ffd4f
check sketch is not a directory
d-a-v 98bc2e3
Merge branch 'master' of github.com:arduino/arduino-cli
d-a-v 05576c9
additions:
d-a-v fe4cd8b
fixes from "task check"
d-a-v b51893a
updates per review
d-a-v cde4bec
style
d-a-v d41fa12
Update arduino/builder/sketch.go
d-a-v 9de3344
fixes
d-a-v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package builder | |
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
@@ -58,6 +59,44 @@ func SketchSaveItemCpp(item *sketch.Item, destPath string) error { | |
return nil | ||
} | ||
|
||
func simpleLocalWalkRecursive(root string, maxDepth int, walkFn func(path string, info os.FileInfo, err error) error) error { | ||
|
||
info, err := os.Stat(root) | ||
|
||
if err != nil { | ||
return walkFn(root, nil, err) | ||
} | ||
|
||
err = walkFn(root, info, err) | ||
if err == filepath.SkipDir { | ||
return nil | ||
} | ||
|
||
if info.IsDir() { | ||
if maxDepth <= 0 { | ||
return walkFn(root, info, errors.New("Filesystem bottom is too deep (directory recursion or filesystem really deep): "+root)) | ||
} | ||
maxDepth-- | ||
files, err := ioutil.ReadDir(root) | ||
if err == nil { | ||
for _, file := range files { | ||
err = simpleLocalWalkRecursive(root+string(os.PathSeparator)+file.Name(), maxDepth, walkFn) | ||
if err == filepath.SkipDir { | ||
return nil | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SimpleLocalWalk locally replaces filepath.Walk and/but goes through symlinks | ||
func SimpleLocalWalk(root string, walkFn func(path string, info os.FileInfo, err error) error) error { | ||
// see discussion in https://github.com/arduino/arduino-cli/pull/421 | ||
return simpleLocalWalkRecursive(root, 40, walkFn) | ||
} | ||
|
||
// SketchLoad collects all the files composing a sketch. | ||
// The parameter `sketchPath` holds a path pointing to a single sketch file or a sketch folder, | ||
// the path must be absolute. | ||
|
@@ -79,14 +118,28 @@ func SketchLoad(sketchPath, buildPath string) (*sketch.Sketch, error) { | |
return nil, errors.Wrap(err, "unable to find the main sketch file") | ||
} | ||
f.Close() | ||
// ensure it is not a directory | ||
info, err := os.Stat(mainSketchFile) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "unable to check the main sketch file") | ||
} | ||
if info.IsDir() { | ||
return nil, errors.Wrap(errors.New(mainSketchFile), "sketch must not be a directory") | ||
} | ||
} else { | ||
sketchFolder = filepath.Dir(sketchPath) | ||
mainSketchFile = sketchPath | ||
} | ||
|
||
// collect all the sketch files | ||
var files []string | ||
err = filepath.Walk(sketchFolder, func(path string, info os.FileInfo, err error) error { | ||
err = SimpleLocalWalk(sketchFolder, func(path string, info os.FileInfo, err error) error { | ||
|
||
if err != nil { | ||
fmt.Printf("\nerror: %+v\n\n", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use the
|
||
return filepath.SkipDir | ||
} | ||
|
||
// ignore hidden files and skip hidden directories | ||
if strings.HasPrefix(info.Name(), ".") { | ||
if info.IsDir() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
simpleLocalWalkRecursive()
is currently used in this module only, There's no need to wrap it and export it. Can you please remove the wrapper and use directlysimpleLocalWalkRecursive()
?Regarding the
maxDepth
param, can you please create a private constant in this module (named for example maxFileSystemDepth) documenting it properly writing something like:As currently implemented on Linux, the maximum number of symbolic links that will be followed while resolving a pathname is 40
? This way you can use something more meaningful as a parameter when calling the function.Thanks!