-
Notifications
You must be signed in to change notification settings - Fork 83
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
Allow traversal of symbolic links with find* #21
Comments
Yeah, symlinks are intentionally filtered out right now. One problem is that they can lead to circular (never-ending) finds. |
How about something along the lines of:
And then I could do this:
I'm not sure if that's the best way, but it avoids having to create a new John |
I wouldn't want to add such a setting into the core of Shelly. But this is a good idea: we could define some setting for the finder that can be build up in a monad, might look like: shelly $ do
finder "/tmp" $ do
followSymlinks True This feels right for Shelly, but I am not sure if this is better than the record approach finder "/tmp" def {followSymlinks = True} Will have to think some more... |
FWIW, I think this is a really nice choice. I'd like to then have other
To provide a set of paths not to be traversed. You would be able to create a John |
It doesn't look like I am going to be able to get to this for a few weeks. Let me know if you take a crack at it. You can make Shelly work how you want now by just removing the line that checks for the symlink: https://github.com/yesodweb/Shelly.hs/blob/master/Shelly/Find.hs#L69 |
I'm afraid my Haskell skills are just at the beginning stages. I started to Thanks, John |
I think you want a Writer monad (use runWriter), but I think the monad is just going to build up a record, so a record-based interface is probably where I would start. |
Here's an idea: Create a DSL using the Free monad, to describe what it is you
findWhen's first argument would be a function that takes a FilePath, and
Note that the Sh monad doesn't come into play in the call to match, since In addition to matching, ShPred would support declarative statements giving
(I can imagine followSymlinksWhen, crossFilesystemWhen, etc). If I test for something to be a regular file, Shelly would know it doesn't
How does that sound? John |
I like the idea of re-using the filter to set options. test_f, etc can't be made pure unless find is redesigned to hold the necessary file stat information with each file. |
I was thinking that the "filter" function passed to find would be a pure So the "test_d" in the predicate isn't a function that gets called, it just John |
Hi Greg, I've created a version of Find.hs that uses Arrows for the predicate function
The FindArrow type in that file observes and maintains meta-state, such as:
Here is the type declaration:
Meta-state is changed by using functions cognizant of the arrow. Right now
We'd likely use a combinator for this pattern:
Here's an example of a predicate which calls stat for each filesystem entry:
Here's a predicate that doesn't need stat to be called at all:
Again, for typical predicates, like comparing against filename parts, a family Finally, here is the sample code that uses them:
The result:
If this is of interest to you, I'm sure we can find better ways of fleshing John |
This looks great! One concern I have is that shelly is being used by new users. Arrows are actually something that I have barely used (I think only in Hakyll). Applicative on the other hand is much more common place. So if it is possible to configure with Monads + Applicative or otherwise something more beginner friendly that would be preferable. I am a bit snowed in now, but will be able to look in depth at least by this weekend. |
Hmm, it would seem there is no good way with Monads to maintain the sort of
See his discussion on "static meta-information". With arrows, we can know I do agree that forcing arrow notation may be a bit heavy-handed, but in fact Here's a predicate that matches on directories that are both readable and
This would be impossible to express in point-free style using monads and
But this is not as easily composable. I have to encode logic in the inner lambda,
Plus, I still get the optimization benefits: I know before performing any John |
Thanks for thinking about the alternatives. One more thing to look at would be filemanip |
Ah, I see, creating a new family of operators to allow points-free expressions in the Monad. Is it really optimizing calls to stat? Also, why not just using filemanip, then, rather than duplicate that functionality in Shelly? |
On further reflection, there is no reason why the filemanip-style operators could not be implemented on top of arrows. This would hide arrows for all of those use cases, and yet provide that avenue for those who wish to explore it. For example:
Now you can join two predicate arrows with a short-circuiting (&&). And likewise for ==? and the other types of operators. |
Greg, I've been thinking more about how to optimally use monads instead of arrows, and The problem of optimizing pattern matches against structured data is one that
In both this and the ASTMatcher case, the predicate doesn't do the matching Now imagine the following DSL in the Free Monad:
This would assemble a series of instructions to be interpreted by findWhen as The advantages of this approach are that it's monadic, and allows for not only The downside is the extremely undiomatic nature of this code compared to, say,
What do you think of this direction? It also keeps the predicate function John |
This looks very interesting also. The reason I wrote my own finds was to have something that fit in with shelly without having the user learn a new family of functions for the finding but instead just use existing shelly functions. |
Actually, I've been meaning to write an abstract library for reading, So I think that if I solve this problem in the general, I can create a finding John |
I like the free monad version (perhaps free applicative might be more appropriate, but monads make for nicer DSLs) and I think it could be included in Shelly by default. |
I'm writing a utility that needs to descend into all directories under a directory given by the user. It shouldn't matter whether these are symbolic links or real directory. However, with Shelly's findFold, I can see no way to descend into symbolic links to directories.
The text was updated successfully, but these errors were encountered: