-
Notifications
You must be signed in to change notification settings - Fork 13
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
Enable directory recursion in Dir() #15
Open
BiggerNoise
wants to merge
3
commits into
Teamwork:master
Choose a base branch
from
BiggerNoise:feature/listdirs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3a6b94f
Create a ListDirs method for convienient recorsive scan of directories
BiggerNoise 57c590c
Implement directory recursion in reload.Dir() - just look for a trail…
BiggerNoise 61ff2bb
Use /... to indicate recursion instead of just a trailing slash
BiggerNoise 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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -80,6 +80,8 @@ func Do(log func(string, ...interface{}), additional ...dir) error { | |||||
} | ||||||
timers[binSelf] = stoppedTimer(Exec) | ||||||
|
||||||
additional = expandAdditional(log, additional) | ||||||
|
||||||
// Watch the directory, because a recompile renames the existing | ||||||
// file (rather than rewriting it), so we won't get events for that. | ||||||
dirs := make([]string, len(additional)+1) | ||||||
|
@@ -152,6 +154,33 @@ func Do(log func(string, ...interface{}), additional ...dir) error { | |||||
return nil | ||||||
} | ||||||
|
||||||
func expandAdditional(log func(string, ...interface{}), additional []dir) []dir { | ||||||
result := make([]dir, 0, len(additional)) | ||||||
for _, a := range additional { | ||||||
if lastChar := a.path[len(a.path)-1]; lastChar == '\\' || lastChar == '/' { | ||||||
result = append(result, listDirs(log, a.path, a.cb)...) | ||||||
} else { | ||||||
result = append(result, a) | ||||||
} | ||||||
} | ||||||
return result | ||||||
} | ||||||
|
||||||
func listDirs(log func(string, ...interface{}), rootPath string, cb func()) (result []dir) { | ||||||
filepath.WalkDir(rootPath, func(dirPath string, d fs.DirEntry, err error) error { | ||||||
if err != nil { | ||||||
log("Error reading %s, skipped", dirPath) | ||||||
return fs.SkipDir | ||||||
} | ||||||
if d.IsDir() { | ||||||
result = append(result, Dir(dirPath, cb)) | ||||||
} | ||||||
return nil | ||||||
}) | ||||||
|
||||||
return | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
// Exec replaces the current process with a new copy of itself. | ||||||
func Exec() { | ||||||
execName := binSelf | ||||||
|
@@ -207,17 +236,3 @@ func relpath(p string) string { | |||||
|
||||||
return p | ||||||
} | ||||||
|
||||||
func ListDirs(rootPath string, cb func()) (result []dir) { | ||||||
filepath.WalkDir(rootPath, func(dirPath string, d fs.DirEntry, err error) error { | ||||||
if err != nil { | ||||||
return fs.SkipDir | ||||||
} | ||||||
if d.IsDir() { | ||||||
result = append(result, Dir(dirPath, cb)) | ||||||
} | ||||||
return nil | ||||||
}) | ||||||
|
||||||
return | ||||||
} |
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.
IMHO it's better to return an error on this (from reload.Do()), rather than skipping it. It's on startup, and skipping directories (even with a print) is somewhat confusing, IMHO.