filemanip icon indicating copy to clipboard operation
filemanip copied to clipboard

Simple `*` GlobPattern completely broken with directories?

Open Fuuzetsu opened this issue 9 years ago • 6 comments

It seems to me that * is completely broken for directories when using the Find or GlobPattern modules, which is very strange to me considering it should be basic functionality and everything else seems to work great.

> "foo/bar" ~~ "*/*"
False

Seems inconsistent with namesMatching too

> namesMatching "*/*.hs"
["./Hpack/Util.hs","./Hpack/Config.hs","./Hpack/Run.hs"]
> "Hpack/Config.hs" ~~ "*/*.hs"
False

Using 0.3.6.3.

Fuuzetsu avatar Jul 04 '15 22:07 Fuuzetsu

I noticed this as well a few days ago.

Another case to compare:

> "a/b" ~~ "*/b"
False

@Fuuzetsu I'm not sure whether your fix is correct, as it allows * to match even empty directory components: Before "a//c" ~~ "a/*/c == False, with your patch"a//c" ~~ "a/*/c" == True`.

Another suggestion what might have been intended:

          matchDir cs' = case matchTerms ts cs' of
                      -- Nothing -> matchDir $ tail cs' -- instead of this
                         Nothing -> return $ dropWhile (/= pathSeparator) cs'
                         _ -> return cs'

nh2 avatar Jul 12 '15 16:07 nh2

Perhaps. I'll be happy to close the PR and have you submit the fix. In the end I ended up using Glob package instead.

Fuuzetsu avatar Jul 12 '15 18:07 Fuuzetsu

I'm not sure if my fix is correct either, that depends on what semantics we want.

@bos what do you think?

On July 12, 2015 7:02:23 PM GMT+01:00, Mateusz Kowalczyk [email protected] wrote:

Perhaps. I'll be happy to close the PR and have you submit the fix. In the end I ended up using Glob package instead.


Reply to this email directly or view it on GitHub: https://github.com/bos/filemanip/issues/9#issuecomment-120751223

nh2 avatar Jul 12 '15 18:07 nh2

I am also using 0.3.6.3, but I cannot reproduce it.

Prelude System.FilePath.GlobPattern> "foo/bar" ~~ "*/*"
True

Prelude System.FilePath.GlobPattern> "Hpack/Config.hs" ~~ "*/*.hs"
True

epsilonidiot avatar Jul 22 '15 11:07 epsilonidiot

@epsilonidiot Now this is odd. Here's what it looks like for me:

stack@ares:~$ ghc-pkg list filemanip
/opt/stackage/lts-2/ghc/lib/ghc-7.8.4.20141229/package.conf.d
   filemanip-0.3.6.3
stack@ares:~$ ghci
GHCi, version 7.8.4.20141229: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import System.FilePath.GlobPattern
Prelude System.FilePath.GlobPattern> "foo/bar" ~~ "*/*"
Loading package filepath-1.3.0.2 ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package bytestring-0.10.4.0 ... linking ... done.
Loading package old-locale-1.0.0.6 ... linking ... done.
Loading package time-1.4.2 ... linking ... done.
Loading package unix-2.7.0.1 ... linking ... done.
Loading package directory-1.2.1.0 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package mtl-2.1.3.1 ... linking ... done.
Loading package unix-compat-0.4.1.4 ... linking ... done.
Loading package filemanip-0.3.6.3 ... linking ... done.
False

nh2 avatar Jul 22 '15 12:07 nh2

@nh2 I figured out why I could not reproduce it. I am on Windows. The Windows pathSeparator is not '/'. matchDir (c:_) | c == pathSeparator = fail "path separator" was not excuted when "foo/bar" ~~ "*/*", thus I've got a True.

epsilonidiot avatar Jul 22 '15 19:07 epsilonidiot