aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-01-18 14:03:04 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-01-18 14:03:04 +0000
commita62869d0c57a9ec2f904d5d5dd5c739fcafa7f9a (patch)
treec74f577e9c8140f57d31a058a71f6c8525489da9
parent323de8bbeb0cd5b792b18842a32d833c2761caa4 (diff)
downloadpaludis-a62869d0c57a9ec2f904d5d5dd5c739fcafa7f9a.tar.gz
paludis-a62869d0c57a9ec2f904d5d5dd5c739fcafa7f9a.tar.xz
Implement DepList downgrade control. Fixes: ticket:27
-rw-r--r--paludis/dep_list/dep_list.cc34
-rw-r--r--paludis/dep_list/dep_list.sr1
-rw-r--r--paludis/dep_list/exceptions.cc8
-rw-r--r--paludis/dep_list/exceptions.hh20
-rw-r--r--paludis/dep_list/options.hh13
-rw-r--r--src/clients/paludis/command_line.cc6
-rw-r--r--src/clients/paludis/command_line.hh1
-rw-r--r--src/clients/paludis/install.cc12
8 files changed, 95 insertions, 0 deletions
diff --git a/paludis/dep_list/dep_list.cc b/paludis/dep_list/dep_list.cc
index 9b7c977..fd4be5e 100644
--- a/paludis/dep_list/dep_list.cc
+++ b/paludis/dep_list/dep_list.cc
@@ -45,6 +45,7 @@ DepListOptions::DepListOptions() :
reinstall_scm(dl_reinstall_scm_never),
target_type(dl_target_package),
upgrade(dl_upgrade_always),
+ downgrade(dl_downgrade_as_needed),
new_slots(dl_new_slots_always),
fall_back(dl_fall_back_as_needed_except_targets),
installed_deps_pre(dl_deps_discard),
@@ -632,6 +633,39 @@ DepList::AddVisitor::visit(const PackageDepAtom * const a)
Log::get_instance()->message(ll_debug, lc_context, "No installed packages in SLOT '"
+ stringify(slot) + "', taking uninstalled package '" + stringify(*best_visible_candidate) + "'");
+ /* if this is a downgrade, make sure that that's ok */
+ switch (d->_imp->opts.downgrade)
+ {
+ case dl_downgrade_as_needed:
+ break;
+
+ case dl_downgrade_error:
+ case dl_downgrade_warning:
+ {
+ PackageDatabaseEntryCollection::Pointer are_we_downgrading(
+ d->_imp->env->package_database()->query(PackageDepAtom(
+ stringify(a->package()) + ":" + stringify(slot)),
+ is_installed_only, qo_order_by_version));
+
+ if (are_we_downgrading->empty())
+ break;
+
+ if (are_we_downgrading->last()->version <= best_visible_candidate->version)
+ break;
+
+ if (d->_imp->opts.downgrade == dl_downgrade_error)
+ throw DowngradeNotAllowedError(stringify(*best_visible_candidate),
+ stringify(*are_we_downgrading->last()));
+
+ Log::get_instance()->message(ll_warning, lc_context, "Downgrade to '" + stringify(*best_visible_candidate)
+ + "' from '" + stringify(*are_we_downgrading->last()) + "' forced");
+ }
+ break;
+
+ case last_dl_downgrade:
+ ;
+ }
+
d->add_package(*best_visible_candidate, a->tag());
}
diff --git a/paludis/dep_list/dep_list.sr b/paludis/dep_list/dep_list.sr
index 0c7612e..804b018 100644
--- a/paludis/dep_list/dep_list.sr
+++ b/paludis/dep_list/dep_list.sr
@@ -7,6 +7,7 @@ make_class_DepListOptions()
key reinstall_scm DepListReinstallScmOption
key target_type DepListTargetType
key upgrade DepListUpgradeOption
+ key downgrade DepListDowngradeOption
key new_slots DepListNewSlotsOption
key fall_back DepListFallBackOption
diff --git a/paludis/dep_list/exceptions.cc b/paludis/dep_list/exceptions.cc
index ce54041..489bc28 100644
--- a/paludis/dep_list/exceptions.cc
+++ b/paludis/dep_list/exceptions.cc
@@ -48,4 +48,12 @@ CircularDependencyError::CircularDependencyError(const std::string & msg) throw
{
}
+DowngradeNotAllowedError::DowngradeNotAllowedError(const std::string & to, const std::string & from) throw () :
+ DepListError("Downgrade to '" + to + "' from '" + from + "' forbidden")
+{
+}
+
+DowngradeNotAllowedError::~DowngradeNotAllowedError() throw ()
+{
+}
diff --git a/paludis/dep_list/exceptions.hh b/paludis/dep_list/exceptions.hh
index 4d27163..8bcd1fd 100644
--- a/paludis/dep_list/exceptions.hh
+++ b/paludis/dep_list/exceptions.hh
@@ -110,6 +110,26 @@ namespace paludis
};
/**
+ * Thrown if a downgrade is forced and we're not allowed to downgrade.
+ *
+ * \ingroup grpexceptions
+ * \ingroup grpdepresolver
+ * \nosubgrouping
+ */
+ class DowngradeNotAllowedError : public DepListError
+ {
+ public:
+ ///\name Basic operations
+ ///\{
+
+ DowngradeNotAllowedError(const std::string & to, const std::string & from) throw ();
+
+ virtual ~DowngradeNotAllowedError() throw ();
+
+ ///\}
+ };
+
+ /**
* Thrown if a block is encountered.
*
* \ingroup grpdepresolver
diff --git a/paludis/dep_list/options.hh b/paludis/dep_list/options.hh
index 520ab5a..7abdbbd 100644
--- a/paludis/dep_list/options.hh
+++ b/paludis/dep_list/options.hh
@@ -91,6 +91,19 @@ namespace paludis
};
/**
+ * What to do when we downgrade.
+ *
+ * \ingroup grpdepresolver
+ */
+ enum DepListDowngradeOption
+ {
+ dl_downgrade_as_needed, ///< As needed
+ dl_downgrade_warning, ///< As needed, but warn
+ dl_downgrade_error, ///< Don't
+ last_dl_downgrade
+ };
+
+ /**
* When should we pull in a new slot.
*
* \ingroup grpdepresolver
diff --git a/src/clients/paludis/command_line.cc b/src/clients/paludis/command_line.cc
index bb5fd07..0284a0a 100644
--- a/src/clients/paludis/command_line.cc
+++ b/src/clients/paludis/command_line.cc
@@ -133,6 +133,12 @@ CommandLine::CommandLine() :
("always", "Always")
("as-needed", "As needed"),
"always"),
+ dl_downgrade(&dl_args, "dl-downgrade", '\0', "When to downgrade packages",
+ args::EnumArg::EnumArgOptions
+ ("as-needed", "As needed")
+ ("warning", "As needed, but warn when doing so")
+ ("error", "Downgrades should be treated as errors"),
+ "as-needed"),
dl_deps_default(&dl_args, "dl-deps-default", '\0',
"Override default behaviour for all dependency classes",
diff --git a/src/clients/paludis/command_line.hh b/src/clients/paludis/command_line.hh
index 4363564..cd5e92e 100644
--- a/src/clients/paludis/command_line.hh
+++ b/src/clients/paludis/command_line.hh
@@ -240,6 +240,7 @@ class CommandLine :
paludis::args::EnumArg dl_reinstall_scm;
paludis::args::EnumArg dl_upgrade;
paludis::args::EnumArg dl_new_slots;
+ paludis::args::EnumArg dl_downgrade;
paludis::args::DepsOptionArg dl_deps_default;
diff --git a/src/clients/paludis/install.cc b/src/clients/paludis/install.cc
index 50aeb5c..d6d94f9 100644
--- a/src/clients/paludis/install.cc
+++ b/src/clients/paludis/install.cc
@@ -342,6 +342,18 @@ do_install()
throw args::DoHelp("bad value for --dl-new-slots");
}
+ if (CommandLine::get_instance()->dl_downgrade.specified())
+ {
+ if (CommandLine::get_instance()->dl_downgrade.argument() == "as-needed")
+ options.downgrade = dl_downgrade_as_needed;
+ else if (CommandLine::get_instance()->dl_downgrade.argument() == "warning")
+ options.downgrade = dl_downgrade_warning;
+ else if (CommandLine::get_instance()->dl_downgrade.argument() == "error")
+ options.downgrade = dl_downgrade_error;
+ else
+ throw args::DoHelp("bad value for --dl-downgrade");
+ }
+
if (CommandLine::get_instance()->dl_circular.specified())
{
if (CommandLine::get_instance()->dl_circular.argument() == "discard")