aboutsummaryrefslogtreecommitdiff
path: root/tests/wildcard/driver.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-03-10 00:14:00 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-03-13 14:45:32 +0300
commitdc2c25e3f3182e8181a15487de4befca74a1ffec (patch)
treeb83cfb83188abd2c361f9eb839cc3600fb1f8f44 /tests/wildcard/driver.cxx
parent870da718e38555352343a46ce02fb46d5eb3a365 (diff)
Add flexibility to path search callback function
Diffstat (limited to 'tests/wildcard/driver.cxx')
-rw-r--r--tests/wildcard/driver.cxx32
1 files changed, 29 insertions, 3 deletions
diff --git a/tests/wildcard/driver.cxx b/tests/wildcard/driver.cxx
index b3aae62..5744969 100644
--- a/tests/wildcard/driver.cxx
+++ b/tests/wildcard/driver.cxx
@@ -39,7 +39,10 @@ int _CRT_glob = 0;
// Search for paths matching the pattern in the directory specified (absent
// directory means the current one). Print the matching canonicalized paths
// to STDOUT in the ascending order. Succeed if at least one matching path
-// is found. Note that this option must go first in the command line,
+// is found. Note that this option must go first in the command line.
+//
+// Also note that the driver excludes from search file system entries which
+// names start from dot, unless the pattern explicitly matches them.
//
// -n
// Do not sort paths found.
@@ -87,9 +90,32 @@ try
assert (i == argc); // All args parsed,
vector<path> paths;
- auto add = [&paths] (path&& p) -> bool
+ auto add =
+ [&paths, &start] (path&& p, const std::string& pt, bool interim) -> bool
{
- paths.emplace_back (move (p.canonicalize ()));
+ bool pd (!pt.empty () && pt[0] == '.'); // Dot-started pattern.
+
+ const path& fp (!p.empty ()
+ ? p
+ : path_cast<path> (!start.empty ()
+ ? start
+ : path::current_directory ()));
+
+ const string& s (fp.leaf ().string ());
+ assert (!s.empty ());
+
+ bool ld (s[0] == '.'); // Dot-started leaf.
+
+ // Skip dot-started names if pattern is not dot-started.
+ //
+ bool skip (ld && !pd);
+
+ if (interim)
+ return !skip;
+
+ if (!skip)
+ paths.emplace_back (move (p.canonicalize ()));
+
return true;
};