aboutsummaryrefslogtreecommitdiff
path: root/paludis
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-06 20:54:54 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-08 10:53:06 +0100
commit8ef0fd8929c0a6a16ff450565b811c9636a695c4 (patch)
treee15d0d005134e06c424a3a55e5a2f5cadb03445a /paludis
parentea6612acb9d1ccbbe9fbf784655b70ac2b694b0b (diff)
downloadpaludis-8ef0fd8929c0a6a16ff450565b811c9636a695c4.tar.gz
paludis-8ef0fd8929c0a6a16ff450565b811c9636a695c4.tar.xz
ConfirmHelper
Diffstat (limited to 'paludis')
-rw-r--r--paludis/resolver/Makefile.am2
-rw-r--r--paludis/resolver/confirm_helper-fwd.hh31
-rw-r--r--paludis/resolver/confirm_helper.cc185
-rw-r--r--paludis/resolver/confirm_helper.hh58
-rw-r--r--paludis/resolver/resolver_test.cc13
-rw-r--r--paludis/resolver/resolver_test.hh6
6 files changed, 281 insertions, 14 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index 2a7b6f7a6..f184a60fc 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -35,6 +35,7 @@ noinst_HEADERS = \
can_use_helper.hh can_use_helper-fwd.hh \
change_by_resolvent.hh change_by_resolvent-fwd.hh \
change_type.hh change_type-fwd.hh change_type-se.hh \
+ confirm_helper.hh confirm_helper-fwd.hh \
constraint.hh constraint-fwd.hh \
decider.hh decider-fwd.hh \
decision.hh decision-fwd.hh \
@@ -75,6 +76,7 @@ libpaludisresolver_a_SOURCES = \
can_use_helper.cc \
change_by_resolvent.cc \
change_type.cc \
+ confirm_helper.cc \
constraint.cc \
decider.cc \
decision.cc \
diff --git a/paludis/resolver/confirm_helper-fwd.hh b/paludis/resolver/confirm_helper-fwd.hh
new file mode 100644
index 000000000..55898cbc6
--- /dev/null
+++ b/paludis/resolver/confirm_helper-fwd.hh
@@ -0,0 +1,31 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_CONFIRM_HELPER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_CONFIRM_HELPER_FWD_HH 1
+
+namespace paludis
+{
+ namespace resolver
+ {
+ struct ConfirmHelper;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/confirm_helper.cc b/paludis/resolver/confirm_helper.cc
new file mode 100644
index 000000000..8edba86c7
--- /dev/null
+++ b/paludis/resolver/confirm_helper.cc
@@ -0,0 +1,185 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/resolver/confirm_helper.hh>
+#include <paludis/resolver/reason.hh>
+#include <paludis/resolver/constraint.hh>
+#include <paludis/resolver/resolvent.hh>
+#include <paludis/resolver/resolution.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/required_confirmations.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/make_null_shared_ptr.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/package_id.hh>
+#include <paludis/package_dep_spec_collection.hh>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+namespace paludis
+{
+ template <>
+ struct Imp<ConfirmHelper>
+ {
+ const Environment * const env;
+ PackageDepSpecCollection permit_downgrade_specs;
+ PackageDepSpecCollection permit_old_version_specs;
+ PackageDepSpecCollection allowed_to_break_specs;
+ bool allowed_to_break_system;
+
+ Imp(const Environment * const e) :
+ env(e),
+ allowed_to_break_system(false)
+ {
+ }
+ };
+}
+
+ConfirmHelper::ConfirmHelper(const Environment * const e) :
+ Pimp<ConfirmHelper>(e)
+{
+}
+
+ConfirmHelper::~ConfirmHelper() = default;
+
+void
+ConfirmHelper::add_permit_downgrade_spec(const PackageDepSpec & spec)
+{
+ _imp->permit_downgrade_specs.insert(spec);
+}
+
+void
+ConfirmHelper::add_permit_old_version_spec(const PackageDepSpec & spec)
+{
+ _imp->permit_old_version_specs.insert(spec);
+}
+
+void
+ConfirmHelper::add_allowed_to_break_spec(const PackageDepSpec & spec)
+{
+ _imp->allowed_to_break_specs.insert(spec);
+}
+
+void
+ConfirmHelper::set_allowed_to_break_system(const bool b)
+{
+ _imp->allowed_to_break_system = b;
+}
+
+namespace
+{
+ struct ConfirmVisitor
+ {
+ const Environment * const env;
+ const PackageDepSpecCollection & permit_downgrade_specs;
+ const PackageDepSpecCollection & permit_old_version_specs;
+ const PackageDepSpecCollection & allowed_to_break_specs;
+ const bool allowed_to_break_system;
+ const std::shared_ptr<const PackageID> id;
+
+ bool visit(const DowngradeConfirmation &) const
+ {
+ if (id)
+ if (permit_downgrade_specs.match_any(env, id, { }))
+ return true;
+
+ return false;
+ }
+
+ bool visit(const NotBestConfirmation &) const
+ {
+ if (id)
+ if (permit_old_version_specs.match_any(env, id, { }))
+ return true;
+
+ return false;
+ }
+
+ bool visit(const BreakConfirmation &) const
+ {
+ if (id)
+ if (allowed_to_break_specs.match_any(env, id, { }))
+ return true;
+
+ return false;
+ }
+
+ bool visit(const RemoveSystemPackageConfirmation &) const
+ {
+ return allowed_to_break_system;
+ }
+
+ bool visit(const MaskedConfirmation &) const
+ {
+ return false;
+ }
+
+ bool visit(const ChangedChoicesConfirmation &) const
+ {
+ return false;
+ }
+ };
+
+ struct IDVisitor
+ {
+ std::shared_ptr<const PackageID> visit(const ChangesToMakeDecision & decision) const
+ {
+ return decision.origin_id();
+ }
+
+ std::shared_ptr<const PackageID> visit(const BreakDecision & decision) const
+ {
+ return decision.existing_id();
+ }
+
+ std::shared_ptr<const PackageID> visit(const ExistingNoChangeDecision & decision) const
+ {
+ return decision.existing_id();
+ }
+
+ std::shared_ptr<const PackageID> visit(const NothingNoChangeDecision &) const
+ {
+ return make_null_shared_ptr();
+ }
+
+ std::shared_ptr<const PackageID> visit(const RemoveDecision &) const
+ {
+ return make_null_shared_ptr();
+ }
+
+ std::shared_ptr<const PackageID> visit(const UnableToMakeDecision &) const
+ {
+ return make_null_shared_ptr();
+ }
+ };
+}
+
+bool
+ConfirmHelper::operator() (
+ const std::shared_ptr<const Resolution> & resolution,
+ const std::shared_ptr<const RequiredConfirmation> & confirmation) const
+{
+ auto id(resolution->decision()->accept_returning<std::shared_ptr<const PackageID> >(IDVisitor()));
+ return confirmation->accept_returning<bool>(ConfirmVisitor{_imp->env, _imp->permit_downgrade_specs,
+ _imp->permit_old_version_specs, _imp->allowed_to_break_specs, _imp->allowed_to_break_system, id});
+}
+
+template class Pimp<ConfirmHelper>;
+
diff --git a/paludis/resolver/confirm_helper.hh b/paludis/resolver/confirm_helper.hh
new file mode 100644
index 000000000..2ecc88781
--- /dev/null
+++ b/paludis/resolver/confirm_helper.hh
@@ -0,0 +1,58 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_CONFIRM_HELPER_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_CONFIRM_HELPER_HH 1
+
+#include <paludis/resolver/confirm_helper-fwd.hh>
+#include <paludis/resolver/resolution-fwd.hh>
+#include <paludis/resolver/required_confirmations-fwd.hh>
+#include <paludis/util/pimp.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <memory>
+
+namespace paludis
+{
+ namespace resolver
+ {
+ class PALUDIS_VISIBLE ConfirmHelper :
+ private Pimp<ConfirmHelper>
+ {
+ public:
+ explicit ConfirmHelper(const Environment * const);
+ ~ConfirmHelper();
+
+ void add_permit_downgrade_spec(const PackageDepSpec &);
+ void add_permit_old_version_spec(const PackageDepSpec &);
+ void add_allowed_to_break_spec(const PackageDepSpec &);
+ void set_allowed_to_break_system(const bool);
+
+ bool operator() (
+ const std::shared_ptr<const Resolution> &,
+ const std::shared_ptr<const RequiredConfirmation> &) const;
+ };
+ }
+
+ extern template class Pimp<resolver::ConfirmHelper>;
+}
+
+#endif
diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc
index 1141fa331..3ac6bfa5d 100644
--- a/paludis/resolver/resolver_test.cc
+++ b/paludis/resolver/resolver_test.cc
@@ -231,14 +231,6 @@ paludis::resolver::resolver_test::order_early_fn(
return indeterminate;
}
-bool
-paludis::resolver::resolver_test::confirm_fn(
- const std::shared_ptr<const Resolution> &,
- const std::shared_ptr<const RequiredConfirmation> &)
-{
- return true;
-}
-
const std::shared_ptr<ConstraintSequence>
paludis::resolver::resolver_test::get_constraints_for_dependent_fn(
const std::shared_ptr<const Resolution> &,
@@ -331,7 +323,8 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s,
allow_choice_changes_helper(&env),
allowed_to_remove_helper(&env),
always_via_binary_helper(&env),
- can_use_helper(&env)
+ can_use_helper(&env),
+ confirm_helper(&env)
{
std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>());
keys->insert("format", "e");
@@ -381,7 +374,7 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint
n::allowed_to_remove_fn() = std::cref(allowed_to_remove_helper),
n::always_via_binary_fn() = std::cref(always_via_binary_helper),
n::can_use_fn() = std::cref(can_use_helper),
- n::confirm_fn() = &confirm_fn,
+ n::confirm_fn() = std::cref(confirm_helper),
n::find_repository_for_fn() = std::bind(&find_repository_for_fn,
&env, std::placeholders::_1, std::placeholders::_2),
n::get_constraints_for_dependent_fn() = &get_constraints_for_dependent_fn,
diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh
index 743a20a59..47a8d6206 100644
--- a/paludis/resolver/resolver_test.hh
+++ b/paludis/resolver/resolver_test.hh
@@ -39,6 +39,7 @@
#include <paludis/resolver/allowed_to_remove_helper.hh>
#include <paludis/resolver/always_via_binary_helper.hh>
#include <paludis/resolver/can_use_helper.hh>
+#include <paludis/resolver/confirm_helper.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
@@ -133,10 +134,6 @@ namespace paludis
Tribool order_early_fn(
const std::shared_ptr<const Resolution> &);
- bool confirm_fn(
- const std::shared_ptr<const Resolution> &,
- const std::shared_ptr<const RequiredConfirmation> &);
-
struct ResolverTestCase : test::TestCase
{
TestEnvironment env;
@@ -149,6 +146,7 @@ namespace paludis
AllowedToRemoveHelper allowed_to_remove_helper;
AlwaysViaBinaryHelper always_via_binary_helper;
CanUseHelper can_use_helper;
+ ConfirmHelper confirm_helper;
ResolverTestCase(const std::string & group, const std::string & test_name, const std::string & eapi,
const std::string & layout);