aboutsummaryrefslogtreecommitdiff
path: root/bdep/config.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-05-22 08:05:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-05-22 08:07:05 +0200
commitc2589526054b394052fe59e29e58fcdd284d81f3 (patch)
treefaed5a338274ec8cd8720e47572d39f2864443d6 /bdep/config.cxx
parent8717405eb2869115a5abe4b146fa5e73421467d4 (diff)
Diagnose if configuration is inside package
Diffstat (limited to 'bdep/config.cxx')
-rw-r--r--bdep/config.cxx49
1 files changed, 40 insertions, 9 deletions
diff --git a/bdep/config.cxx b/bdep/config.cxx
index d0b641e..21dfa38 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -116,9 +116,27 @@ namespace bdep
name = move (s);
}
+ // Verify the configuration directory is not inside one of the packages.
+ //
+ static void
+ verify_configuration_path (const dir_path& cfg,
+ const dir_path& prj,
+ const package_locations& pkgs)
+ {
+ for (const package_location& p: pkgs)
+ {
+ dir_path d (prj / p.path); // Should already be normalized.
+
+ if (cfg.sub (d))
+ fail << "configuration directory " << cfg << " is inside package "
+ << p.name << " (" << d << ")";
+ }
+ }
+
shared_ptr<configuration>
cmd_config_add (const configuration_add_options& ao,
const dir_path& prj,
+ const package_locations& pkgs,
database& db,
dir_path path,
optional<string> name,
@@ -133,6 +151,17 @@ namespace bdep
if (!exists (path))
fail << "configuration directory " << path << " does not exist";
+ // Make sure the configuration path is absolute and normalized. Also
+ // derive relative to project directory path if possible.
+ //
+ path.complete ();
+ path.normalize ();
+
+ verify_configuration_path (path, prj, pkgs);
+
+ optional<dir_path> rel_path;
+ try {rel_path = path.relative (prj);} catch (const invalid_path&) {}
+
transaction t (db.begin ());
using count = configuration_count;
@@ -171,15 +200,6 @@ namespace bdep
}
}
- // Make sure the configuration path is absolute and normalized. Also
- // derive relative to project directory path if possible.
- //
- path.complete ();
- path.normalize ();
-
- optional<dir_path> rel_path;
- try {rel_path = path.relative (prj);} catch (const invalid_path&) {}
-
shared_ptr<configuration> r (
new configuration {
id,
@@ -237,14 +257,22 @@ namespace bdep
cmd_config_create (const common_options& co,
const configuration_add_options& ao,
const dir_path& prj,
+ const package_locations& pkgs,
database& db,
dir_path path,
cli::scanner& cfg_args,
optional<string> name,
optional<uint64_t> id)
{
+ // Similar logic to *_add().
+ //
translate_path_name (prj, path, name);
+ path.complete ();
+ path.normalize ();
+
+ verify_configuration_path (path, prj, pkgs);
+
// Call bpkg to create the configuration.
//
{
@@ -262,6 +290,7 @@ namespace bdep
return cmd_config_add (ao,
prj,
+ package_locations {}, // Already verified.
db,
move (path),
move (name),
@@ -306,6 +335,7 @@ namespace bdep
cmd_config_add (o,
prj,
+ load_packages (prj, true /* allow_empty */),
db,
move (path),
move (name),
@@ -354,6 +384,7 @@ namespace bdep
cmd_config_create (o,
o,
prj,
+ load_packages (prj, true /* allow_empty */),
db,
move (path),
args,