Skip to content

Commit d6b829d

Browse files
globbing: exclude files with leading dots.
This was the pre-globstar behaviour; now it is tested and documented.
1 parent 950f6d1 commit d6b829d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Cabal/Distribution/Simple/Glob.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Distribution.Verbosity
3232
import Distribution.Version
3333

3434
import System.Directory (getDirectoryContents, doesFileExist)
35-
import System.FilePath (joinPath, splitExtensions, splitDirectories, takeExtensions, (</>))
35+
import System.FilePath (joinPath, splitExtensions, splitDirectories, takeFileName, (</>))
3636

3737
-- Note throughout that we use splitDirectories, not splitPath. On
3838
-- Posix, this makes no difference, but, because Windows accepts both
@@ -108,9 +108,11 @@ fileGlobMatchesSegments pat (seg : segs) = case pat of
108108
dir == seg && fileGlobMatchesSegments pat' segs
109109
GlobFinal final -> case final of
110110
FinalMatch Recursive ext ->
111-
ext == takeExtensions (last $ seg:segs)
111+
let (candidateBase, candidateExts) = splitExtensions (last $ seg:segs)
112+
in ext == candidateExts && not (null candidateBase)
112113
FinalMatch NonRecursive ext ->
113-
null segs && ext == takeExtensions seg
114+
let (candidateBase, candidateExts) = splitExtensions seg
115+
in null segs && ext == candidateExts && not (null candidateBase)
114116
FinalLit filename ->
115117
null segs && filename == seg
116118

@@ -189,7 +191,10 @@ matchDirFileGlob' verbosity version rawDir filepath = case parseFileGlob version
189191
candidates <- case recursive of
190192
Recursive -> getDirectoryContentsRecursive prefix
191193
NonRecursive -> filterM (doesFileExist . (prefix </>)) =<< getDirectoryContents prefix
192-
return $ filter ((==) exts . takeExtensions) candidates
194+
let checkName candidate =
195+
let (candidateBase, candidateExts) = splitExtensions $ takeFileName candidate
196+
in not (null candidateBase) && exts == candidateExts
197+
return $ filter checkName candidates
193198
FinalLit fn -> do
194199
exists <- doesFileExist (dir </> joinedPrefix </> fn)
195200
return [ fn | exists ]

Cabal/doc/developing-packages.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,9 @@ describe the package as a whole:
996996
full extension must match exactly, so ``*.gz`` matches
997997
``foo.gz`` but not ``foo.tar.gz``.
998998

999+
- ``*`` wildcards will not match if the file name is empty (e.g.,
1000+
``*.html`` will not match ``foo/.html``).
1001+
9991002
- ``**`` wildcards can only appear as the final path component
10001003
before the file name (e.g., ``data/**/images/*.jpg`` is not
10011004
allowed). If a ``**`` wildcard is used, then the file name must

Cabal/tests/UnitTests/Distribution/Simple/Glob.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ sampleFileNames =
2222
, "b.html"
2323
, "b.html.gz"
2424
, "c.en.html"
25+
, "foo/.blah.html"
26+
, "foo/.html"
2527
, "foo/a"
2628
, "foo/a.html"
2729
, "foo/a.html.gz"
@@ -30,6 +32,7 @@ sampleFileNames =
3032
, "foo/b.html"
3133
, "foo/b.html.gz"
3234
, "foo/x.gz"
35+
, "foo/bar/.html"
3336
, "foo/bar/a.html"
3437
, "foo/bar/a.html.gz"
3538
, "foo/bar/a.tex"

0 commit comments

Comments
 (0)