aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-03 20:03:27 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-03 20:03:27 +0100
commita8081daa93c1d5b50e3489f99758a437b7b981ff (patch)
treeba89c99bd36c99469aee41b0cfee500328fc20ec
parentab43c09cb67218faf3868a253aefa0f52dff241d (diff)
downloadpaludis-a8081daa93c1d5b50e3489f99758a437b7b981ff.tar.gz
paludis-a8081daa93c1d5b50e3489f99758a437b7b981ff.tar.xz
reinstall scm
-rw-r--r--paludis/resolver/qpn_s.cc10
-rw-r--r--paludis/resolver/qpn_s.hh7
-rw-r--r--paludis/resolver/resolver.cc19
-rw-r--r--paludis/resolver/resolver.hh3
-rw-r--r--src/clients/cave/cmd_resolve.cc120
5 files changed, 137 insertions, 22 deletions
diff --git a/paludis/resolver/qpn_s.cc b/paludis/resolver/qpn_s.cc
index f538228..ed3698d 100644
--- a/paludis/resolver/qpn_s.cc
+++ b/paludis/resolver/qpn_s.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/resolver/qpn_s.hh>
+#include <paludis/filter.hh>
#include <sstream>
using namespace paludis;
@@ -62,3 +63,12 @@ paludis::resolver::operator<< (std::ostream & s, const QPN_S & q)
return s;
}
+Filter
+QPN_S::make_slot_filter() const
+{
+ if (slot_name_or_null())
+ return filter::Slot(*slot_name_or_null());
+ else
+ return filter::NoSlot();
+}
+
diff --git a/paludis/resolver/qpn_s.hh b/paludis/resolver/qpn_s.hh
index 7dea100..44c82d6 100644
--- a/paludis/resolver/qpn_s.hh
+++ b/paludis/resolver/qpn_s.hh
@@ -22,7 +22,9 @@
#include <paludis/resolver/qpn_s-fwd.hh>
#include <paludis/util/named_value.hh>
+#include <paludis/util/attributes.hh>
#include <paludis/name.hh>
+#include <paludis/filter-fwd.hh>
#include <tr1/memory>
namespace paludis
@@ -35,10 +37,13 @@ namespace paludis
namespace resolver
{
- struct QPN_S
+ struct PALUDIS_VISIBLE QPN_S
{
NamedValue<n::package, QualifiedPackageName> package;
NamedValue<n::slot_name_or_null, std::tr1::shared_ptr<const SlotName> > slot_name_or_null;
+
+ Filter make_slot_filter() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
};
}
diff --git a/paludis/resolver/resolver.cc b/paludis/resolver/resolver.cc
index 324aa2e..be37016 100644
--- a/paludis/resolver/resolver.cc
+++ b/paludis/resolver/resolver.cc
@@ -541,7 +541,7 @@ Resolver::_best_installed_id_for(const QPN_S & qpn_s, const std::tr1::shared_ptr
{
const std::tr1::shared_ptr<const PackageIDSequence> ids((*_imp->env)[selection::AllVersionsSorted(
generator::Package(qpn_s.package()) |
- _make_slot_filter(qpn_s) |
+ qpn_s.make_slot_filter() |
filter::SupportsAction<InstalledAction>())]);
return _best_id_from(ids, qpn_s, resolution);
@@ -552,7 +552,7 @@ Resolver::_best_installable_id_for(const QPN_S & qpn_s, const std::tr1::shared_p
{
const std::tr1::shared_ptr<const PackageIDSequence> ids((*_imp->env)[selection::AllVersionsSorted(
generator::Package(qpn_s.package()) |
- _make_slot_filter(qpn_s) |
+ qpn_s.make_slot_filter() |
filter::SupportsAction<InstallAction>() |
filter::NotMasked())]);
@@ -588,15 +588,6 @@ Resolver::_best_id_from(
return make_null_shared_ptr();
}
-Filter
-Resolver::_make_slot_filter(const QPN_S & qpn_s) const
-{
- if (qpn_s.slot_name_or_null())
- return filter::Slot(*qpn_s.slot_name_or_null());
- else
- return filter::NoSlot();
-}
-
void
Resolver::_add_dependencies(const QPN_S & our_qpn_s, const std::tr1::shared_ptr<Resolution> & our_resolution)
{
@@ -823,13 +814,13 @@ Resolver::_decision_from_package_id(const QPN_S & qpn_s, const std::tr1::shared_
if (is_installed)
comparison_ids = ((*_imp->env)[selection::BestVersionOnly(
generator::Package(qpn_s.package()) |
- _make_slot_filter(qpn_s) |
+ qpn_s.make_slot_filter() |
filter::SupportsAction<InstallAction>() |
filter::NotMasked())]);
else
comparison_ids = ((*_imp->env)[selection::BestVersionOnly(
generator::Package(qpn_s.package()) |
- _make_slot_filter(qpn_s) |
+ qpn_s.make_slot_filter() |
filter::SupportsAction<InstalledAction>())]);
if (comparison_ids->empty())
@@ -862,7 +853,7 @@ Resolver::_unable_to_decide(
{
const std::tr1::shared_ptr<const PackageIDSequence> ids((*_imp->env)[selection::AllVersionsSorted(
generator::Package(qpn_s.package()) |
- _make_slot_filter(qpn_s) |
+ qpn_s.make_slot_filter() |
filter::SupportsAction<InstallAction>() |
filter::NotMasked())]);
diff --git a/paludis/resolver/resolver.hh b/paludis/resolver/resolver.hh
index 566fe6c..0a43654 100644
--- a/paludis/resolver/resolver.hh
+++ b/paludis/resolver/resolver.hh
@@ -36,7 +36,6 @@
#include <paludis/package_id-fwd.hh>
#include <paludis/dep_spec-fwd.hh>
#include <paludis/name.hh>
-#include <paludis/filter-fwd.hh>
#include <paludis/environment-fwd.hh>
#include <paludis/repository-fwd.hh>
#include <tr1/memory>
@@ -116,8 +115,6 @@ namespace paludis
void _add_dependencies(const QPN_S & our_qpn_s, const std::tr1::shared_ptr<Resolution> & our_resolution);
- Filter _make_slot_filter(const QPN_S &) const;
-
bool _care_about_dependency_spec(const QPN_S &, const std::tr1::shared_ptr<const Resolution> &,
const SanitisedDependency &) const;
diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc
index 8f7da6f..b38835e 100644
--- a/src/clients/cave/cmd_resolve.cc
+++ b/src/clients/cave/cmd_resolve.cc
@@ -37,6 +37,13 @@
#include <paludis/resolver/constraint.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/notifier_callback.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/selection.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/version_spec.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/environment.hh>
#include <iostream>
#include <cstdlib>
@@ -539,13 +546,116 @@ namespace
return reason->accept_returning<UseInstalled>(v);
}
+ int reinstall_scm_days(const ResolveCommandLine & cmdline)
+ {
+ if (cmdline.a_reinstall_scm.argument() == "always")
+ return 0;
+ else if (cmdline.a_reinstall_scm.argument() == "daily")
+ return 1;
+ else if (cmdline.a_reinstall_scm.argument() == "weekly")
+ return 7;
+ else if (cmdline.a_reinstall_scm.argument() == "never")
+ return -1;
+ else
+ throw args::DoHelp("Don't understand argument '" + cmdline.a_reinstall_scm.argument() + "' to '--"
+ + cmdline.a_reinstall_scm.long_name() + "'");
+ }
+
+ bool is_scm_name(const QualifiedPackageName & n)
+ {
+ std::string pkg(stringify(n.package()));
+ switch (pkg.length())
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ return false;
+
+ default:
+ if (0 == pkg.compare(pkg.length() - 6, 6, "-darcs"))
+ return true;
+
+ case 5:
+ if (0 == pkg.compare(pkg.length() - 5, 5, "-live"))
+ return true;
+
+ case 4:
+ if (0 == pkg.compare(pkg.length() - 4, 4, "-cvs"))
+ return true;
+ if (0 == pkg.compare(pkg.length() - 4, 4, "-svn"))
+ return true;
+ return false;
+ }
+ }
+
+ bool is_scm_older_than(const std::tr1::shared_ptr<const PackageID> & id, const int n)
+ {
+ if (id->version().is_scm() || is_scm_name(id->name()))
+ {
+ static time_t current_time(time(0)); /* static to avoid weirdness */
+ time_t installed_time(current_time);
+ if (id->installed_time_key())
+ installed_time = id->installed_time_key()->value();
+
+ return (current_time - installed_time) > (24 * 60 * 60 * n);
+ }
+ else
+ return false;
+ }
+
+ bool installed_is_scm_older_than(const Environment * const env, const QPN_S & q, const int n)
+ {
+ Context context("When working out whether '" + stringify(q) + "' has installed SCM packages:");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
+ generator::Package(q.package()) |
+ q.make_slot_filter() |
+ filter::SupportsAction<InstalledAction>())]);
+
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ {
+ if (is_scm_older_than(*i, n))
+ return true;
+ }
+
+ return false;
+ }
+
typedef std::map<QPN_S, std::tr1::shared_ptr<Constraints> > InitialConstraints;
- const std::tr1::shared_ptr<Constraints> initial_constraints_for_fn(const InitialConstraints & initial_constraints, const QPN_S & qpn_s)
+ const std::tr1::shared_ptr<Constraints> make_initial_constraints_for(
+ const Environment * const env,
+ const ResolveCommandLine & cmdline,
+ const QPN_S & qpn_s)
+ {
+ const std::tr1::shared_ptr<Constraints> result(new Constraints);
+
+ int n(reinstall_scm_days(cmdline));
+ if ((-1 != n) && installed_is_scm_older_than(env, qpn_s, n))
+ {
+ result->add(make_shared_ptr(new Constraint(make_named_values<Constraint>(
+ value_for<n::desire_strength>(ds_target),
+ value_for<n::reason>(make_shared_ptr(new PresetReason)),
+ value_for<n::spec>(make_package_dep_spec(PartiallyMadePackageDepSpecOptions()).package(qpn_s.package())),
+ value_for<n::to_destination_slash>(false),
+ value_for<n::use_installed>(ui_only_if_transient)
+ ))));
+ }
+
+ return result;
+ }
+
+ const std::tr1::shared_ptr<Constraints> initial_constraints_for_fn(
+ const Environment * const env,
+ const ResolveCommandLine & cmdline,
+ const InitialConstraints & initial_constraints,
+ const QPN_S & qpn_s)
{
InitialConstraints::const_iterator i(initial_constraints.find(qpn_s));
if (i == initial_constraints.end())
- return make_shared_ptr(new Constraints);
+ return make_initial_constraints_for(env, cmdline, qpn_s);
else
return i->second;
}
@@ -579,7 +689,7 @@ ResolveCommand::run(
ResolverFunctions resolver_functions(make_named_values<ResolverFunctions>(
value_for<n::get_initial_constraints_for_fn>(std::tr1::bind(&initial_constraints_for_fn,
- std::tr1::cref(initial_constraints), std::tr1::placeholders::_1)),
+ env.get(), std::tr1::cref(cmdline), std::tr1::cref(initial_constraints), std::tr1::placeholders::_1)),
value_for<n::get_use_installed_fn>(std::tr1::bind(&use_installed_fn,
std::tr1::cref(cmdline), std::tr1::placeholders::_1, std::tr1::placeholders::_2, std::tr1::placeholders::_3))
));
@@ -602,7 +712,9 @@ ResolveCommand::run(
std::cout << "Restarting: for '" << e.qpn_s() << "' we had chosen '" << *e.previous_decision()
<< "' but new constraint '" << *e.problematic_constraint() << "' means we now want '"
<< *e.new_decision() << "' instead" << std::endl;
- initial_constraints.insert(std::make_pair(e.qpn_s(), make_shared_ptr(new Constraints))).first->second->add(e.suggested_preset());
+ initial_constraints.insert(std::make_pair(e.qpn_s(), make_initial_constraints_for(
+ env.get(), cmdline, e.qpn_s()))).first->second->add(
+ e.suggested_preset());
resolver = make_shared_ptr(new Resolver(env.get(), resolver_functions));
}
}