aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-21 13:21:08 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-21 13:21:08 +0100
commit7831d5e9fd75301156f72f7da4c8360ae29ed460 (patch)
tree2243b43c681caa89bb9b69371131b95e26de60d5
parent34197bc815fcf05cf7243ddf5a829be65f0117d5 (diff)
downloadpaludis-7831d5e9fd75301156f72f7da4c8360ae29ed460.tar.gz
paludis-7831d5e9fd75301156f72f7da4c8360ae29ed460.tar.xz
cave verify
-rw-r--r--.gitignore1
-rw-r--r--doc/clients/Makefile.am3
-rw-r--r--src/clients/cave/Makefile.am4
-rw-r--r--src/clients/cave/cmd_verify.cc221
-rw-r--r--src/clients/cave/cmd_verify.hh43
-rw-r--r--src/clients/cave/command_factory.cc2
-rw-r--r--src/clients/cave/formats.cc6
-rw-r--r--src/clients/cave/formats.hh2
8 files changed, 280 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index b5b0891..3dd6214 100644
--- a/.gitignore
+++ b/.gitignore
@@ -120,6 +120,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-sync.html
/doc/clients/cave-uninstall.html
/doc/clients/cave-update-world.html
+/doc/clients/cave-verify.html
/doc/clients/contrarius.html
/doc/clients/footer.html.part
/doc/clients/header.html.part
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 7f88d31..2a1d4cf 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -64,7 +64,8 @@ CAVE_COMMANDS_HTML = \
cave-show.html \
cave-sync.html \
cave-uninstall.html \
- cave-update-world.html
+ cave-update-world.html \
+ cave-verify.html
if HAVE_HTMLTIDY
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index e5431b1..ad45fb0 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -57,7 +57,8 @@ command_MANS = \
cave-show.1 \
cave-sync.1 \
cave-uninstall.1 \
- cave-update-world.1
+ cave-update-world.1 \
+ cave-verify.1
man_MANS = \
cave.1 \
@@ -144,6 +145,7 @@ libcave_a_SOURCES = \
cmd_sync.cc cmd_sync.hh \
cmd_uninstall.cc cmd_uninstall.hh \
cmd_update_world.cc cmd_update_world.hh \
+ cmd_verify.cc cmd_verify.hh \
exceptions.cc exceptions.hh \
executables_common.cc executables_common.hh \
format_general.cc format_general.hh \
diff --git a/src/clients/cave/cmd_verify.cc b/src/clients/cave/cmd_verify.cc
new file mode 100644
index 0000000..1ea19ea
--- /dev/null
+++ b/src/clients/cave/cmd_verify.cc
@@ -0,0 +1,221 @@
+/* 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 "cmd_verify.hh"
+#include "exceptions.hh"
+#include "format_general.hh"
+#include "formats.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/make_named_values.hh>
+#include <paludis/util/accept_visitor.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/safe_ifstream.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/md5.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repository.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/selection.hh>
+#include <paludis/package_id.hh>
+#include <paludis/action.hh>
+#include <paludis/hook.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/output_manager_from_environment.hh>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+#include <set>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct VerifyCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave verify";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Verify that an installed package's files haven't changed.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Verify than an installed package's files haven't changed. Note that there are "
+ "legitimate reasons for some files (such as configuration files) to have been "
+ "changed after a merge, and that some packages may install files that are not "
+ "directly tracked by the package manager.";
+ }
+
+ VerifyCommandLine()
+ {
+ add_usage_line("spec");
+ }
+ };
+
+ struct Verifier
+ {
+ int exit_status;
+
+ Verifier() :
+ exit_status(0)
+ {
+ }
+
+ void message(const FSEntry & path, const std::string & text)
+ {
+ exit_status |= 1;
+ cout << format_general_sr(f::verify_error(), text, stringify(path));
+ }
+
+ bool check_mtime(const ContentsEntry & e, const FSEntry & f)
+ {
+ ContentsEntry::MetadataConstIterator k(e.find_metadata("mtime"));
+ if (e.end_metadata() != k)
+ {
+ const MetadataTimeKey * kk(simple_visitor_cast<const MetadataTimeKey>(**k));
+ if (kk && (kk->value().seconds() != f.mtim().seconds()))
+ {
+ message(f, "Modification time changed");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ bool check_md5(const ContentsEntry & e, const FSEntry & f)
+ {
+ ContentsEntry::MetadataConstIterator k(e.find_metadata("md5"));
+ if (e.end_metadata() != k)
+ {
+ const MetadataValueKey<std::string> * kk(simple_visitor_cast<const MetadataValueKey<std::string> >(**k));
+ if (kk)
+ {
+ SafeIFStream s(f);
+ MD5 md5(s);
+ if (kk->value() != md5.hexsum())
+ {
+ message(f, "Contents (md5) changed");
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ void visit(const ContentsFileEntry & e)
+ {
+ FSEntry f(e.location_key()->value());
+ if (! f.exists())
+ message(f, "Does not exist");
+ else if (! f.is_regular_file())
+ message(f, "Not a regular file");
+ else
+ check_mtime(e, f) && check_md5(e, f);
+ }
+
+ void visit(const ContentsSymEntry & e)
+ {
+ FSEntry f(e.location_key()->value());
+ if (! f.exists())
+ message(f, "Does not exist");
+ else if (! f.is_symbolic_link())
+ message(f, "Not a symbolic link");
+ else
+ check_mtime(e, f);
+ }
+
+ void visit(const ContentsDirEntry & e)
+ {
+ FSEntry f(e.location_key()->value());
+ if (! f.exists())
+ message(f, "Does not exist");
+ else if (! f.is_directory())
+ message(f, "Not a directory");
+ }
+
+ void visit(const ContentsOtherEntry &)
+ {
+ }
+ };
+}
+
+int
+VerifyCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ VerifyCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_VERIFY_OPTIONS", "CAVE_VERIFY_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
+ throw args::DoHelp("verify takes exactly one parameter");
+
+ PackageDepSpec spec(parse_user_package_dep_spec(*cmdline.begin_parameters(), env.get(),
+ UserPackageDepSpecOptions(), filter::InstalledAtRoot(env->root())));
+
+ std::tr1::shared_ptr<const PackageIDSequence> entries(
+ (*env)[selection::AllVersionsSorted(generator::Matches(spec, MatchPackageOptions()) | filter::InstalledAtRoot(env->root()))]);
+
+ if (entries->empty())
+ throw NothingMatching(spec);
+
+ const std::tr1::shared_ptr<const PackageID> id(*entries->last());
+ if (! id->contents_key())
+ throw BadIDForCommand(spec, id, "does not support listing contents");
+
+ Verifier v;
+ std::for_each(indirect_iterator(id->contents_key()->value()->begin()),
+ indirect_iterator(id->contents_key()->value()->end()),
+ accept_visitor(v));
+
+ return v.exit_status;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+VerifyCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new VerifyCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_verify.hh b/src/clients/cave/cmd_verify.hh
new file mode 100644
index 0000000..bc027d4
--- /dev/null
+++ b/src/clients/cave/cmd_verify.hh
@@ -0,0 +1,43 @@
+/* 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_SRC_CLIENTS_CAVE_CMD_VERIFY_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_VERIFY_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE VerifyCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::tr1::shared_ptr<Environment> &,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ std::tr1::shared_ptr<args::ArgsHandler> make_doc_cmdline();
+ };
+ }
+}
+
+#endif
diff --git a/src/clients/cave/command_factory.cc b/src/clients/cave/command_factory.cc
index 06f0401..8a9772e 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -73,6 +73,7 @@
#include "cmd_sync.hh"
#include "cmd_uninstall.hh"
#include "cmd_update_world.hh"
+#include "cmd_verify.hh"
using namespace paludis;
using namespace cave;
@@ -176,6 +177,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("sync", std::tr1::bind(&make_command<SyncCommand>)));
_imp->handlers.insert(std::make_pair("uninstall", std::tr1::bind(&make_command<UninstallCommand>)));
_imp->handlers.insert(std::make_pair("update-world", std::tr1::bind(&make_command<UpdateWorldCommand>)));
+ _imp->handlers.insert(std::make_pair("verify", std::tr1::bind(&make_command<VerifyCommand>)));
}
CommandFactory::~CommandFactory()
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index dd1ce97..5a3cd89 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -675,3 +675,9 @@ paludis::cave::f::executables_file()
return c::bold_blue_or_pink() + "%s" + c::normal() + "\\n";
}
+const std::string
+paludis::cave::f::verify_error()
+{
+ return c::bold_red() + "%s:" + c::normal() + "%{column 30}%r\\n";
+}
+
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index 178b160..1926296 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -169,6 +169,8 @@ namespace paludis
const std::string owner_id();
const std::string executables_file();
+
+ const std::string verify_error();
}
}
}