aboutsummaryrefslogtreecommitdiff
path: root/libbutl/filesystem.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-12-01 19:35:43 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-12-01 22:30:21 +0300
commit49531f69ed251f0caf030e19afbf6a0fd1868aa6 (patch)
treeaae14a5edc1772d30f75aa21de131eb7d7f15ce1 /libbutl/filesystem.cxx
parentabfee51c362cb1ed2e8eb62fec12b3eb5ca03fb0 (diff)
Change path_search() to only match directory absent components in 'match absent' mode
Diffstat (limited to 'libbutl/filesystem.cxx')
-rw-r--r--libbutl/filesystem.cxx29
1 files changed, 4 insertions, 25 deletions
diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx
index 736426b..2fae1f9 100644
--- a/libbutl/filesystem.cxx
+++ b/libbutl/filesystem.cxx
@@ -1737,32 +1737,11 @@ namespace butl
// component omitted, unless this is the only pattern component.
//
if ((fl & path_match_flags::match_absent) != path_match_flags::none &&
+ pc.to_directory () &&
+ (!pattern_dir.empty () || !simple) &&
pc.string ().find_first_not_of ('*') == string::npos &&
- (!pattern_dir.empty () || !simple))
- {
- // Stripping the (leading) absent-matching pattern component and calling
- // search() with the resulting pattern and the same pattern dir works in
- // most cases, except for a simple pattern. In the latter case, the
- // pattern becomes empty and its type information gets lost. In other
- // words, the patterns a/b/*/ and a/b/* become indistinguishable. Thus,
- // for such a corner case we will strip the leaf from the pattern dir
- // and use it as a pattern, stripping the trailing separator, if
- // required. So for the above examples the search() calls will be as
- // follows:
- //
- // search(b/, a/)
- // search(b, a/)
- //
- const dir_path& d (!simple ? pattern_dir : pattern_dir.directory ());
-
- const path& p (
- !simple ? pattern.leaf (pc) :
- pattern.to_directory () ? pattern_dir.leaf () :
- path (pattern_dir.leaf ().string ())); // Strip the trailing separator.
-
- if (!search (p, d, fl, func, filesystem))
- return false;
- }
+ !search (pattern.leaf (pc), pattern_dir, fl, func, filesystem))
+ return false;
return true;
}