diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-04-12 10:51:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-04-12 10:51:40 +0200 |
commit | 33be784e4b991a95d3ef14a6ef555f1299ec7021 (patch) | |
tree | 067908546e7054b21b99f5553505cf3b4bcd5d19 | |
parent | d6e9703edbd28508882fab3ce698617d036abfdd (diff) |
Diagnose invalid directories specified on command line
GitHub issue #376.
-rw-r--r-- | build2/b.cxx | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/build2/b.cxx b/build2/b.cxx index f0c9338..8decadf 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -856,12 +856,19 @@ main (int argc, char* argv[]) } } - if (out_base.relative ()) - out_base = work / out_base; + try + { + if (out_base.relative ()) + out_base = work / out_base; - // This directory came from the command line so actualize it. - // - out_base.normalize (true); + // This directory came from the command line so actualize it. + // + out_base.normalize (true); + } + catch (const invalid_path& e) + { + fail << "invalid out_base directory '" << e.path << "'"; + } // The order in which we determine the roots depends on whether // src_base was specified explicitly. @@ -887,12 +894,19 @@ main (int argc, char* argv[]) if (!exists (src_base)) fail << "src_base directory " << src_base << " does not exist"; - if (src_base.relative ()) - src_base = work / src_base; + try + { + if (src_base.relative ()) + src_base = work / src_base; - // Also came from the command line, so actualize. - // - src_base.normalize (true); + // Also came from the command line, so actualize. + // + src_base.normalize (true); + } + catch (const invalid_path& e) + { + fail << "invalid src_base directory '" << e.path << "'"; + } // Make sure out_base is not a subdirectory of src_base. Who would // want to do that, you may ask. Well, you would be surprised... @@ -1459,10 +1473,17 @@ main (int argc, char* argv[]) // dir_path& d (tn.dir); - if (d.relative ()) - d = work / d; + try + { + if (d.relative ()) + d = work / d; - d.normalize (true); // Actualize since came from command line. + d.normalize (true); // Actualize since came from command line. + } + catch (const invalid_path& e) + { + fail << "invalid target directory '" << e.path << "'"; + } if (ts.forwarded) d = rs.out_path () / d.leaf (rs.src_path ()); // Remap. |