aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-03-08 16:05:48 +0000
committerAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-03-08 16:05:48 +0000
commitbc41693a10284b3c0ae8f01d0569249e6643b608 (patch)
treee52a0c0607190f9e75b94aad189e6421c568e4b1
parentc78ad6f074ed0e796594ed97defd1304f7d119e4 (diff)
downloadpaludis-bc41693a10284b3c0ae8f01d0569249e6643b608.tar.gz
paludis-bc41693a10284b3c0ae8f01d0569249e6643b608.tar.xz
Add strip_leading methods to FSEntry and use that instead of VDBMerger::make_tidy.
-rw-r--r--paludis/repositories/gentoo/vdb_merger.cc21
-rw-r--r--paludis/repositories/gentoo/vdb_merger.hh3
-rw-r--r--paludis/util/fs_entry.cc12
-rw-r--r--paludis/util/fs_entry.hh5
-rw-r--r--paludis/util/fs_entry_TEST.cc27
5 files changed, 49 insertions, 19 deletions
diff --git a/paludis/repositories/gentoo/vdb_merger.cc b/paludis/repositories/gentoo/vdb_merger.cc
index 33635b3..3f23a7a 100644
--- a/paludis/repositories/gentoo/vdb_merger.cc
+++ b/paludis/repositories/gentoo/vdb_merger.cc
@@ -95,7 +95,8 @@ VDBMerger::extend_hook(const Hook & h)
void
VDBMerger::record_install_file(const FSEntry & src, const FSEntry & dst_dir, const std::string & dst_name)
{
- std::string tidy(make_tidy(dst_dir / dst_name)), tidy_real(make_tidy(dst_dir / src.basename()));
+ std::string tidy(stringify((dst_dir / dst_name).strip_leading(_imp->options.root))),
+ tidy_real(stringify((dst_dir / src.basename()).strip_leading(_imp->options.root)));
time_t timestamp((dst_dir / dst_name).mtime());
std::ifstream infile(stringify(FSEntry(dst_dir / dst_name)).c_str());
@@ -115,8 +116,7 @@ VDBMerger::record_install_file(const FSEntry & src, const FSEntry & dst_dir, con
void
VDBMerger::record_install_dir(const FSEntry & src, const FSEntry & dst_dir)
{
- std::string tidy(make_tidy(dst_dir / src.basename()));
-
+ std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->options.root)));
std::cout << ">>> [dir] " << tidy << std::endl;
*_imp->contents_file << "dir " << tidy << std::endl;
@@ -125,7 +125,7 @@ VDBMerger::record_install_dir(const FSEntry & src, const FSEntry & dst_dir)
void
VDBMerger::record_install_sym(const FSEntry & src, const FSEntry & dst_dir)
{
- std::string tidy(make_tidy(dst_dir / src.basename()));
+ std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->options.root)));
std::string target((dst_dir / src.basename()).readlink());
time_t timestamp((dst_dir / src.basename()).mtime());
@@ -155,7 +155,7 @@ VDBMerger::on_warn(bool is_check, const std::string & s)
bool
VDBMerger::config_protected(const FSEntry & src, const FSEntry & dst_dir)
{
- std::string tidy(make_tidy(dst_dir / src.basename()));
+ std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->options.root)));
bool result(false);
for (std::list<std::string>::const_iterator c(_imp->config_protect.begin()),
@@ -221,14 +221,3 @@ VDBMerger::check()
return Merger::check();
}
-std::string
-VDBMerger::make_tidy(const FSEntry & f) const
-{
- std::string root_str(stringify(_imp->options.root)), f_str(stringify(f));
- if (root_str == "/")
- root_str.clear();
- if (0 != f_str.compare(0, root_str.length(), root_str))
- throw MergerError("Can't work out tidy name for '" + f_str + "' with root '" + root_str + "'");
- return f_str.substr(root_str.length());
-}
-
diff --git a/paludis/repositories/gentoo/vdb_merger.hh b/paludis/repositories/gentoo/vdb_merger.hh
index d3f8eb9..194b2bc 100644
--- a/paludis/repositories/gentoo/vdb_merger.hh
+++ b/paludis/repositories/gentoo/vdb_merger.hh
@@ -34,9 +34,6 @@ namespace paludis
public Merger,
private PrivateImplementationPattern<VDBMerger>
{
- protected:
- std::string make_tidy(const FSEntry &) const;
-
public:
VDBMerger(const VDBMergerOptions &);
~VDBMerger();
diff --git a/paludis/util/fs_entry.cc b/paludis/util/fs_entry.cc
index 72647da..204ce6e 100644
--- a/paludis/util/fs_entry.cc
+++ b/paludis/util/fs_entry.cc
@@ -309,6 +309,18 @@ FSEntry::basename() const
}
FSEntry
+FSEntry::strip_leading(const FSEntry & f) const
+{
+ std::string root(stringify(f));
+
+ if (root == "/")
+ root.clear();
+ if (0 != _path.compare(0, root.length(), root))
+ throw FSError("Can't strip leading '" + root + "' from FSEntry '" + _path + "'");
+ return FSEntry(_path.substr(root.length()));
+}
+
+FSEntry
FSEntry::dirname() const
{
if (_path == "/")
diff --git a/paludis/util/fs_entry.hh b/paludis/util/fs_entry.hh
index 69e3a30..0c5bff1 100644
--- a/paludis/util/fs_entry.hh
+++ b/paludis/util/fs_entry.hh
@@ -163,6 +163,11 @@ namespace paludis
PALUDIS_ATTRIBUTE((warn_unused_result));
/**
+ * Return the path without a given prefix (eg '/foo/bar/baz'->strip_leading('/foo') => '/bar/baz').
+ */
+ FSEntry strip_leading(const FSEntry & prefix) const;
+
+ /**
* Return the first part of our path (eg '/foo/bar' => '/foo').
*/
FSEntry dirname() const
diff --git a/paludis/util/fs_entry_TEST.cc b/paludis/util/fs_entry_TEST.cc
index 4e57d4e..aca7e32 100644
--- a/paludis/util/fs_entry_TEST.cc
+++ b/paludis/util/fs_entry_TEST.cc
@@ -267,6 +267,33 @@ namespace test_cases
} test_fs_entry_dir_base_name;
/**
+ * \test Test FSEntry strip_leading method
+ *
+ * \ingroup grpfilesystem
+ */
+ struct FSEntryStripLeading : TestCase
+ {
+ FSEntryStripLeading() : TestCase("strip_leading") {}
+
+ void run()
+ {
+ FSEntry root1("/stairway/to/heaven/");
+ FSEntry root2("");
+ FSEntry root3("/");
+
+ FSEntry a(root1);
+ FSEntry b(root1 / "usr" / "share");
+ FSEntry c(root2 / "my" / "directory");
+ FSEntry d(root3 / "my" / "directory");
+
+ TEST_CHECK(stringify(a.strip_leading(root1)) == "/");
+ TEST_CHECK(stringify(b.strip_leading(root1)) == "/usr/share");
+ TEST_CHECK(stringify(c.strip_leading(root2)) == "/my/directory");
+ TEST_CHECK(stringify(d.strip_leading(root3)) == "/my/directory");
+ }
+ } test_fs_entry_strip_leading;
+
+ /**
* \test Test FSEntry chmod, chown and permissions methods
*
* \ingroup grpfilesystem