aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-06-21 20:36:18 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-06-21 20:37:18 +0100
commite6002a401adf0fc173ac4995a7628b789664f3da (patch)
treec4c50700724b3b9c876e41a148d867e65a353625
parentdb00a9998ed27ad2d9c917b85100e262bcc51f28 (diff)
downloadpaludis-e6002a401adf0fc173ac4995a7628b789664f3da.tar.gz
paludis-e6002a401adf0fc173ac4995a7628b789664f3da.tar.xz
Merger::permit_destination
-rw-r--r--paludis/fs_merger.cc1
-rw-r--r--paludis/fs_merger.hh5
-rw-r--r--paludis/fs_merger_TEST.cc4
-rw-r--r--paludis/merger.cc18
-rw-r--r--paludis/merger.hh14
-rw-r--r--paludis/ndbam_merger.cc1
-rw-r--r--paludis/ndbam_merger.hh2
-rw-r--r--paludis/repositories/e/e_repository.cc2
-rw-r--r--paludis/repositories/e/exndbam_repository.cc2
-rw-r--r--paludis/repositories/e/pbin_merger.cc1
-rw-r--r--paludis/repositories/e/pbin_merger.hh2
-rw-r--r--paludis/repositories/e/vdb_merger.cc1
-rw-r--r--paludis/repositories/e/vdb_merger.hh2
-rw-r--r--paludis/repositories/e/vdb_merger_TEST.cc4
-rw-r--r--paludis/repositories/e/vdb_repository.cc2
-rw-r--r--paludis/repositories/unpackaged/installed_repository.cc9
-rw-r--r--paludis/tar_merger.cc1
-rw-r--r--paludis/tar_merger.hh2
-rw-r--r--paludis/tar_merger_TEST.cc4
19 files changed, 69 insertions, 8 deletions
diff --git a/paludis/fs_merger.cc b/paludis/fs_merger.cc
index 6aa3f54..883e4ea 100644
--- a/paludis/fs_merger.cc
+++ b/paludis/fs_merger.cc
@@ -93,6 +93,7 @@ FSMerger::FSMerger(const FSMergerParams & p) :
n::merged_entries() = p.merged_entries(),
n::no_chown() = p.no_chown(),
n::options() = p.options(),
+ n::permit_destination() = p.permit_destination(),
n::root() = p.root()
)),
_imp(p)
diff --git a/paludis/fs_merger.hh b/paludis/fs_merger.hh
index 5713b52..6d6036d 100644
--- a/paludis/fs_merger.hh
+++ b/paludis/fs_merger.hh
@@ -57,6 +57,7 @@ namespace paludis
typedef Name<struct name_merged_entries> merged_entries;
typedef Name<struct name_no_chown> no_chown;
typedef Name<struct name_options> options;
+ typedef Name<struct name_permit_destination> permit_destination;
typedef Name<struct name_root> root;
}
@@ -96,6 +97,10 @@ namespace paludis
NamedValue<n::no_chown, bool> no_chown;
NamedValue<n::options, MergerOptions> options;
+
+ ///\since 0.66
+ NamedValue<n::permit_destination, PermitDestinationFn> permit_destination;
+
NamedValue<n::root, FSPath> root;
};
diff --git a/paludis/fs_merger_TEST.cc b/paludis/fs_merger_TEST.cc
index 0e5c0bb..f958c0f 100644
--- a/paludis/fs_merger_TEST.cc
+++ b/paludis/fs_merger_TEST.cc
@@ -34,7 +34,9 @@
#include <paludis/util/fs_path.hh>
#include <paludis/util/fs_error.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/return_literal_function.hh>
+#include <functional>
#include <iterator>
#include <list>
@@ -172,6 +174,7 @@ namespace
n::merged_entries() = std::make_shared<FSPathSet>(),
n::no_chown() = true,
n::options() = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = root_dir
))
{
@@ -193,6 +196,7 @@ namespace
n::merged_entries() = std::make_shared<FSPathSet>(),
n::no_chown() = true,
n::options() = o,
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = root_dir
))
{
diff --git a/paludis/merger.cc b/paludis/merger.cc
index 287f6cb..ed7dadf 100644
--- a/paludis/merger.cc
+++ b/paludis/merger.cc
@@ -151,13 +151,19 @@ Merger::do_dir_recursive(bool is_check, const FSPath & src, const FSPath & dst)
FSIterator d(src, { fsio_include_dotfiles, fsio_inode_sort }), d_end;
- if (is_check && d == d_end && dst != _imp->params.root().realpath())
+ if (is_check)
{
- if (_imp->params.options()[mo_allow_empty_dirs])
- Log::get_instance()->message("merger.empty_directory", ll_warning, lc_context) << "Installing empty directory '"
- << stringify(dst) << "'";
- else
- on_error(is_check, "Attempted to install empty directory '" + stringify(dst) + "'");
+ if (d == d_end && dst != _imp->params.root().realpath())
+ {
+ if (_imp->params.options()[mo_allow_empty_dirs])
+ Log::get_instance()->message("merger.empty_directory", ll_warning, lc_context) << "Installing empty directory '"
+ << stringify(dst) << "'";
+ else
+ on_error(is_check, "Attempted to install empty directory '" + stringify(dst) + "'");
+ }
+
+ if (! _imp->params.permit_destination()(dst))
+ on_error(is_check, "Not allowed to merge '" + stringify(src) + "' to '" + stringify(dst) + "'");
}
for ( ; d != d_end ; ++d)
diff --git a/paludis/merger.hh b/paludis/merger.hh
index e9ca693..800c56f 100644
--- a/paludis/merger.hh
+++ b/paludis/merger.hh
@@ -43,10 +43,20 @@ namespace paludis
typedef Name<struct name_merged_entries> merged_entries;
typedef Name<struct name_no_chown> no_chown;
typedef Name<struct name_options> options;
+ typedef Name<struct name_permit_destination> permit_destination;
typedef Name<struct name_root> root;
}
/**
+ * Whether to allow merging to a particular destination.
+ *
+ * \ingroup g_repository
+ * \see MergerParams
+ * \since 0.66
+ */
+ typedef std::function<bool (const FSPath &)> PermitDestinationFn;
+
+ /**
* Parameters for a basic Merger.
*
* \see Merger
@@ -65,6 +75,10 @@ namespace paludis
NamedValue<n::merged_entries, std::shared_ptr<FSPathSet> > merged_entries;
NamedValue<n::no_chown, bool> no_chown;
NamedValue<n::options, MergerOptions> options;
+
+ ///\since 0.66
+ NamedValue<n::permit_destination, PermitDestinationFn> permit_destination;
+
NamedValue<n::root, FSPath> root;
};
diff --git a/paludis/ndbam_merger.cc b/paludis/ndbam_merger.cc
index a57794a..ad8d14c 100644
--- a/paludis/ndbam_merger.cc
+++ b/paludis/ndbam_merger.cc
@@ -82,6 +82,7 @@ NDBAMMerger::NDBAMMerger(const NDBAMMergerParams & p) :
n::merged_entries() = p.merged_entries(),
n::no_chown() = ! getenv_with_default(env_vars::no_chown, "").empty(),
n::options() = p.options(),
+ n::permit_destination() = p.permit_destination(),
n::root() = p.root()
)),
_imp(p)
diff --git a/paludis/ndbam_merger.hh b/paludis/ndbam_merger.hh
index e938352..d6c551e 100644
--- a/paludis/ndbam_merger.hh
+++ b/paludis/ndbam_merger.hh
@@ -42,6 +42,7 @@ namespace paludis
typedef Name<struct name_options> options;
typedef Name<struct name_output_manager> output_manager;
typedef Name<struct name_package_id> package_id;
+ typedef Name<struct name_permit_destination> permit_destination;
typedef Name<struct name_root> root;
}
@@ -59,6 +60,7 @@ namespace paludis
NamedValue<n::options, MergerOptions> options;
NamedValue<n::output_manager, std::shared_ptr<OutputManager> > output_manager;
NamedValue<n::package_id, std::shared_ptr<const PackageID> > package_id;
+ NamedValue<n::permit_destination, PermitDestinationFn> permit_destination;
NamedValue<n::root, FSPath> root;
};
diff --git a/paludis/repositories/e/e_repository.cc b/paludis/repositories/e/e_repository.cc
index 9209619..b9d9ab4 100644
--- a/paludis/repositories/e/e_repository.cc
+++ b/paludis/repositories/e/e_repository.cc
@@ -82,6 +82,7 @@
#include <paludis/util/options.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/process.hh>
+#include <paludis/util/return_literal_function.hh>
#include <paludis/util/rmd160.hh>
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/safe_ofstream.hh>
@@ -1727,6 +1728,7 @@ ERepository::merge(const MergeParams & m)
n::options() = m.options(),
n::output_manager() = m.output_manager(),
n::package_id() = m.package_id(),
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = FSPath("/"),
n::tar_file() = _imp->params.binary_distdir() / (bin_dist_base + pbin_tar_extension)
));
diff --git a/paludis/repositories/e/exndbam_repository.cc b/paludis/repositories/e/exndbam_repository.cc
index f301839..71a9624 100644
--- a/paludis/repositories/e/exndbam_repository.cc
+++ b/paludis/repositories/e/exndbam_repository.cc
@@ -39,6 +39,7 @@
#include <paludis/util/fs_stat.hh>
#include <paludis/util/fs_iterator.hh>
#include <paludis/util/join.hh>
+#include <paludis/util/return_literal_function.hh>
#include <paludis/output_manager.hh>
#include <paludis/distribution.hh>
@@ -430,6 +431,7 @@ ExndbamRepository::merge(const MergeParams & m)
n::options() = m.options(),
n::output_manager() = m.output_manager(),
n::package_id() = m.package_id(),
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = installed_root_key()->parse_value()
));
diff --git a/paludis/repositories/e/pbin_merger.cc b/paludis/repositories/e/pbin_merger.cc
index 24052d1..98c2919 100644
--- a/paludis/repositories/e/pbin_merger.cc
+++ b/paludis/repositories/e/pbin_merger.cc
@@ -76,6 +76,7 @@ PbinMerger::PbinMerger(const PbinMergerParams & p) :
n::merged_entries() = p.merged_entries(),
n::no_chown() = ! getenv_with_default(env_vars::no_chown, "").empty(),
n::options() = p.options(),
+ n::permit_destination() = p.permit_destination(),
n::root() = p.root(),
n::tar_file() = p.tar_file()
)),
diff --git a/paludis/repositories/e/pbin_merger.hh b/paludis/repositories/e/pbin_merger.hh
index 09c958e..dbc29c5 100644
--- a/paludis/repositories/e/pbin_merger.hh
+++ b/paludis/repositories/e/pbin_merger.hh
@@ -39,6 +39,7 @@ namespace paludis
typedef Name<struct name_options> options;
typedef Name<struct name_output_manager> output_manager;
typedef Name<struct name_package_id> package_id;
+ typedef Name<struct name_permit_destination> permit_destination;
typedef Name<struct name_root> root;
typedef Name<struct name_tar_file> tar_file;
}
@@ -56,6 +57,7 @@ namespace paludis
NamedValue<n::options, MergerOptions> options;
NamedValue<n::output_manager, std::shared_ptr<OutputManager> > output_manager;
NamedValue<n::package_id, std::shared_ptr<const PackageID> > package_id;
+ NamedValue<n::permit_destination, PermitDestinationFn> permit_destination;
NamedValue<n::root, FSPath> root;
NamedValue<n::tar_file, FSPath> tar_file;
};
diff --git a/paludis/repositories/e/vdb_merger.cc b/paludis/repositories/e/vdb_merger.cc
index ebe0568..8c6b23c 100644
--- a/paludis/repositories/e/vdb_merger.cc
+++ b/paludis/repositories/e/vdb_merger.cc
@@ -96,6 +96,7 @@ VDBMerger::VDBMerger(const VDBMergerParams & p) :
n::merged_entries() = p.merged_entries(),
n::no_chown() = ! getenv_with_default(env_vars::no_chown, "").empty(),
n::options() = p.options(),
+ n::permit_destination() = p.permit_destination(),
n::root() = p.root()
)),
_imp(p)
diff --git a/paludis/repositories/e/vdb_merger.hh b/paludis/repositories/e/vdb_merger.hh
index 457cd0f..57374e1 100644
--- a/paludis/repositories/e/vdb_merger.hh
+++ b/paludis/repositories/e/vdb_merger.hh
@@ -40,6 +40,7 @@ namespace paludis
typedef Name<struct name_options> options;
typedef Name<struct name_output_manager> output_manager;
typedef Name<struct name_package_id> package_id;
+ typedef Name<struct name_permit_destination> permit_destination;
typedef Name<struct name_root> root;
}
@@ -64,6 +65,7 @@ namespace paludis
NamedValue<n::options, MergerOptions> options;
NamedValue<n::output_manager, std::shared_ptr<OutputManager> > output_manager;
NamedValue<n::package_id, std::shared_ptr<const PackageID> > package_id;
+ NamedValue<n::permit_destination, PermitDestinationFn> permit_destination;
NamedValue<n::root, FSPath> root;
};
diff --git a/paludis/repositories/e/vdb_merger_TEST.cc b/paludis/repositories/e/vdb_merger_TEST.cc
index 034a5b1..223a36f 100644
--- a/paludis/repositories/e/vdb_merger_TEST.cc
+++ b/paludis/repositories/e/vdb_merger_TEST.cc
@@ -29,9 +29,12 @@
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/set.hh>
#include <paludis/util/fs_stat.hh>
+#include <paludis/util/return_literal_function.hh>
#include <paludis/standard_output_manager.hh>
+#include <functional>
+
#include <gtest/gtest.h>
using namespace paludis;
@@ -109,6 +112,7 @@ namespace
n::options() = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
n::output_manager() = std::make_shared<StandardOutputManager>(),
n::package_id() = std::shared_ptr<PackageID>(),
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = root_dir
));
}
diff --git a/paludis/repositories/e/vdb_repository.cc b/paludis/repositories/e/vdb_repository.cc
index b1063e7..373b7dd 100644
--- a/paludis/repositories/e/vdb_repository.cc
+++ b/paludis/repositories/e/vdb_repository.cc
@@ -78,6 +78,7 @@
#include <paludis/util/fs_stat.hh>
#include <paludis/util/fs_iterator.hh>
#include <paludis/util/join.hh>
+#include <paludis/util/return_literal_function.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/create_iterator-impl.hh>
@@ -657,6 +658,7 @@ VDBRepository::merge(const MergeParams & m)
n::options() = m.options(),
n::output_manager() = m.output_manager(),
n::package_id() = m.package_id(),
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = installed_root_key()->parse_value()
));
diff --git a/paludis/repositories/unpackaged/installed_repository.cc b/paludis/repositories/unpackaged/installed_repository.cc
index 89924a3..67a6c94 100644
--- a/paludis/repositories/unpackaged/installed_repository.cc
+++ b/paludis/repositories/unpackaged/installed_repository.cc
@@ -20,8 +20,7 @@
#include <paludis/repositories/unpackaged/installed_repository.hh>
#include <paludis/repositories/unpackaged/installed_id.hh>
#include <paludis/repositories/unpackaged/exceptions.hh>
-#include <paludis/ndbam.hh>
-#include <paludis/ndbam_merger.hh>
+
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/stringify.hh>
@@ -36,6 +35,10 @@
#include <paludis/util/make_null_shared_ptr.hh>
#include <paludis/util/fs_iterator.hh>
#include <paludis/util/fs_stat.hh>
+#include <paludis/util/return_literal_function.hh>
+
+#include <paludis/ndbam.hh>
+#include <paludis/ndbam_merger.hh>
#include <paludis/action.hh>
#include <paludis/environment.hh>
#include <paludis/metadata_key.hh>
@@ -48,6 +51,7 @@
#include <paludis/hook.hh>
#include <paludis/common_sets.hh>
#include <paludis/unformatted_pretty_printer.hh>
+
#include <sstream>
#include <sys/time.h>
@@ -374,6 +378,7 @@ InstalledUnpackagedRepository::merge(const MergeParams & m)
n::options() = m.options(),
n::output_manager() = m.output_manager(),
n::package_id() = m.package_id(),
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = installed_root_key()->parse_value()
));
diff --git a/paludis/tar_merger.cc b/paludis/tar_merger.cc
index ab97335..d487753 100644
--- a/paludis/tar_merger.cc
+++ b/paludis/tar_merger.cc
@@ -117,6 +117,7 @@ TarMerger::TarMerger(const TarMergerParams & p) :
n::merged_entries() = p.merged_entries(),
n::no_chown() = p.no_chown(),
n::options() = p.options(),
+ n::permit_destination() = p.permit_destination(),
n::root() = p.root()
)),
_imp(p)
diff --git a/paludis/tar_merger.hh b/paludis/tar_merger.hh
index 9e57e3b..c6f8775 100644
--- a/paludis/tar_merger.hh
+++ b/paludis/tar_merger.hh
@@ -38,6 +38,7 @@ namespace paludis
typedef Name<struct name_merged_entries> merged_entries;
typedef Name<struct name_no_chown> no_chown;
typedef Name<struct name_options> options;
+ typedef Name<struct name_permit_destination> permit_destination;
typedef Name<struct name_root> root;
typedef Name<struct name_tar_file> tar_file;
}
@@ -62,6 +63,7 @@ namespace paludis
NamedValue<n::merged_entries, std::shared_ptr<FSPathSet> > merged_entries;
NamedValue<n::no_chown, bool> no_chown;
NamedValue<n::options, MergerOptions> options;
+ NamedValue<n::permit_destination, PermitDestinationFn> permit_destination;
NamedValue<n::root, FSPath> root;
NamedValue<n::tar_file, FSPath> tar_file;
};
diff --git a/paludis/tar_merger_TEST.cc b/paludis/tar_merger_TEST.cc
index 6fed784..96d718c 100644
--- a/paludis/tar_merger_TEST.cc
+++ b/paludis/tar_merger_TEST.cc
@@ -31,6 +31,9 @@
#include <paludis/util/stringify.hh>
#include <paludis/util/make_null_shared_ptr.hh>
#include <paludis/util/fs_stat.hh>
+#include <paludis/util/return_literal_function.hh>
+
+#include <functional>
#include <gtest/gtest.h>
@@ -98,6 +101,7 @@ TEST(TarMerger, Works)
n::merged_entries() = std::make_shared<FSPathSet>(),
n::no_chown() = true,
n::options() = MergerOptions() + mo_rewrite_symlinks,
+ n::permit_destination() = std::bind(return_literal_function(true)),
n::root() = FSPath("/"),
n::tar_file() = output
));