openshake icon indicating copy to clipboard operation
openshake copied to clipboard

"ls" only matches files relative to the current directory

Open nominolo opened this issue 13 years ago • 6 comments

If you use ls in a rule, it won't pick up paths outside of the current directory (unless you use "..").

This seems to be a bug from the Glob library. E.g., try this

$ cd ~/tmp
$ touch aaa
$ ghci
> import System.FilePath.Glob
> globDir1 (compile "/home/me/tmp/aaa") ""   -- use your home dir

This should find the given file, but doesn't.

nominolo avatar Aug 14 '11 16:08 nominolo

The code sample you give shouldn't work since I think the arguments to globDir1 are the wrong way around. Try this:

globDir1 (compile "*") "/Users/myusername"

It works as expected.

batterseapower avatar Sep 10 '11 23:09 batterseapower

Can you give me an example of how ls fails?

batterseapower avatar Sep 10 '11 23:09 batterseapower

Well, the Glob library itself may not be at fault, but one could argue that openshake is. The use case is the following:

When I compile a file with GHC it goes on to look through a number of search paths to find source files and dependencies, etc. These paths are usually outside the current project directory. I want to properly model all of these dependencies, because if the contents of these directories change it may affect my project.

The way globDir is currently used inside openshake I am not able to specify a dependency on a file where I know the absolute path. I can only refer to it by computing the right amount of "../".

nominolo avatar Sep 11 '11 16:09 nominolo

OK now I understand.

So you expect that globDir1 ((compile dir) fp) should return getDirectoryContents dir for any fp. This does indeed seem like reasonable behaviour for the glob package.

batterseapower avatar Sep 11 '11 19:09 batterseapower

Well, yes, although even more general. The fp argument should really only be used to resolve relative patterns (e.g., foo*), but absolute filepath patterns should be allowed, too, i.e., globDir1 (compile (dir </> "*")) fp should also return the contents of dir.

Interestingly, this doesn't work in regular Unix tools, either. E.g., find . -name '/home/me/tmp/*' doesn't return anything. So, perhaps the question is whether the Glob library is the right tool in all cases.

nominolo avatar Sep 11 '11 21:09 nominolo

My intuition is that (globDir1 pat dir) is the same thing as (cd dir && echo pat), in which case what you want to do makes sense.

batterseapower avatar Sep 12 '11 05:09 batterseapower