aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-07 21:03:29 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-07 21:03:29 +0000
commit12a7a8b5a83d209153c95b2215f4ddcebd5c4c41 (patch)
treee5cc940469a04ae0acb99ba3cdd9b49052109c9e
parent9902ccae43ee3c54fd7c05154f5d41fb8392c69c (diff)
downloadpaludis-12a7a8b5a83d209153c95b2215f4ddcebd5c4c41.tar.gz
paludis-12a7a8b5a83d209153c95b2215f4ddcebd5c4c41.tar.xz
remove if dependent
-rw-r--r--paludis/resolver/decider.cc19
-rw-r--r--paludis/resolver/decider.hh2
-rw-r--r--paludis/resolver/resolver_functions.hh6
-rw-r--r--paludis/resolver/resolver_test.cc11
-rw-r--r--paludis/resolver/resolver_test.hh5
-rw-r--r--src/clients/cave/cmd_resolve_cmdline.cc8
-rw-r--r--src/clients/cave/cmd_resolve_cmdline.hh2
-rw-r--r--src/clients/cave/resolve_common.cc35
8 files changed, 74 insertions, 14 deletions
diff --git a/paludis/resolver/decider.cc b/paludis/resolver/decider.cc
index 09fc9af..8e9647d 100644
--- a/paludis/resolver/decider.cc
+++ b/paludis/resolver/decider.cc
@@ -162,13 +162,22 @@ Decider::_resolve_dependents()
{
_imp->env->trigger_notifier_callback(NotifierCallbackResolverStepEvent());
- if (_allowed_to_break(*s))
+ bool allowed_to_break(_allowed_to_break(*s)), should_remove(_remove_if_dependent(*s));
+
+ if (allowed_to_break && ! should_remove)
continue;
if (! _dependent(*s, changing.first, changing.second))
continue;
- throw InternalError(PALUDIS_HERE, "unsafe " + stringify(**s));
+ if (should_remove)
+ {
+ throw InternalError(PALUDIS_HERE, "remove " + stringify(**s));
+ }
+ else if (! allowed_to_break)
+ {
+ throw InternalError(PALUDIS_HERE, "unsafe " + stringify(**s));
+ }
}
}
}
@@ -1559,6 +1568,12 @@ Decider::_allowed_to_break(const std::tr1::shared_ptr<const PackageID> & id) con
return _imp->fns.allowed_to_break_fn()(id);
}
+bool
+Decider::_remove_if_dependent(const std::tr1::shared_ptr<const PackageID> & id) const
+{
+ return _imp->fns.remove_if_dependent_fn()(id);
+}
+
const std::tr1::shared_ptr<const PackageIDSequence>
Decider::_installed_ids(const Resolvent & resolvent) const
{
diff --git a/paludis/resolver/decider.hh b/paludis/resolver/decider.hh
index e509d52..a39cda9 100644
--- a/paludis/resolver/decider.hh
+++ b/paludis/resolver/decider.hh
@@ -193,6 +193,8 @@ namespace paludis
bool _allowed_to_break(const std::tr1::shared_ptr<const PackageID> &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+ bool _remove_if_dependent(const std::tr1::shared_ptr<const PackageID> &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+
const std::pair<
std::tr1::shared_ptr<const PackageIDSequence>,
std::tr1::shared_ptr<const PackageIDSequence> > _collect_changing() const PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/paludis/resolver/resolver_functions.hh b/paludis/resolver/resolver_functions.hh
index 7ef054b..ad9e8db 100644
--- a/paludis/resolver/resolver_functions.hh
+++ b/paludis/resolver/resolver_functions.hh
@@ -51,6 +51,7 @@ namespace paludis
struct get_use_existing_fn;
struct make_destination_filtered_generator_fn;
struct prefer_or_avoid_fn;
+ struct remove_if_dependent_fn;
struct take_dependency_fn;
}
@@ -114,6 +115,10 @@ namespace paludis
)> PreferOrAvoidFunction;
typedef std::tr1::function<bool (
+ const std::tr1::shared_ptr<const PackageID> &
+ )> RemoveIfDependentFunction;
+
+ typedef std::tr1::function<bool (
const Resolvent &,
const SanitisedDependency &,
const std::tr1::shared_ptr<const Reason> &
@@ -133,6 +138,7 @@ namespace paludis
NamedValue<n::make_destination_filtered_generator_fn,
MakeDestinationFilteredGeneratorFunction> make_destination_filtered_generator_fn;
NamedValue<n::prefer_or_avoid_fn, PreferOrAvoidFunction> prefer_or_avoid_fn;
+ NamedValue<n::remove_if_dependent_fn, RemoveIfDependentFunction> remove_if_dependent_fn;
NamedValue<n::take_dependency_fn, TakeDependencyFunction> take_dependency_fn;
};
}
diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc
index 506b2a5..3dccf11 100644
--- a/paludis/resolver/resolver_test.cc
+++ b/paludis/resolver/resolver_test.cc
@@ -261,6 +261,14 @@ paludis::resolver::resolver_test::allowed_to_remove_fn(
return s->end() != s->find(i->name());
}
+bool
+paludis::resolver::resolver_test::remove_if_dependent_fn(
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> & s,
+ const std::tr1::shared_ptr<const PackageID> & i)
+{
+ return s->end() != s->find(i->name());
+}
+
Tribool
paludis::resolver::resolver_test::prefer_or_avoid_fn(
const std::tr1::shared_ptr<const Map<QualifiedPackageName, bool> > & s,
@@ -287,6 +295,7 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s,
TestCase(s),
allowed_to_break_names(new QualifiedPackageNameSet),
allowed_to_remove_names(new QualifiedPackageNameSet),
+ remove_if_dependent_names(new QualifiedPackageNameSet),
prefer_or_avoid_names(new Map<QualifiedPackageName, bool>)
{
std::tr1::shared_ptr<Map<std::string, std::string> > keys(new Map<std::string, std::string>);
@@ -351,6 +360,8 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint
value_for<n::make_destination_filtered_generator_fn>(&make_destination_filtered_generator_fn),
value_for<n::prefer_or_avoid_fn>(std::tr1::bind(&prefer_or_avoid_fn,
prefer_or_avoid_names, std::tr1::placeholders::_1)),
+ value_for<n::remove_if_dependent_fn>(std::tr1::bind(&remove_if_dependent_fn,
+ remove_if_dependent_names, std::tr1::placeholders::_1)),
value_for<n::take_dependency_fn>(&take_dependency_fn)
);
}
diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh
index a1c7c6e..c25b006 100644
--- a/paludis/resolver/resolver_test.hh
+++ b/paludis/resolver/resolver_test.hh
@@ -99,6 +99,10 @@ namespace paludis
const std::tr1::shared_ptr<const QualifiedPackageNameSet> &,
const std::tr1::shared_ptr<const PackageID> &);
+ bool remove_if_dependent_fn(
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> &,
+ const std::tr1::shared_ptr<const PackageID> &);
+
Tribool prefer_or_avoid_fn(
const std::tr1::shared_ptr<const Map<QualifiedPackageName, bool> > &,
const QualifiedPackageName &);
@@ -115,6 +119,7 @@ namespace paludis
std::tr1::shared_ptr<FakeInstalledRepository> fake_inst_repo;
std::tr1::shared_ptr<QualifiedPackageNameSet> allowed_to_break_names;
std::tr1::shared_ptr<QualifiedPackageNameSet> allowed_to_remove_names;
+ std::tr1::shared_ptr<QualifiedPackageNameSet> remove_if_dependent_names;
std::tr1::shared_ptr<Map<QualifiedPackageName, bool> > prefer_or_avoid_names;
ResolverTestCase(const std::string & group, const std::string & test_name, const std::string & eapi,
diff --git a/src/clients/cave/cmd_resolve_cmdline.cc b/src/clients/cave/cmd_resolve_cmdline.cc
index 97385b3..1669470 100644
--- a/src/clients/cave/cmd_resolve_cmdline.cc
+++ b/src/clients/cave/cmd_resolve_cmdline.cc
@@ -69,10 +69,10 @@ ResolveCommandLineResolutionOptions::ResolveCommandLineResolutionOptions(args::A
a_uninstalls_may_break(&g_resolution_options, "uninstalls-may-break", 'u',
"Permit uninstalls that might break packages matching the specified specification. May be "
"specified multiple times. Use '*/*' to allow all packages to be broken."),
-// a_remove_if_dependent(&g_resolution_options, "remove-if-dependent", 'r',
-// "Remove dependent packages that might be broken by other changes if those packages match "
-// "the specified specification. May be specified multiple times. Use '*/*' to remove all "
-// "dependent packages that might be broken, recursively. Does not imply --permit-uninstall."),
+ a_remove_if_dependent(&g_resolution_options, "remove-if-dependent", 'r',
+ "Remove dependent packages that might be broken by other changes if those packages match "
+ "the specified specification. May be specified multiple times. Use '*/*' to remove all "
+ "dependent packages that might be broken, recursively. Does not imply --permit-uninstall."),
// a_purge(&g_resolution_options, "purge", 'P',
// "Purge packages matching the given specification, if they will no longer be used after "
// "a resolution. Use '*/*' to accept all purges, but note that by doing so you are putting "
diff --git a/src/clients/cave/cmd_resolve_cmdline.hh b/src/clients/cave/cmd_resolve_cmdline.hh
index eb85936..79eb58e 100644
--- a/src/clients/cave/cmd_resolve_cmdline.hh
+++ b/src/clients/cave/cmd_resolve_cmdline.hh
@@ -47,7 +47,7 @@ namespace paludis
args::StringSetArg a_permit_downgrade;
args::StringSetArg a_permit_any_version;
args::StringSetArg a_uninstalls_may_break;
-// args::StringSetArg a_remove_if_dependent;
+ args::StringSetArg a_remove_if_dependent;
// args::StringSetArg a_purge;
args::ArgsGroup g_keep_options;
diff --git a/src/clients/cave/resolve_common.cc b/src/clients/cave/resolve_common.cc
index 89d6b79..ec0f559 100644
--- a/src/clients/cave/resolve_common.cc
+++ b/src/clients/cave/resolve_common.cc
@@ -1031,7 +1031,7 @@ namespace
throw InternalError(PALUDIS_HERE, "unhandled dt");
}
- bool allowed_to_break_fn(
+ bool match_any(
const Environment * const env,
const PackageDepSpecList & list,
const std::tr1::shared_ptr<const PackageID> & i)
@@ -1044,17 +1044,28 @@ namespace
return false;
}
+ bool allowed_to_break_fn(
+ const Environment * const env,
+ const PackageDepSpecList & list,
+ const std::tr1::shared_ptr<const PackageID> & i)
+ {
+ return match_any(env, list, i);
+ }
+
bool allowed_to_remove_fn(
const Environment * const env,
const PackageDepSpecList & list,
const std::tr1::shared_ptr<const PackageID> & i)
{
- for (PackageDepSpecList::const_iterator l(list.begin()), l_end(list.end()) ;
- l != l_end ; ++l)
- if (match_package(*env, *l, *i, MatchPackageOptions()))
- return true;
+ return match_any(env, list, i);
+ }
- return false;
+ bool remove_if_dependent_fn(
+ const Environment * const env,
+ const PackageDepSpecList & list,
+ const std::tr1::shared_ptr<const PackageID> & i)
+ {
+ return match_any(env, list, i);
}
bool prefer_or_avoid_one(const Environment * const env, const QualifiedPackageName & q, const std::string & s)
@@ -1410,7 +1421,7 @@ paludis::cave::resolve_common(
int retcode(0);
InitialConstraints initial_constraints;
- PackageDepSpecList allowed_to_remove_specs, allowed_to_break_specs;
+ PackageDepSpecList allowed_to_remove_specs, allowed_to_break_specs, remove_if_dependent_specs;
for (args::StringSetArg::ConstIterator i(resolution_options.a_permit_uninstall.begin_args()),
i_end(resolution_options.a_permit_uninstall.end_args()) ;
@@ -1424,6 +1435,12 @@ paludis::cave::resolve_common(
allowed_to_break_specs.push_back(parse_user_package_dep_spec(*i, env.get(),
UserPackageDepSpecOptions() + updso_allow_wildcards));
+ for (args::StringSetArg::ConstIterator i(resolution_options.a_remove_if_dependent.begin_args()),
+ i_end(resolution_options.a_remove_if_dependent.end_args()) ;
+ i != i_end ; ++i)
+ remove_if_dependent_specs.push_back(parse_user_package_dep_spec(*i, env.get(),
+ UserPackageDepSpecOptions() + updso_allow_wildcards));
+
for (args::StringSetArg::ConstIterator i(resolution_options.a_preset.begin_args()),
i_end(resolution_options.a_preset.end_args()) ;
i != i_end ; ++i)
@@ -1487,6 +1504,10 @@ paludis::cave::resolve_common(
value_for<n::prefer_or_avoid_fn>(std::tr1::bind(&prefer_or_avoid_fn,
env.get(), std::tr1::cref(resolution_options),
std::tr1::placeholders::_1)),
+ value_for<n::remove_if_dependent_fn>(std::tr1::bind(&remove_if_dependent_fn,
+ env.get(),
+ std::tr1::cref(remove_if_dependent_specs),
+ std::tr1::placeholders::_1)),
value_for<n::take_dependency_fn>(std::tr1::bind(&take_dependency_fn, env.get(),
std::tr1::cref(resolution_options), std::tr1::placeholders::_1, std::tr1::placeholders::_2, std::tr1::placeholders::_3))