aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-command.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-11-26 21:03:34 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-11-29 19:56:21 +0300
commit4f31188d4a7ce3cd9b657cc58e06632b9ccd7d8f (patch)
tree4a05e04c5a19132b2917856dd9ecfe0157412430 /bpkg/pkg-command.cxx
parent6e05e4079170efb84db25db6ca8f25886ab379d4 (diff)
Disallow installing/uninstalling packages from host configuration
Diffstat (limited to 'bpkg/pkg-command.cxx')
-rw-r--r--bpkg/pkg-command.cxx36
1 files changed, 32 insertions, 4 deletions
diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx
index 668aca1..0ff6a0d 100644
--- a/bpkg/pkg-command.cxx
+++ b/bpkg/pkg-command.cxx
@@ -114,10 +114,19 @@ namespace bpkg
collect_dependencies (const shared_ptr<selected_package>& p,
bool recursive,
bool package_cwd,
- vector<pkg_command_vars>& ps)
+ vector<pkg_command_vars>& ps,
+ bool allow_host_type)
{
for (const auto& pr: p->prerequisites)
{
+ if (!allow_host_type)
+ {
+ database& db (pr.first.database ());
+
+ if (db.type == host_config_type || db.type == build2_config_type)
+ continue;
+ }
+
shared_ptr<selected_package> d (pr.first.load ());
// The selected package can only be configured if all its dependencies
@@ -145,7 +154,11 @@ namespace bpkg
package_cwd});
if (recursive)
- collect_dependencies (d, recursive, package_cwd, ps);
+ collect_dependencies (d,
+ recursive,
+ package_cwd,
+ ps,
+ allow_host_type);
}
}
}
@@ -159,6 +172,7 @@ namespace bpkg
bool all,
const strings& all_patterns,
bool package_cwd,
+ bool allow_host_type,
cli::group_scanner& args)
{
tracer trace ("pkg_command");
@@ -254,6 +268,15 @@ namespace bpkg
vector<pkg_command_vars> ps;
{
database db (c, trace, true /* pre_attach */);
+
+ if (!allow_host_type && (db.type == host_config_type ||
+ db.type == build2_config_type))
+ {
+ fail << "unable to " << cmd << " from " << db.type
+ << " configuration" <<
+ info << "use target configuration instead";
+ }
+
transaction t (db);
// We need to suppress duplicate dependencies for the recursive command
@@ -261,7 +284,8 @@ namespace bpkg
//
session ses;
- auto add = [&db, &ps, recursive, immediate, package_cwd] (
+ auto add =
+ [&db, &ps, allow_host_type, recursive, immediate, package_cwd] (
const shared_ptr<selected_package>& p,
strings vars)
{
@@ -275,7 +299,11 @@ namespace bpkg
// Note that it can only be recursive or immediate but not both.
//
if (recursive || immediate)
- collect_dependencies (p, recursive, package_cwd, ps);
+ collect_dependencies (p,
+ recursive,
+ package_cwd,
+ ps,
+ allow_host_type);
};
if (all || !all_patterns.empty ())