diff options
-rw-r--r-- | build2/parser.cxx | 20 | ||||
-rw-r--r-- | tests/name/pattern.test | 24 |
2 files changed, 39 insertions, 5 deletions
diff --git a/build2/parser.cxx b/build2/parser.cxx index 50fcc06..b7f1930 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -2422,22 +2422,32 @@ namespace build2 unique = (i == string::npos || p.find ("**", i + 2) == string::npos); } - //@@ PAT TODO: weed out starting with dot (unless pattern starts - // with dot; last component? intermediate components?). - // function<bool (path&&, const string&, bool)> func; if (unique) - func = [a, &append] (path&& m, const string&, bool interm) + func = [a, &append] (path&& m, const string& p, bool interm) { + // Ignore entries that start with a dot unless the pattern that + // matched them also starts with a dot. + // + const string& s (m.string ()); + if (p[0] != '.' && s[path::traits::find_leaf (s)] == '.') + return !interm; + if (!interm) append (move (m).representation (), a); + return true; }; else - func = [a, &include_match] (path&& m, const string&, bool interm) + func = [a, &include_match] (path&& m, const string& p, bool interm) { + const string& s (m.string ()); + if (p[0] != '.' && s[path::traits::find_leaf (s)] == '.') + return !interm; + if (!interm) include_match (move (m).representation (), a); + return true; }; diff --git a/tests/name/pattern.test b/tests/name/pattern.test index e9e1c45..ae0cc3a 100644 --- a/tests/name/pattern.test +++ b/tests/name/pattern.test @@ -133,6 +133,30 @@ EOI $* <'print dir{*/ -bar/}' >/'dir{foo/}' } +: dot +: +: Test filtering of hidden files/directories. +{ + touch foo.txt .foo.txt; + $* <'print *.txt' >'foo.txt' : file-excl + + touch foo.txt .foo.txt; + $* <'print .*.txt' >'.foo.txt' : file-incl + + mkdir dir .dir; + $* <'print */' >/'dir/' : dir-excl + + mkdir dir .dir; + $* <'print .*/' >/'.dir/' : dir-incl + + mkdir dir .dir && touch dir/foo.txt .dir/foo.txt; + $* <'print */*.txt' >/'dir/foo.txt'; + $* <'print **.txt' >/'dir/foo.txt' : dir-interm-excl + + mkdir dir .dir && touch dir/foo.txt .dir/foo.txt; + $* <'print .*/*.txt' >/'.dir/foo.txt' : dir-interm-incl +} + : expansion : : Test interaction with expansion/concatenation/re-parse. |