aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-09 16:40:02 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-09 16:40:02 +0000
commitff5289f54babbb2add96adda54754d2f9ee2bb08 (patch)
treef480e7210a9af400617c162ff02883098dc0a2a9
parent0645c90066c9d4bd448b2ba8449bc40f55f53c80 (diff)
downloadpaludis-ff5289f54babbb2add96adda54754d2f9ee2bb08.tar.gz
paludis-ff5289f54babbb2add96adda54754d2f9ee2bb08.tar.xz
Add adjutrix downgrade check
-rw-r--r--src/clients/adjutrix/Makefile.am11
-rw-r--r--src/clients/adjutrix/adjutrix.cc22
-rw-r--r--src/clients/adjutrix/command_line.cc9
-rw-r--r--src/clients/adjutrix/command_line.hh4
-rw-r--r--src/clients/adjutrix/downgrade_check.cc237
-rw-r--r--src/clients/adjutrix/downgrade_check.hh28
-rw-r--r--src/clients/adjutrix/downgrade_check.sr11
-rw-r--r--src/clients/adjutrix/find_insecure_packages.cc3
-rw-r--r--src/clients/adjutrix/find_reverse_deps.cc9
9 files changed, 329 insertions, 5 deletions
diff --git a/src/clients/adjutrix/Makefile.am b/src/clients/adjutrix/Makefile.am
index 1380fc6..e641d65 100644
--- a/src/clients/adjutrix/Makefile.am
+++ b/src/clients/adjutrix/Makefile.am
@@ -43,6 +43,7 @@ adjutrix_SOURCES = \
display_profiles_use.hh display_profiles_use.cc \
display_default_system_resolution.hh display_default_system_resolution.cc \
what_needs_keywording.hh what_needs_keywording.cc \
+ downgrade_check.hh downgrade_check.cc \
adjutrix.cc
adjutrix_LDADD = \
@@ -75,6 +76,7 @@ EXTRA_DIST = \
$(TESTS) \
find_stable_candidates-sr.hh find_stable_candidates-sr.cc find_stable_candidates.sr \
find_dropped_keywords-sr.hh find_dropped_keywords-sr.cc find_dropped_keywords.sr \
+ downgrade_check-sr.hh downgrade_check-sr.cc downgrade_check.sr \
find_stable_candidates_TEST_setup.sh find_stable_candidates_TEST_cleanup.sh
CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda
@@ -83,7 +85,8 @@ DISTCLEANFILES = $(man_MANS) $(noinst_DATA) \
MAINTAINERCLEANFILES = Makefile.in
BUILT_SOURCES = \
find_stable_candidates-sr.hh find_stable_candidates-sr.cc \
- find_dropped_keywords-sr.hh find_dropped_keywords-sr.cc
+ find_dropped_keywords-sr.hh find_dropped_keywords-sr.cc \
+ downgrade_check-sr.hh downgrade_check-sr.cc
find_stable_candidates-sr.hh : find_stable_candidates.sr $(top_srcdir)/misc/make_sr.bash
$(top_srcdir)/misc/make_sr.bash --header $(srcdir)/find_stable_candidates.sr > $@
@@ -97,6 +100,12 @@ find_dropped_keywords-sr.hh : find_dropped_keywords.sr $(top_srcdir)/misc/make_s
find_dropped_keywords-sr.cc : find_dropped_keywords.sr $(top_srcdir)/misc/make_sr.bash
$(top_srcdir)/misc/make_sr.bash --source $(srcdir)/find_dropped_keywords.sr > $@
+downgrade_check-sr.hh : downgrade_check.sr $(top_srcdir)/misc/make_sr.bash
+ $(top_srcdir)/misc/make_sr.bash --header $(srcdir)/downgrade_check.sr > $@
+
+downgrade_check-sr.cc : downgrade_check.sr $(top_srcdir)/misc/make_sr.bash
+ $(top_srcdir)/misc/make_sr.bash --source $(srcdir)/downgrade_check.sr > $@
+
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/src/clients/adjutrix/adjutrix.cc b/src/clients/adjutrix/adjutrix.cc
index c755c29..6306345 100644
--- a/src/clients/adjutrix/adjutrix.cc
+++ b/src/clients/adjutrix/adjutrix.cc
@@ -28,6 +28,7 @@
#include "display_profiles_use.hh"
#include "display_default_system_resolution.hh"
#include "what_needs_keywording.hh"
+#include "downgrade_check.hh"
#include <paludis/about.hh>
#include <paludis/util/join.hh>
@@ -137,6 +138,8 @@ main(int argc, char *argv[])
CommandLine::get_instance()->a_reverse_deps.specified() +
CommandLine::get_instance()->a_display_profiles_use.specified() +
CommandLine::get_instance()->a_display_default_system_resolution.specified() +
+ CommandLine::get_instance()->a_build_downgrade_check_list.specified() +
+ CommandLine::get_instance()->a_downgrade_check.specified() +
CommandLine::get_instance()->a_what_needs_keywording.specified()
))
throw DoHelp("you should specify exactly one action");
@@ -242,6 +245,25 @@ main(int argc, char *argv[])
return do_what_needs_keywording(env);
}
+ if (CommandLine::get_instance()->a_build_downgrade_check_list.specified())
+ {
+ if (1 != std::distance(CommandLine::get_instance()->begin_parameters(),
+ CommandLine::get_instance()->end_parameters()))
+ throw DoHelp("build-downgrade-check-list takes exactly one parameter (the output directory)");
+
+ return do_build_downgrade_check_list(env);
+ }
+
+ if (CommandLine::get_instance()->a_downgrade_check.specified())
+ {
+ if (2 != std::distance(CommandLine::get_instance()->begin_parameters(),
+ CommandLine::get_instance()->end_parameters()))
+ throw DoHelp("build-downgrade-check-list takes exactly two parameters "
+ "(the before and after directories)");
+
+ return do_downgrade_check(env);
+ }
+
throw InternalError(__PRETTY_FUNCTION__, "no action?");
}
catch (const DoVersion &)
diff --git a/src/clients/adjutrix/command_line.cc b/src/clients/adjutrix/command_line.cc
index e7c2fac..66340a7 100644
--- a/src/clients/adjutrix/command_line.cc
+++ b/src/clients/adjutrix/command_line.cc
@@ -52,6 +52,15 @@ CommandLine::CommandLine() :
"display-default-system-resolution", 'S', "Display package names and versions that are included in "
"the default resolution of the system set"),
+ downgrade_check_args(this, "Downgrade Check Actions",
+ "Selects which downgrade check related action to perform. Exactly one action should "
+ "be specified."),
+
+ a_build_downgrade_check_list(&downgrade_check_args,
+ "build-downgrade-check-list", '\0', "Build the downgrade check lists"),
+ a_downgrade_check(&downgrade_check_args,
+ "downgrade-check", '\0', "Perform the dowgrade check"),
+
general_action_args(this, "General Actions",
"Selects which basic general action to perform. Exactly one action should "
"be specified."),
diff --git a/src/clients/adjutrix/command_line.hh b/src/clients/adjutrix/command_line.hh
index d7ca28c..cec43ad 100644
--- a/src/clients/adjutrix/command_line.hh
+++ b/src/clients/adjutrix/command_line.hh
@@ -72,6 +72,10 @@ class CommandLine :
paludis::args::SwitchArg a_display_profiles_use;
paludis::args::SwitchArg a_display_default_system_resolution;
+ paludis::args::ArgsGroup downgrade_check_args;
+ paludis::args::SwitchArg a_build_downgrade_check_list;
+ paludis::args::SwitchArg a_downgrade_check;
+
paludis::args::ArgsGroup general_action_args;
paludis::args::SwitchArg a_version;
paludis::args::SwitchArg a_help;
diff --git a/src/clients/adjutrix/downgrade_check.cc b/src/clients/adjutrix/downgrade_check.cc
new file mode 100644
index 0000000..8e3254f
--- /dev/null
+++ b/src/clients/adjutrix/downgrade_check.cc
@@ -0,0 +1,237 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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 "downgrade_check.hh"
+#include "command_line.hh"
+#include <paludis/query.hh>
+#include <paludis/repositories/portage/portage_repository.hh>
+#include <paludis/util/sr.hh>
+#include <paludis/util/compare.hh>
+#include <paludis/util/tokeniser.hh>
+#include <fstream>
+#include <iostream>
+#include <map>
+
+using namespace paludis;
+
+namespace paludis
+{
+#include <src/clients/adjutrix/downgrade_check-sr.hh>
+}
+
+#include <src/clients/adjutrix/downgrade_check-sr.cc>
+
+namespace
+{
+ int
+ build_one_list(NoConfigEnvironment & env, std::ostream & f)
+ {
+ std::tr1::shared_ptr<const PackageDatabaseEntryCollection> matches(
+ env.package_database()->query(query::NotMasked(), qo_group_by_slot));
+
+ QualifiedPackageName old_package("dummy/dummy");
+ SlotName old_slot("dummy");
+ VersionSpec best_version("0");
+ for (PackageDatabaseEntryCollection::Iterator m(matches->begin()), m_end(matches->end()) ;
+ m != m_end ; ++m)
+ {
+ SlotName slot(env.package_database()->fetch_repository(m->repository)->version_metadata(
+ m->name, m->version)->slot);
+
+ if (m->name != old_package || slot != old_slot)
+ {
+ f << old_package << " " << old_slot << " " << best_version << std::endl;
+
+ old_package = m->name;
+ old_slot = slot;
+ best_version = m->version;
+ }
+ }
+
+ f << old_package << " " << old_slot << " " << best_version << std::endl;
+
+ return 0;
+ }
+
+ std::string
+ make_filename(const PortageRepository::ProfilesIterator & p, bool unstable)
+ {
+ std::string result;
+ FSEntry f(p->path);
+ while (f.basename() != "profiles" && f != FSEntry("/"))
+ {
+ result = f.basename() + (result.empty() ? "" : "_" + result);
+ f = f.dirname();
+ }
+
+ result.append(unstable ? ".unstable.txt" : ".stable.txt");
+
+ return result;
+ }
+
+ std::string
+ make_desc(const PortageRepository::ProfilesIterator & p, bool unstable)
+ {
+ std::string result;
+ FSEntry f(p->path);
+ while (f.basename() != "profiles" && f != FSEntry("/"))
+ {
+ result = f.basename() + (result.empty() ? "" : "/" + result);
+ f = f.dirname();
+ }
+
+ result.append(unstable ? " (unstable)" : " (stable)");
+
+ return result;
+ }
+
+ void
+ load_list(std::map<QPNS, VersionSpec> & map, std::istream & f)
+ {
+ std::string s;
+ while (std::getline(f, s))
+ {
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(s, std::back_inserter(tokens));
+ if (tokens.size() != 3)
+ throw ConfigurationError("Bad line '" + s + "'");
+
+ map.insert(std::make_pair(QPNS(QualifiedPackageName(tokens.at(0)),
+ SlotName(tokens.at(1))), VersionSpec(tokens.at(2))));
+ }
+ }
+
+ int
+ check_one_list(NoConfigEnvironment & env, std::istream & f1,
+ std::istream & f2, std::multimap<QPNS, std::string> & results,
+ const std::string & desc)
+ {
+ int exit_status(0);
+
+ std::map<QPNS, VersionSpec> before, after;
+
+ load_list(before, f1);
+ load_list(after, f2);
+
+ for (std::map<QPNS, VersionSpec>::const_iterator b(before.begin()), b_end(before.end()) ;
+ b != b_end ; ++b)
+ {
+ std::map<QPNS, VersionSpec>::const_iterator a(after.find(b->first));
+ if (after.end() == a)
+ {
+ if (! env.package_database()->query(query::Matches(PackageDepAtom(
+ stringify(b->first.name) + ":" + stringify(b->first.slot))),
+ qo_whatever)->empty())
+ {
+ results.insert(std::make_pair(b->first, stringify(b->second) + " -> nothing on " + desc));
+ exit_status |= 2;
+ }
+ }
+ else if (b->second > a->second)
+ {
+ results.insert(std::make_pair(b->first, stringify(b->second) + " -> " +
+ stringify(a->second) + " on " + desc));
+ exit_status |= 4;
+ }
+ }
+
+ return exit_status;
+ }
+}
+
+int
+do_build_downgrade_check_list(NoConfigEnvironment & env)
+{
+ int exit_status(0);
+
+ FSEntry output_dir(*CommandLine::get_instance()->begin_parameters());
+ if (! output_dir.mkdir())
+ throw ConfigurationError("Output directory already exists");
+
+ for (PortageRepository::ProfilesIterator p(env.portage_repository()->begin_profiles()),
+ p_end(env.portage_repository()->end_profiles()) ; p != p_end ; ++p)
+ {
+ for (int i = 0 ; i < 2 ; ++i)
+ {
+ env.set_accept_unstable(i);
+ env.portage_repository()->set_profile(p);
+ std::string n(make_filename(p, i));
+ std::cerr << "Generating " << n << "..." << std::endl;
+ std::ofstream f(stringify(output_dir / n).c_str());
+ exit_status |= build_one_list(env, f);
+ }
+ }
+
+ return exit_status;
+}
+
+int
+do_downgrade_check(NoConfigEnvironment & env)
+{
+ int exit_status(0);
+
+ FSEntry before_dir(*CommandLine::get_instance()->begin_parameters());
+ if (! before_dir.is_directory())
+ throw ConfigurationError("First input directory is not a directory");
+
+ FSEntry after_dir(*next(CommandLine::get_instance()->begin_parameters()));
+ if (! after_dir.is_directory())
+ throw ConfigurationError("Second input directory is not a directory");
+
+ std::multimap<QPNS, std::string> results;
+
+ for (PortageRepository::ProfilesIterator p(env.portage_repository()->begin_profiles()),
+ p_end(env.portage_repository()->end_profiles()) ; p != p_end ; ++p)
+ {
+ for (int i = 0 ; i < 2 ; ++i)
+ {
+ env.set_accept_unstable(i);
+ env.portage_repository()->set_profile(p);
+ std::string n(make_filename(p, i)), desc(make_desc(p, i));
+
+ if ((before_dir / n).exists() && (after_dir / n).exists())
+ {
+ std::cerr << "Checking " << n << "..." << std::endl;
+
+ std::ifstream f1(stringify(before_dir / n).c_str());
+ std::ifstream f2(stringify(after_dir / n).c_str());
+
+ exit_status |= check_one_list(env, f1, f2, results, desc);
+ }
+ else
+ std::cerr << "Skipping " << n << "..." << std::endl;
+ }
+ }
+
+ QPNS old_qpns(QualifiedPackageName("dummy/dummmy"), SlotName("dummy"));
+ for (std::multimap<QPNS, std::string>::const_iterator r(results.begin()), r_end(results.end()) ;
+ r != r_end ; ++r)
+ {
+ if (old_qpns != r->first)
+ {
+ std::cout << r->first.name << " :" << r->first.slot << std::endl;
+ old_qpns = r->first;
+ }
+
+ std::cout << " " << r->second << std::endl;
+ }
+
+ return exit_status;
+}
+
diff --git a/src/clients/adjutrix/downgrade_check.hh b/src/clients/adjutrix/downgrade_check.hh
new file mode 100644
index 0000000..0ed5d46
--- /dev/null
+++ b/src/clients/adjutrix/downgrade_check.hh
@@ -0,0 +1,28 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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_SRC_CLIENTS_ADJUTRIX_DOWNGRADE_CHECK_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_ADJUTRIX_DOWNGRADE_CHECK_HH 1
+
+#include <paludis/environment/no_config/no_config_environment.hh>
+
+int do_build_downgrade_check_list(paludis::NoConfigEnvironment & env);
+int do_downgrade_check(paludis::NoConfigEnvironment & env);
+
+#endif
diff --git a/src/clients/adjutrix/downgrade_check.sr b/src/clients/adjutrix/downgrade_check.sr
new file mode 100644
index 0000000..b93145a
--- /dev/null
+++ b/src/clients/adjutrix/downgrade_check.sr
@@ -0,0 +1,11 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+make_class_QPNS()
+{
+ key name QualifiedPackageName;
+ key slot SlotName;
+
+ comparison_operators all all
+}
+
diff --git a/src/clients/adjutrix/find_insecure_packages.cc b/src/clients/adjutrix/find_insecure_packages.cc
index 2cf1dd4..add7acd 100644
--- a/src/clients/adjutrix/find_insecure_packages.cc
+++ b/src/clients/adjutrix/find_insecure_packages.cc
@@ -22,6 +22,7 @@
#include <paludis/util/tokeniser.hh>
#include <paludis/util/compare.hh>
+#include <paludis/query.hh>
#include <set>
#include <map>
@@ -83,7 +84,7 @@ namespace
void visit(const PackageDepAtom * const a)
{
std::tr1::shared_ptr<const PackageDatabaseEntryCollection> insecure(
- _env.package_database()->query(*a, is_any, qo_order_by_version));
+ _env.package_database()->query(query::Matches(*a), qo_order_by_version));
for (PackageDatabaseEntryCollection::Iterator i(insecure->begin()),
i_end(insecure->end()) ; i != i_end ; ++i)
if (a->tag())
diff --git a/src/clients/adjutrix/find_reverse_deps.cc b/src/clients/adjutrix/find_reverse_deps.cc
index 5ef4ea3..a280059 100644
--- a/src/clients/adjutrix/find_reverse_deps.cc
+++ b/src/clients/adjutrix/find_reverse_deps.cc
@@ -25,6 +25,7 @@
#include <paludis/util/collection_concrete.hh>
#include <paludis/util/save.hh>
#include <paludis/util/log.hh>
+#include <paludis/query.hh>
#include <set>
#include <map>
@@ -117,7 +118,8 @@ namespace
void
ReverseDepChecker::visit(const PackageDepAtom * const a)
{
- std::tr1::shared_ptr<const PackageDatabaseEntryCollection> dep_entries(_db->query(*a, is_any, qo_order_by_version));
+ std::tr1::shared_ptr<const PackageDatabaseEntryCollection> dep_entries(_db->query(
+ query::Matches(*a), qo_order_by_version));
std::tr1::shared_ptr<PackageDatabaseEntryCollection> matches(new PackageDatabaseEntryCollection::Concrete);
bool header_written = false;
@@ -177,7 +179,7 @@ namespace
Context context("When checking package '" + stringify(p) + "':");
std::tr1::shared_ptr<PackageDatabaseEntryCollection> p_entries(env.package_database()->query(
- PackageDepAtom(p), is_any, qo_order_by_version));
+ query::Package(p), qo_order_by_version));
bool found_matches(false);
@@ -241,7 +243,8 @@ int do_find_reverse_deps(NoConfigEnvironment & env)
return 4;
}
- std::tr1::shared_ptr<PackageDatabaseEntryCollection> entries(env.package_database()->query(*atom, is_any, qo_order_by_version));
+ std::tr1::shared_ptr<PackageDatabaseEntryCollection> entries(env.package_database()->query(
+ query::Matches(*atom), qo_order_by_version));
int ret(0);
if (entries->empty())