aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-10-04 20:59:55 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-10-04 20:59:55 +0100
commit3cc05f7f1d8f1fe5f05d7ff3eb2c8430b0165c47 (patch)
tree7838905c1a18b4bed53b916813d8ac11f51cde78
parent343898402c4d4ac9c7d5230d8ef05673782777c9 (diff)
downloadpaludis-3cc05f7f1d8f1fe5f05d7ff3eb2c8430b0165c47.tar.gz
paludis-3cc05f7f1d8f1fe5f05d7ff3eb2c8430b0165c47.tar.xz
cave size, print-id-size
Fixes: ticket:1007
-rw-r--r--.gitignore2
-rw-r--r--doc/clients/Makefile.am2
-rw-r--r--doc/clients/cave-print-size.html172
-rw-r--r--src/clients/cave/Makefile.am7
-rw-r--r--src/clients/cave/cmd_print_id_size.cc93
-rw-r--r--src/clients/cave/cmd_print_id_size.hh43
-rw-r--r--src/clients/cave/cmd_size.cc93
-rw-r--r--src/clients/cave/cmd_size.hh43
-rw-r--r--src/clients/cave/command_factory.cc4
-rw-r--r--src/clients/cave/size_common.cc123
-rw-r--r--src/clients/cave/size_common.hh43
11 files changed, 624 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 0606842..b60201d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -107,6 +107,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-print-id-executables.html
/doc/clients/cave-print-id-masks.html
/doc/clients/cave-print-id-metadata.html
+/doc/clients/cave-print-id-size.html
/doc/clients/cave-print-ids.html
/doc/clients/cave-print-owners.html
/doc/clients/cave-print-packages.html
@@ -123,6 +124,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-resume.html
/doc/clients/cave-search.html
/doc/clients/cave-show.html
+/doc/clients/cave-size.html
/doc/clients/cave-sync.html
/doc/clients/cave-uninstall.html
/doc/clients/cave-update-world.html
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 4b1d7ee..a961bb2 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -52,6 +52,7 @@ CAVE_COMMANDS_HTML = \
cave-print-id-executables.html \
cave-print-id-masks.html \
cave-print-id-metadata.html \
+ cave-print-id-size.html \
cave-print-ids.html \
cave-print-owners.html \
cave-print-packages.html \
@@ -67,6 +68,7 @@ CAVE_COMMANDS_HTML = \
cave-resume.html \
cave-search.html \
cave-show.html \
+ cave-size.html \
cave-sync.html \
cave-uninstall.html \
cave-update-world.html \
diff --git a/doc/clients/cave-print-size.html b/doc/clients/cave-print-size.html
new file mode 100644
index 0000000..4187d90
--- /dev/null
+++ b/doc/clients/cave-print-size.html
@@ -0,0 +1,172 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<title>Paludis, the Other Package Mangler</title>
+<link rel="stylesheet" href="../paludis.css" type="text/css" />
+</head>
+<body>
+
+ <div class="topnav">
+
+<!-- vim: set tw=120 ft=html sw=4 sts=4 et : -->
+
+<div class="topnavinner">
+ <table border="0" cellspacing="0" summary="Navigation links">
+ <tr>
+ <td rowspan="7" class="logotab">
+ <a href="..//index.html" class="noarrow"><img style="border: 0px; padding-right: 50px;"
+ src="../paludis_270.png" alt="Paludis Logo"
+ /></a>
+ </td>
+
+ <td>
+ <a href="..//index.html">Introduction</a>
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/cave.html">cave</a>
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/paludis.html">paludis</a>
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/accerso.html">accerso</a>
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+ <a href="http://trac.pioto.org/paludis/">Bugs, Requests, Support</a>
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/importare.html">importare</a>
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/adjutrix.html">adjutrix</a>
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+ <a href="../overview/index.html">Overview</a>
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/inquisitio.html">inquisitio</a>
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/instruo.html">instruo</a>
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+ <a href="../faq/index.html">FAQ</a>
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/reconcilio.html">reconcilio</a>
+ </td>
+
+ <td class="currentpage">
+ <a href="../clients/appareo.html">appareo</a>
+ </td>
+ </tr>
+
+ <tr>
+ <td class="currenttab">
+ <a href="../clients/index.html">Clients</a>
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+ <a href="../configuration/index.html">Configuration</a>
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+ <a href="../api/index.html">API</a>
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+
+ <td class="currentpage">
+ &nbsp;
+ </td>
+ </tr>
+ </table>
+</div>
+
+ </div>
+
+ <div class="main">
+
+<h1>cave print-size(1)</h1>
+<h2>Name</h2>
+<p>cave print-size - Prints the size of files installed by a package.</p>
+<h2>Synopsis</h2>
+<p>cave print-size spec</p>
+<h2>Description</h2>
+<p>Prints the size of files installed by a package. No formatting is used, making the output suitable for parsing by scripts.</p>
+<h2>Options</h2>
+<h3>Global Options</h3>
+<p>Global options, used by every subcommand.</p>
+<dl><dt>-h, --help</dt>
+<dd>display help message
+</dl>
+<!-- vim: set tw=120 ft=html sw=4 sts=4 et : -->
+</div>
+</body>
+</html>
+
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 4a67b62..d2e2989 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -48,6 +48,7 @@ command_MANS = \
cave-print-id-executables.1 \
cave-print-id-masks.1 \
cave-print-id-metadata.1 \
+ cave-print-id-size.1 \
cave-print-ids.1 \
cave-print-owners.1 \
cave-print-packages.1 \
@@ -64,6 +65,7 @@ command_MANS = \
cave-resume.1 \
cave-search.1 \
cave-show.1 \
+ cave-size.1 \
cave-sync.1 \
cave-uninstall.1 \
cave-update-world.1 \
@@ -142,6 +144,7 @@ libcave_a_SOURCES = \
cmd_print_id_executables.cc cmd_print_id_executables.hh \
cmd_print_id_masks.cc cmd_print_id_masks.hh \
cmd_print_id_metadata.cc cmd_print_id_metadata.hh \
+ cmd_print_id_size.cc cmd_print_id_size.hh \
cmd_print_ids.cc cmd_print_ids.hh \
cmd_print_owners.cc cmd_print_owners.hh \
cmd_print_packages.cc cmd_print_packages.hh \
@@ -162,6 +165,7 @@ libcave_a_SOURCES = \
cmd_search.cc cmd_search.hh \
cmd_search_cmdline.cc cmd_search_cmdline.hh \
cmd_show.cc cmd_show.hh cmd_show-fmt.hh \
+ cmd_size.cc cmd_size.hh \
cmd_sync.cc cmd_sync.hh cmd_sync-fmt.hh \
cmd_uninstall.cc cmd_uninstall.hh \
cmd_update_world.cc cmd_update_world.hh cmd_update_world-fmt.hh \
@@ -178,7 +182,8 @@ libcave_a_SOURCES = \
select_format_for_spec.cc select_format_for_spec.hh \
owner_common.cc owner_common.hh \
resolve_common.cc resolve_common.hh \
- resume_data.cc resume_data.hh
+ resume_data.cc resume_data.hh \
+ size_common.cc size_common.hh
TESTS = \
continue_on_failure_TEST
diff --git a/src/clients/cave/cmd_print_id_size.cc b/src/clients/cave/cmd_print_id_size.cc
new file mode 100644
index 0000000..03c3c23
--- /dev/null
+++ b/src/clients/cave/cmd_print_id_size.cc
@@ -0,0 +1,93 @@
+/* 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_print_id_size.hh"
+#include "command_command_line.hh"
+#include "size_common.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <iostream>
+#include <cstdlib>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintIDSizeCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-id-size";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints the size of files installed by a package.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints the size of files installed by a package. No formatting is used, making the output suitable for parsing by scripts.";
+ }
+
+ args::ArgsGroup g_spec_options;
+ args::SwitchArg a_all;
+ args::SwitchArg a_best;
+
+ PrintIDSizeCommandLine() :
+ g_spec_options(main_options_section(), "Spec Options", "Alter how the supplied spec is used."),
+ a_all(&g_spec_options, "all", 'a', "If the spec matches multiple IDs, display all matches.", true),
+ a_best(&g_spec_options, "best", 'b', "If the spec matches multiple IDs, select the best ID rather than giving an error.", true)
+ {
+ add_usage_line("spec");
+ }
+ };
+}
+
+int
+PrintIDSizeCommand::run(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintIDSizeCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_ID_SIZE_OPTIONS", "CAVE_PRINT_ID_SIZE_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1)
+ throw args::DoHelp("print-id-size takes exactly one parameter");
+
+ return size_common(env, false, *cmdline.begin_parameters(), cmdline.a_all.specified(), cmdline.a_best.specified());
+}
+
+std::shared_ptr<args::ArgsHandler>
+PrintIDSizeCommand::make_doc_cmdline()
+{
+ return std::make_shared<PrintIDSizeCommandLine>();
+}
+
diff --git a/src/clients/cave/cmd_print_id_size.hh b/src/clients/cave/cmd_print_id_size.hh
new file mode 100644
index 0000000..4da0218
--- /dev/null
+++ b/src/clients/cave/cmd_print_id_size.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_PRINT_ID_SIZE_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_ID_SIZE_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintIDSizeCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ std::shared_ptr<args::ArgsHandler> make_doc_cmdline();
+ };
+ }
+}
+
+#endif
diff --git a/src/clients/cave/cmd_size.cc b/src/clients/cave/cmd_size.cc
new file mode 100644
index 0000000..ee18932
--- /dev/null
+++ b/src/clients/cave/cmd_size.cc
@@ -0,0 +1,93 @@
+/* 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_size.hh"
+#include "command_command_line.hh"
+#include "size_common.hh"
+
+#include <paludis/action.hh>
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/stringify.hh>
+
+#include <iostream>
+#include <cstdlib>
+#include <functional>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct SizeCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave size";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Shows the size of files installed by a package.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Shows the size of files installed by a package.";
+ }
+
+ SizeCommandLine()
+ {
+ add_usage_line("spec");
+ }
+ };
+}
+
+int
+SizeCommand::run(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ SizeCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_SIZE_OPTIONS", "CAVE_SIZE_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1)
+ throw args::DoHelp("size takes exactly one parameter");
+
+ return size_common(env, true, *cmdline.begin_parameters(), true, false);
+}
+
+std::shared_ptr<args::ArgsHandler>
+SizeCommand::make_doc_cmdline()
+{
+ return std::make_shared<SizeCommandLine>();
+}
+
diff --git a/src/clients/cave/cmd_size.hh b/src/clients/cave/cmd_size.hh
new file mode 100644
index 0000000..9937f79
--- /dev/null
+++ b/src/clients/cave/cmd_size.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_SIZE_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_SIZE_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE SizeCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ std::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 8ae273f..9c13998 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -61,6 +61,7 @@
#include "cmd_print_id_executables.hh"
#include "cmd_print_id_masks.hh"
#include "cmd_print_id_metadata.hh"
+#include "cmd_print_id_size.hh"
#include "cmd_print_ids.hh"
#include "cmd_print_owners.hh"
#include "cmd_print_packages.hh"
@@ -77,6 +78,7 @@
#include "cmd_resume.hh"
#include "cmd_search.hh"
#include "cmd_show.hh"
+#include "cmd_size.hh"
#include "cmd_sync.hh"
#include "cmd_uninstall.hh"
#include "cmd_update_world.hh"
@@ -172,6 +174,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("print-id-executables", std::bind(&make_command<PrintIDExecutablesCommand>)));
_imp->handlers.insert(std::make_pair("print-id-masks", std::bind(&make_command<PrintIDMasksCommand>)));
_imp->handlers.insert(std::make_pair("print-id-metadata", std::bind(&make_command<PrintIDMetadataCommand>)));
+ _imp->handlers.insert(std::make_pair("print-id-size", std::bind(&make_command<PrintIDSizeCommand>)));
_imp->handlers.insert(std::make_pair("print-ids", std::bind(&make_command<PrintIDsCommand>)));
_imp->handlers.insert(std::make_pair("print-owners", std::bind(&make_command<PrintOwnersCommand>)));
_imp->handlers.insert(std::make_pair("print-packages", std::bind(&make_command<PrintPackagesCommand>)));
@@ -187,6 +190,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("resume", std::bind(&make_command<ResumeCommand>)));
_imp->handlers.insert(std::make_pair("search", std::bind(&make_command<SearchCommand>)));
_imp->handlers.insert(std::make_pair("show", std::bind(&make_command<ShowCommand>)));
+ _imp->handlers.insert(std::make_pair("size", std::bind(&make_command<SizeCommand>)));
_imp->handlers.insert(std::make_pair("sync", std::bind(&make_command<SyncCommand>)));
_imp->handlers.insert(std::make_pair("uninstall", std::bind(&make_command<UninstallCommand>)));
_imp->handlers.insert(std::make_pair("update-world", std::bind(&make_command<UpdateWorldCommand>)));
diff --git a/src/clients/cave/size_common.cc b/src/clients/cave/size_common.cc
new file mode 100644
index 0000000..07f016c
--- /dev/null
+++ b/src/clients/cave/size_common.cc
@@ -0,0 +1,123 @@
+/* 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 "size_common.hh"
+#include "exceptions.hh"
+#include <paludis/action.hh>
+#include <paludis/contents.hh>
+#include <paludis/environment.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/generator.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/name.hh>
+#include <paludis/package_database.hh>
+#include <paludis/package_id.hh>
+#include <paludis/repository.hh>
+#include <paludis/selection.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/pretty_print.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/fs_path.hh>
+#include <paludis/util/fs_stat.hh>
+#include <paludis/util/iterator_funcs.hh>
+#include <algorithm>
+#include <functional>
+#include <iostream>
+
+using namespace paludis;
+
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct GetSize
+ {
+ unsigned long visit(const ContentsDirEntry &) const
+ {
+ return 0;
+ }
+
+ unsigned long visit(const ContentsSymEntry &) const
+ {
+ return 0;
+ }
+
+ unsigned long visit(const ContentsOtherEntry &) const
+ {
+ return 0;
+ }
+
+ unsigned long visit(const ContentsFileEntry & e) const
+ {
+ FSPath path(e.location_key()->value());
+ FSStat stat(path);
+
+ if (stat.is_regular_file_or_symlink_to_regular_file())
+ return stat.file_size();
+ else
+ {
+ Log::get_instance()->message("cave.size.muissing", ll_warning, lc_context) << "Couldn't get size for '"
+ << path << "'";
+ return 0;
+ }
+ }
+ };
+}
+
+int
+paludis::cave::size_common(
+ const std::shared_ptr<Environment> & env,
+ const bool purdy,
+ const std::string & q,
+ const bool all,
+ const bool best)
+{
+ PackageDepSpec spec(parse_user_package_dep_spec(q, env.get(), { }));
+ std::shared_ptr<const PackageIDSequence> entries((*env)[selection::AllVersionsSorted(generator::Matches(spec, { }) |
+ filter::InstalledAtRoot(env->preferred_root_key()->value()))]);
+
+ if (entries->empty())
+ return EXIT_FAILURE;
+ else if ((! best) && (! all) && (next(entries->begin()) != entries->end()))
+ throw BeMoreSpecific(spec, entries);
+
+ for (auto i(best ? entries->last() : entries->begin()), i_end(entries->end()) ;
+ i != i_end ; ++i)
+ {
+ if (! (*i)->contents_key())
+ throw BadIDForCommand(spec, (*i), "does not support listing contents");
+
+ unsigned long size(0);
+ for (auto c((*i)->contents_key()->value()->begin()), c_end((*i)->contents_key()->value()->end()) ;
+ c != c_end ; ++c)
+ size += (*c)->accept_returning<unsigned long>(GetSize());
+
+ if (purdy)
+ cout << pretty_print_bytes(size) << endl;
+ else
+ cout << size << endl;
+ }
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/src/clients/cave/size_common.hh b/src/clients/cave/size_common.hh
new file mode 100644
index 0000000..d00678e
--- /dev/null
+++ b/src/clients/cave/size_common.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_SIZE_COMMON_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_SIZE_COMMON_HH 1
+
+#include <paludis/package_id-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <string>
+#include <memory>
+#include <functional>
+
+namespace paludis
+{
+ namespace cave
+ {
+ int size_common(
+ const std::shared_ptr<Environment> & env,
+ const bool purdy,
+ const std::string & query,
+ const bool all,
+ const bool best);
+ }
+}
+
+#endif