diff options
Diffstat (limited to 'libbuild2/functions-filesystem.cxx')
-rw-r--r-- | libbuild2/functions-filesystem.cxx | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/libbuild2/functions-filesystem.cxx b/libbuild2/functions-filesystem.cxx index 54c5315..665a0f3 100644 --- a/libbuild2/functions-filesystem.cxx +++ b/libbuild2/functions-filesystem.cxx @@ -1,12 +1,13 @@ // file : libbuild2/functions-filesystem.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#include <libbutl/filesystem.mxx> +#include <libbutl/filesystem.hxx> #include <libbuild2/function.hxx> #include <libbuild2/variable.hxx> using namespace std; +using namespace butl; namespace build2 { @@ -29,12 +30,27 @@ namespace build2 return true; }; + auto dangling = [] (const dir_entry& de) + { + bool sl (de.ltype () == entry_type::symlink); + + warn << "skipping " + << (sl ? "dangling symlink" : "inaccessible entry") << ' ' + << de.base () / de.path (); + + return true; + }; + // Print paths "as is" in the diagnostics. // try { if (pattern.absolute ()) - path_search (pattern, add); + path_search (pattern, + add, + dir_path () /* start */, + path_match_flags::follow_symlinks, + dangling); else { // An absolute start directory must be specified for the relative @@ -54,7 +70,11 @@ namespace build2 << "' is relative"; } - path_search (pattern, add, *start); + path_search (pattern, + add, + *start, + path_match_flags::follow_symlinks, + dangling); } } catch (const system_error& e) @@ -78,33 +98,47 @@ namespace build2 void filesystem_functions (function_map& m) { + // @@ Maybe we should have the ability to mark the whole family as not + // pure? + function_family f (m, "filesystem"); - // path_search + // $path_search(<pattern>[, <start-dir>]) // - // Return filesystem paths that match the pattern. If the pattern is an - // absolute path, then the start directory is ignored (if present). - // Otherwise, the start directory must be specified and be absolute. + // Return filesystem paths that match the shell-like wildcard pattern. If + // the pattern is an absolute path, then the start directory is ignored + // (if present). Otherwise, the start directory must be specified and be + // absolute. + // + // Note that this function is not pure. // - f["path_search"] = [](path pattern, optional<dir_path> start) - { - return path_search (pattern, start); - }; - f["path_search"] = [](path pattern, names start) + // @@ In the future we may want to add a flag that controls the + // dangling/inaccessible treatment. + // { - return path_search (pattern, convert<dir_path> (move (start))); - }; + auto e (f.insert ("path_search", false)); - f["path_search"] = [](names pattern, optional<dir_path> start) - { - return path_search (convert<path> (move (pattern)), start); - }; + e += [](path pattern, optional<dir_path> start) + { + return path_search (pattern, start); + }; - f["path_search"] = [](names pattern, names start) - { - return path_search (convert<path> (move (pattern)), - convert<dir_path> (move (start))); - }; + e += [](path pattern, names start) + { + return path_search (pattern, convert<dir_path> (move (start))); + }; + + e += [](names pattern, optional<dir_path> start) + { + return path_search (convert<path> (move (pattern)), start); + }; + + e += [](names pattern, names start) + { + return path_search (convert<path> (move (pattern)), + convert<dir_path> (move (start))); + }; + } } } |