aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-12 14:57:57 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-12 14:57:57 +0000
commit1d52aa43185c513c5aa86283d2c3bd184750677b (patch)
treea539b88b07a7c0cc077c8f7d244c40393608be6c
parent409f32b441d9d852718e638b57bd8cec81a936ab (diff)
downloadpaludis-1d52aa43185c513c5aa86283d2c3bd184750677b.tar.gz
paludis-1d52aa43185c513c5aa86283d2c3bd184750677b.tar.xz
cave fix-cache
-rw-r--r--src/clients/cave/Makefile.am4
-rw-r--r--src/clients/cave/cmd_fix_cache.cc156
-rw-r--r--src/clients/cave/cmd_fix_cache.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
6 files changed, 211 insertions, 2 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 8dea385..4a1e303 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -21,6 +21,7 @@ command_MANS = \
cave-config.1 \
cave-display-resolution.1 \
cave-execute-resolution.1 \
+ cave-fix-cache.1 \
cave-help.1 \
cave-import.1 \
cave-info.1 \
@@ -87,6 +88,7 @@ libcave_a_SOURCES = \
cmd_config.cc cmd_config.hh \
cmd_display_resolution.cc cmd_display_resolution.hh \
cmd_execute_resolution.cc cmd_execute_resolution.hh \
+ cmd_fix_cache.cc cmd_fix_cache.hh \
cmd_help.cc cmd_help.hh \
cmd_import.cc cmd_import.hh \
cmd_info.cc cmd_info.hh \
@@ -129,8 +131,6 @@ libcave_a_SOURCES = \
# cmd_print_repository_metadata.cc \
# cmd_print_set.cc \
# cmd_print_sync_protocol_metadata.cc \
-# cmd_regenerate_installable_cache.cc \
-# cmd_regenerate_installed_cache.cc \
# cmd_report.cc \
# cmd_uninstall.cc \
# cmd_uninstall_unused.cc
diff --git a/src/clients/cave/cmd_fix_cache.cc b/src/clients/cave/cmd_fix_cache.cc
new file mode 100644
index 0000000..46edc09
--- /dev/null
+++ b/src/clients/cave/cmd_fix_cache.cc
@@ -0,0 +1,156 @@
+/* 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_fix_cache.hh"
+#include "formats.hh"
+#include "format_general.hh"
+
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repository.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+
+#include <iostream>
+#include <set>
+#include <algorithm>
+#include <cstdlib>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct FixCacheCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave fix-cache";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Fix on-disk caches.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Fixes on-disk caches. Normally this is handled automatically when needed (e.g. after a sync, "
+ "or when a package is installed), but a forced fix-cache is required after a different package "
+ "manager has been used, or if a repository is modified without a sync.";
+ }
+
+ args::ArgsGroup g_repositories;
+ args::StringSetArg a_repository;
+ args::SwitchArg a_installable;
+ args::SwitchArg a_installed;
+
+ FixCacheCommandLine() :
+ g_repositories(main_options_section(), "Repositories", "Select repositories whose cache is to be "
+ "regenerated. If none of these restrictions are specified, all repositories are selected. "
+ "Otherwise, only repositories matching any of these restrictions are regenerated."),
+ a_repository(&g_repositories, "repository", 'r', "Select the repository with the specified name. May "
+ "be specified multiple times."),
+ a_installable(&g_repositories, "installable", 'i', "Select all installable repositories.", true),
+ a_installed(&g_repositories, "installed", 'I', "Select all installed repositories", true)
+ {
+ }
+ };
+}
+
+int
+FixCacheCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ FixCacheCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_FIX_CACHE_OPTIONS", "CAVE_FIX_CACHE_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (cmdline.begin_parameters() != cmdline.end_parameters())
+ throw args::DoHelp("fix-cache takes no parameters");
+
+ std::set<RepositoryName, RepositoryNameComparator> repository_names;
+
+ bool all(true);
+
+ if (cmdline.a_repository.specified())
+ {
+ all = false;
+ for (args::StringSetArg::ConstIterator p(cmdline.a_repository.begin_args()),
+ p_end(cmdline.a_repository.end_args()) ;
+ p != p_end ; ++p)
+ repository_names.insert(RepositoryName(*p));
+ }
+
+ if (cmdline.a_installable.specified())
+ {
+ all = false;
+ for (IndirectIterator<PackageDatabase::RepositoryConstIterator, const Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories());
+ r != r_end; ++r)
+ if (! r->installed_root_key())
+ repository_names.insert(r->name());
+ }
+
+ if (cmdline.a_installed.specified())
+ {
+ all = false;
+ for (IndirectIterator<PackageDatabase::RepositoryConstIterator, const Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories());
+ r != r_end; ++r)
+ if (r->installed_root_key())
+ repository_names.insert(r->name());
+ }
+
+ if (all)
+ for (IndirectIterator<PackageDatabase::RepositoryConstIterator, const Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories());
+ r != r_end; ++r)
+ repository_names.insert(r->name());
+
+ for (std::set<RepositoryName, RepositoryNameComparator>::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
+ r != r_end; ++r)
+ {
+ cout << format_general_s(f::fix_cache_fixing(), stringify(*r));
+ const std::tr1::shared_ptr<Repository> repo(env->package_database()->fetch_repository(*r));
+ repo->regenerate_cache();
+ }
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+FixCacheCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new FixCacheCommandLine);
+}
diff --git a/src/clients/cave/cmd_fix_cache.hh b/src/clients/cave/cmd_fix_cache.hh
new file mode 100644
index 0000000..6cc22ff
--- /dev/null
+++ b/src/clients/cave/cmd_fix_cache.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_FIX_CACHE_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_FIX_CACHE_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE FixCacheCommand :
+ 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 8b654ff..dd30d52 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -29,6 +29,7 @@
#include "cmd_config.hh"
#include "cmd_display_resolution.hh"
#include "cmd_execute_resolution.hh"
+#include "cmd_fix_cache.hh"
#include "cmd_help.hh"
#include "cmd_import.hh"
#include "cmd_info.hh"
@@ -86,6 +87,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("config", std::tr1::bind(&make_command<ConfigCommand>)));
_imp->handlers.insert(std::make_pair("display-resolution", std::tr1::bind(&make_command<DisplayResolutionCommand>)));
_imp->handlers.insert(std::make_pair("execute-resolution", std::tr1::bind(&make_command<ExecuteResolutionCommand>)));
+ _imp->handlers.insert(std::make_pair("fix-cache", std::tr1::bind(&make_command<FixCacheCommand>)));
_imp->handlers.insert(std::make_pair("help", std::tr1::bind(&make_command<HelpCommand>)));
_imp->handlers.insert(std::make_pair("import", std::tr1::bind(&make_command<ImportCommand>)));
_imp->handlers.insert(std::make_pair("info", std::tr1::bind(&make_command<InfoCommand>)));
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index ae6244d..8e1fa91 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -257,6 +257,12 @@ paludis::cave::f::info_heading()
}
const std::string
+paludis::cave::f::fix_cache_fixing()
+{
+ return "Fixing cache for " + c::blue() + "%s" + c::normal() + "...\\n";
+}
+
+const std::string
paludis::cave::f::colour_formatter_keyword_name_plain()
{
return "%s";
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index 2444ab0..5098f45 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -89,6 +89,8 @@ namespace paludis
const std::string info_id_heading();
const std::string info_heading();
+ const std::string fix_cache_fixing();
+
const std::string colour_formatter_keyword_name_plain();
const std::string colour_formatter_keyword_name_accepted();
const std::string colour_formatter_keyword_name_unaccepted();