Commit d6b829dd authored by quasicomputational's avatar quasicomputational

globbing: exclude files with leading dots.

This was the pre-globstar behaviour; now it is tested and documented.
parent 950f6d1a
......@@ -32,7 +32,7 @@ import Distribution.Verbosity
import Distribution.Version
import System.Directory (getDirectoryContents, doesFileExist)
import System.FilePath (joinPath, splitExtensions, splitDirectories, takeExtensions, (</>))
import System.FilePath (joinPath, splitExtensions, splitDirectories, takeFileName, (</>))
-- Note throughout that we use splitDirectories, not splitPath. On
-- Posix, this makes no difference, but, because Windows accepts both
......@@ -108,9 +108,11 @@ fileGlobMatchesSegments pat (seg : segs) = case pat of
dir == seg && fileGlobMatchesSegments pat' segs
GlobFinal final -> case final of
FinalMatch Recursive ext ->
ext == takeExtensions (last $ seg:segs)
let (candidateBase, candidateExts) = splitExtensions (last $ seg:segs)
in ext == candidateExts && not (null candidateBase)
FinalMatch NonRecursive ext ->
null segs && ext == takeExtensions seg
let (candidateBase, candidateExts) = splitExtensions seg
in null segs && ext == candidateExts && not (null candidateBase)
FinalLit filename ->
null segs && filename == seg
......@@ -189,7 +191,10 @@ matchDirFileGlob' verbosity version rawDir filepath = case parseFileGlob version
candidates <- case recursive of
Recursive -> getDirectoryContentsRecursive prefix
NonRecursive -> filterM (doesFileExist . (prefix </>)) =<< getDirectoryContents prefix
return $ filter ((==) exts . takeExtensions) candidates
let checkName candidate =
let (candidateBase, candidateExts) = splitExtensions $ takeFileName candidate
in not (null candidateBase) && exts == candidateExts
return $ filter checkName candidates
FinalLit fn -> do
exists <- doesFileExist (dir </> joinedPrefix </> fn)
return [ fn | exists ]
......
......@@ -996,6 +996,9 @@ describe the package as a whole:
full extension must match exactly, so ``*.gz`` matches
``foo.gz`` but not ``foo.tar.gz``.
- ``*`` wildcards will not match if the file name is empty (e.g.,
``*.html`` will not match ``foo/.html``).
- ``**`` wildcards can only appear as the final path component
before the file name (e.g., ``data/**/images/*.jpg`` is not
allowed). If a ``**`` wildcard is used, then the file name must
......
......@@ -22,6 +22,8 @@ sampleFileNames =
, "b.html"
, "b.html.gz"
, "c.en.html"
, "foo/.blah.html"
, "foo/.html"
, "foo/a"
, "foo/a.html"
, "foo/a.html.gz"
......@@ -30,6 +32,7 @@ sampleFileNames =
, "foo/b.html"
, "foo/b.html.gz"
, "foo/x.gz"
, "foo/bar/.html"
, "foo/bar/a.html"
, "foo/bar/a.html.gz"
, "foo/bar/a.tex"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment