aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-08-16 17:57:54 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-08-16 17:57:54 +0300
commit0fb8bc472aafaacb6bff3b9f6a3af2df1aa8dc8a (patch)
tree067dbb2b5f8fc77ac2caa7715183e8f7f58fc609
parentffdf220f64c7362bf06f8d43aa9820ed4634fdbb (diff)
Fix uncaught invalid_path exception
-rw-r--r--bdep/config.cxx9
-rw-r--r--bdep/new.cxx20
-rw-r--r--bdep/project.cxx7
-rw-r--r--bdep/sync.cxx3
-rw-r--r--bdep/utility.cxx19
-rw-r--r--bdep/utility.hxx13
6 files changed, 46 insertions, 25 deletions
diff --git a/bdep/config.cxx b/bdep/config.cxx
index f207bad..d8cf33a 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -158,8 +158,7 @@ namespace bdep
// Make sure the configuration path is absolute and normalized. Also
// derive relative to project directory path if possible.
//
- path.complete ();
- path.normalize ();
+ normalize (path, "configuration");
verify_configuration_path (path, prj, pkgs);
@@ -272,8 +271,7 @@ namespace bdep
//
translate_path_name (prj, path, name);
- path.complete ();
- path.normalize ();
+ normalize (path, "configuration");
verify_configuration_path (path, prj, pkgs);
@@ -469,8 +467,7 @@ namespace bdep
if (!exists (path))
fail << "configuration directory " << path << " does not exist";
- path.complete ();
- path.normalize ();
+ normalize (path, "configuration");
}
catch (const invalid_path&)
{
diff --git a/bdep/new.cxx b/bdep/new.cxx
index a69508d..160a9ce 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -491,17 +491,17 @@ namespace bdep
if (o.package () || o.subdirectory ())
{
if (o.directory_specified ())
- (prj = o.directory ()).complete ().normalize ();
+ prj = normalize (o.directory (), "project");
else
prj = current_directory ();
out = o.output_dir_specified () ? o.output_dir () : prj / dir_path (n);
- out.complete ().normalize ();
+ normalize (out, "output");
}
else
{
out = o.output_dir_specified () ? o.output_dir () : dir_path (n);
- out.complete ().normalize ();
+ normalize (out, "output");
prj = out;
}
@@ -2152,19 +2152,15 @@ namespace bdep
auto output_parent_dir = [&o] ()
{
- return o.output_dir ().directory ().complete ().normalize ();
+ return normalize (o.output_dir (), "output");
};
if (o.package () || o.subdirectory ())
{
- auto project_dir = [&o] ()
- {
- return dir_path (o.directory ()).complete ().normalize ();
- };
-
- start_dir = o.output_dir_specified () ? output_parent_dir () :
- o.directory_specified () ? project_dir () :
- current_directory ();
+ start_dir =
+ o.output_dir_specified () ? output_parent_dir () :
+ o.directory_specified () ? normalize (o.directory (), "project") :
+ current_directory ();
// Get the actual project directory.
//
diff --git a/bdep/project.cxx b/bdep/project.cxx
index 21f6f09..7f80c9f 100644
--- a/bdep/project.cxx
+++ b/bdep/project.cxx
@@ -62,8 +62,7 @@ namespace bdep
{
for (dir_path d: po.config ())
{
- d.complete ();
- d.normalize ();
+ normalize (d, "configuration");
if (auto c = db.query_one<configuration> (query::path == d.string ()))
add (move (c));
@@ -135,9 +134,7 @@ namespace bdep
dir_path prj;
optional<dir_path> pkg;
- dir_path d (start);
- d.complete ();
- d.normalize ();
+ dir_path d (normalize (start, "project"));
for (; !d.empty (); d = d.directory ())
{
// Ignore errors when checking for file existence since we may be
diff --git a/bdep/sync.cxx b/bdep/sync.cxx
index ab2fb2b..26781eb 100644
--- a/bdep/sync.cxx
+++ b/bdep/sync.cxx
@@ -741,8 +741,7 @@ namespace bdep
for (dir_path d: o.config ())
{
- d.complete ();
- d.normalize ();
+ normalize (d, "configuration");
if (open && d.string () == *open)
continue;
diff --git a/bdep/utility.cxx b/bdep/utility.cxx
index 9c8057e..148610b 100644
--- a/bdep/utility.cxx
+++ b/bdep/utility.cxx
@@ -95,6 +95,25 @@ namespace bdep
}
}
+ dir_path&
+ normalize (dir_path& d, const char* what)
+ {
+ try
+ {
+ d.complete ().normalize ();
+ }
+ catch (const invalid_path& e)
+ {
+ fail << "invalid " << what << " directory " << e.path;
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to obtain current directory: " << e;
+ }
+
+ return d;
+ }
+
bool
exists (const path& f, bool ignore_error)
{
diff --git a/bdep/utility.hxx b/bdep/utility.hxx
index 133896f..7f02b3c 100644
--- a/bdep/utility.hxx
+++ b/bdep/utility.hxx
@@ -119,6 +119,19 @@ namespace bdep
dir_path
current_directory ();
+ // Normalize a directory path. Also make the relative path absolute using
+ // the current directory.
+ //
+ dir_path&
+ normalize (dir_path&, const char* what);
+
+ inline dir_path
+ normalize (const dir_path& d, const char* what)
+ {
+ dir_path r (d);
+ return move (normalize (r, what));
+ }
+
// Progress.
//
extern bool stderr_term; // True if stderr is a terminal.