-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
RFC: proposal for filtering WalkerHandler
directories
#154
base: main
Are you sure you want to change the base?
Conversation
This proposal proposes that `WalkerHandler.apply` should return a list of directories to walk, rather than modifying the list that is passed to it.
Have you considered changing the |
@dipinhora using a list would get around the awkwardness around removing items from the array. Two things come to mind with that approach:
|
Probably a better option altogether would be to have a function that provides a |
There are tradeoffs here between performance and various abstractions. If we truly wanted the best performance we would write it in assembly. But, since we've chose to use Pony I'm guessing we're all at least implicitly willing to make certain performance tradeoffs. One of the questions here is "which tradeoffs between performance and ease of use and consistency are we willing to make?" Can you provide an example of what you're thinking of with the |
@aturley Yes, of course. Sorry if my earlier comment came across as antagonistic. That wasn't my intent. The following is something along the lines of what I meant by the class MyWalkerHandler is WalkerHandler
fun ref apply(dir_path: FilePath, dir_entry: String): Bool =>
let skip_directories_with_string = "IGNORE_ME"
if dir_entry.contains(skip_directories_with_string) then
false
else
true
end with the following versions of interface WalkerHandler
"""
A handler for `FilePath.walk`.
"""
fun ref apply(dir_path: FilePath, dir_entry: String): Bool and fun val walk(handler: WalkHandler ref, follow_links: Bool = false) =>
"""
Walks a directory structure starting at this.
`handler(dir_path, dir_entry)` will be called for each directory
starting with this one. The handler returns true/false for which subdirectories
to walk or skip.
"""
try
with dir = Directory(this)? do
var entries: Array[String] ref = dir.entries()?
for e in entries.values() do
if WalkHandler(this, e) then
let p = this.join(e)?
let info = FileInfo(p)?
if info.directory and (follow_links or not info.symlink) then
p.walk(handler, follow_links)
end
end
end
end
else
return
end |
I've never used the API in question. I know that @aturley has used it a lot. I trust his judgment on the changes that are needed. I'm sure we have a lot of APIs in the standard library that could use some love. |
@aturley are you interested in continuing with this RFC? |
Rendered