aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-08-12 15:05:41 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-08-12 15:05:41 +0000
commita613b16bb6af396ab612c294e5f8c8874bbac515 (patch)
tree927ce52d03035c0b4bc5c2b450e9ae402906f8f1
parentc95bc893846259e3120cc5811533805115401f89 (diff)
downloadpaludis-a613b16bb6af396ab612c294e5f8c8874bbac515.tar.gz
paludis-a613b16bb6af396ab612c294e5f8c8874bbac515.tar.xz
Fix config protect handling for PMS compliance and ${ROOT}!=/.
-rwxr-xr-xhooks/find_config_updates.hook22
-rw-r--r--paludis/repositories/e/Makefile.am18
-rw-r--r--paludis/repositories/e/vdb_merger.cc31
-rw-r--r--paludis/repositories/e/vdb_merger.hh2
-rw-r--r--paludis/repositories/e/vdb_merger.sr2
-rw-r--r--paludis/repositories/e/vdb_merger_TEST.cc181
-rwxr-xr-xpaludis/repositories/e/vdb_merger_TEST_cleanup.sh9
-rwxr-xr-xpaludis/repositories/e/vdb_merger_TEST_setup.sh60
-rw-r--r--paludis/repositories/e/vdb_unmerger.cc11
-rw-r--r--paludis/repositories/e/vdb_unmerger_TEST.cc42
-rwxr-xr-xpaludis/repositories/e/vdb_unmerger_TEST_setup.sh22
11 files changed, 375 insertions, 25 deletions
diff --git a/hooks/find_config_updates.hook b/hooks/find_config_updates.hook
index 9a7b618..cd842e2 100755
--- a/hooks/find_config_updates.hook
+++ b/hooks/find_config_updates.hook
@@ -31,21 +31,27 @@ check_for_config_updates()
echo
einfo_unhooked "Searching for configuration files requiring action..."
- dir_count=0
- for dir in /etc ${CONFIG_PROTECT} ; do
- [[ -d "${ROOT%/}/${dir}" ]] || continue
- c=$(find "${ROOT%/}/${dir}" -iname '._cfg????_*' | wc -l )
+ local c dir dirs=""
+ for prot in /etc ${CONFIG_PROTECT} ; do
+ if [[ -d "${ROOT%/}/${prot}" ]]; then
+ dir="${prot}"
+ c=$(find "${ROOT%/}/${dir}" -iname '._cfg????_*' | wc -l )
+ else
+ dir="${prot%/*}"
+ [[ -d "${ROOT%/}/${dir}" ]] || continue
+ c=$(find "${ROOT%/}/${dir}" -maxdepth 1 -iname "._cfg????_${prot##*/}" | wc -l )
+ fi
if [[ ${c} -gt 0 ]] ; then
- einfo_unhooked "Found ${c} files in ${ROOT%%+(/)}/${dir}"
- dir_count=$((dir_count + 1))
+ einfo_unhooked "Found ${c} files in ${ROOT%%+(/)}/${dir##+(/)}"
+ dirs="${dirs:+${dirs}$'\n'}${dir}"
fi
done
- if [[ 0 -eq "${dir_count}" ]] ; then
+ if [[ -z "${dirs}" ]] ; then
einfo_unhooked "No configuration file updates required"
exit 0
else
- ewarn "Found files in ${dir_count} directories"
+ ewarn "Found files in $(sort -u <<<"${dirs}" | wc -l ) directories"
ewarn "Your action is required"
exit 0
fi
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am
index 69e9704..9e01e2c 100644
--- a/paludis/repositories/e/Makefile.am
+++ b/paludis/repositories/e/Makefile.am
@@ -161,6 +161,19 @@ e_repository_TEST_LDADD = \
e_repository_TEST_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)
+vdb_merger_TEST_SOURCES = vdb_merger_TEST.cc
+
+vdb_merger_TEST_LDADD = \
+ libpaludiserepository.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
+ $(top_builddir)/test/libtest.a \
+ $(DYNAMIC_LD_LIBS)
+
+vdb_merger_TEST_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)
+
vdb_unmerger_TEST_SOURCES = vdb_unmerger_TEST.cc
vdb_unmerger_TEST_LDADD = \
@@ -310,6 +323,9 @@ EXTRA_DIST = \
vdb_unmerger.sr \
vdb_unmerger-sr.hh \
vdb_unmerger-sr.cc \
+ vdb_merger_TEST.cc \
+ vdb_merger_TEST_setup.sh \
+ vdb_merger_TEST_cleanup.sh \
vdb_unmerger_TEST.cc \
vdb_unmerger_TEST_setup.sh \
vdb_unmerger_TEST_cleanup.sh
@@ -356,6 +372,7 @@ TESTS_ENVIRONMENT = env \
PALUDIS_SKIP_CONFIG="yes" \
TEST_SCRIPT_DIR="$(srcdir)/" \
PALUDIS_REPOSITORY_SO_DIR="$(top_builddir)/paludis/repositories" \
+ PALUDIS_NO_CHOWN="yes" \
LD_LIBRARY_PATH="`echo $$LD_LIBRARY_PATH: | sed -e 's,^:,,'`` \
$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/e/`:` \
$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/e/.libs/`" \
@@ -459,6 +476,7 @@ TESTS = \
dep_parser_TEST \
dep_spec_pretty_printer_TEST \
e_repository_TEST \
+ vdb_merger_TEST \
vdb_unmerger_TEST \
$(GLSA_TESTS) \
e_repository_sets_TEST \
diff --git a/paludis/repositories/e/vdb_merger.cc b/paludis/repositories/e/vdb_merger.cc
index 5bc6c2f..57a9f84 100644
--- a/paludis/repositories/e/vdb_merger.cc
+++ b/paludis/repositories/e/vdb_merger.cc
@@ -25,6 +25,7 @@
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/fs_entry.hh>
+#include <paludis/util/strip.hh>
#include <paludis/hook.hh>
#include <paludis/package_id.hh>
#include <paludis/digests/md5.hh>
@@ -123,10 +124,10 @@ VDBMerger::record_install_file(const FSEntry & src, const FSEntry & dst_dir, con
MD5 md5(infile);
- std::cout << ">>> [obj] " << tidy_real;
+ std::string line(">>> [obj] " + tidy_real);
if (tidy_real != tidy)
- std::cout << " (" << FSEntry(tidy).basename() << ")";
- std::cout << std::endl;
+ line.append(" (" + FSEntry(tidy).basename() + ")");
+ display_override(line);
*_imp->contents_file << "obj " << tidy_real << " " << md5.hexsum() << " " << timestamp << std::endl;
}
@@ -135,7 +136,7 @@ void
VDBMerger::record_install_dir(const FSEntry & src, const FSEntry & dst_dir)
{
std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->options.root)));
- std::cout << ">>> [dir] " << tidy << std::endl;
+ display_override(">>> [dir] " + tidy);
*_imp->contents_file << "dir " << tidy << std::endl;
}
@@ -147,7 +148,7 @@ VDBMerger::record_install_sym(const FSEntry & src, const FSEntry & dst_dir)
std::string target((dst_dir / src.basename()).readlink());
time_t timestamp((dst_dir / src.basename()).mtime());
- std::cout << ">>> [sym] " << tidy << std::endl;
+ display_override(">>> [sym] " + tidy);
*_imp->contents_file << "sym " << tidy << " -> " << target << " " << timestamp << std::endl;
}
@@ -178,13 +179,19 @@ VDBMerger::config_protected(const FSEntry & src, const FSEntry & dst_dir)
bool result(false);
for (std::list<std::string>::const_iterator c(_imp->config_protect.begin()),
c_end(_imp->config_protect.end()) ; c != c_end && ! result ; ++c)
- if (0 == tidy.compare(0, c->length(), *c))
+ {
+ std::string cc(strip_trailing(*c, "/") + "/");
+ if (tidy == *c || 0 == tidy.compare(0, cc.length(), cc))
result = true;
+ }
if (result)
for (std::list<std::string>::const_iterator c(_imp->config_protect_mask.begin()),
c_end(_imp->config_protect_mask.end()) ; c != c_end && result ; ++c)
- if (0 == tidy.compare(0, c->length(), *c))
+ {
+ std::string cc(strip_trailing(*c, "/") + "/");
+ if (tidy == *c || 0 == tidy.compare(0, cc.length(), cc))
result = false;
+ }
return result;
}
@@ -197,17 +204,17 @@ VDBMerger::make_config_protect_name(const FSEntry & src, const FSEntry & dst)
std::ifstream our_md5_file(stringify(src).c_str());
if (! our_md5_file)
- throw MergerError("Could not get md5 for '" + stringify(dst / src.basename()) + "'");
+ throw MergerError("Could not get md5 for '" + stringify((dst / src.basename()).strip_leading(_imp->options.root)) + "'");
MD5 our_md5(our_md5_file);
while (true)
{
- if (! (_imp->options.root / dst / result_name).exists())
+ if (! (dst / result_name).exists())
break;
- if ((_imp->options.root / dst / result_name).is_regular_file_or_symlink_to_regular_file())
+ if ((dst / result_name).is_regular_file_or_symlink_to_regular_file())
{
- std::ifstream other_md5_file(stringify(_imp->options.root / dst / result_name).c_str());
+ std::ifstream other_md5_file(stringify(dst / result_name).c_str());
if (other_md5_file)
{
MD5 other_md5(other_md5_file);
@@ -227,7 +234,7 @@ VDBMerger::make_config_protect_name(const FSEntry & src, const FSEntry & dst)
void
VDBMerger::merge()
{
- std::cout << ">>> Merging to " << _imp->options.root << std::endl;
+ display_override(">>> Merging to " + stringify(_imp->options.root));
_imp->contents_file.reset(new std::ofstream(stringify(_imp->options.contents_file).c_str()));
Merger::merge();
}
diff --git a/paludis/repositories/e/vdb_merger.hh b/paludis/repositories/e/vdb_merger.hh
index 2108fe3..ce55ab1 100644
--- a/paludis/repositories/e/vdb_merger.hh
+++ b/paludis/repositories/e/vdb_merger.hh
@@ -36,7 +36,7 @@ namespace paludis
* \ingroup grpvdbrepository
* \nosubgrouping
*/
- class VDBMerger :
+ class PALUDIS_VISIBLE VDBMerger :
public Merger,
private PrivateImplementationPattern<VDBMerger>
{
diff --git a/paludis/repositories/e/vdb_merger.sr b/paludis/repositories/e/vdb_merger.sr
index ec52169..3f9d6ee 100644
--- a/paludis/repositories/e/vdb_merger.sr
+++ b/paludis/repositories/e/vdb_merger.sr
@@ -3,6 +3,8 @@
make_class_VDBMergerOptions()
{
+ visible
+
key environment "Environment *"
key image "FSEntry"
key root "FSEntry"
diff --git a/paludis/repositories/e/vdb_merger_TEST.cc b/paludis/repositories/e/vdb_merger_TEST.cc
new file mode 100644
index 0000000..1f9300c
--- /dev/null
+++ b/paludis/repositories/e/vdb_merger_TEST.cc
@@ -0,0 +1,181 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr JaroszyƄski <peper@gentoo.org>
+ * Copyright (c) 2007 David Leverton <levertond@googlemail.com>
+ *
+ * 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 "vdb_merger.hh"
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+#include <fstream>
+
+using namespace paludis;
+using namespace test;
+
+namespace
+{
+ class VDBMergerNoDisplay :
+ public VDBMerger
+ {
+ private:
+ void display_override(const std::string &) const
+ {
+ }
+
+ public:
+ VDBMergerNoDisplay(const VDBMergerOptions & o) :
+ VDBMerger(o)
+ {
+ }
+
+ bool check()
+ {
+ return Merger::check();
+ }
+
+ void on_enter_dir(bool, const FSEntry)
+ {
+ }
+ };
+
+ class VDBMergerTest :
+ public TestCase
+ {
+ public:
+
+ FSEntry root_dir;
+ std::string target;
+ TestEnvironment env;
+ VDBMergerNoDisplay merger;
+
+ bool repeatable() const
+ {
+ return false;
+ }
+
+ protected:
+
+ VDBMergerTest(const std::string & what) :
+ TestCase("merge '" + what + "' test"),
+ root_dir(FSEntry::cwd() / "vdb_merger_TEST_dir" / what / "root"),
+ target(what),
+ merger(VDBMergerOptions::create()
+ .environment(&env)
+ .image(FSEntry::cwd() / "vdb_merger_TEST_dir" / what / "image")
+ .root(root_dir)
+ .contents_file(FSEntry::cwd() / "vdb_merger_TEST_dir/CONTENTS" / what)
+ .config_protect("/protected_file /protected_dir")
+ .config_protect_mask("/protected_dir/unprotected_file /protected_dir/unprotected_dir")
+ .package_id(tr1::shared_ptr<PackageID>()))
+ {
+ }
+ };
+}
+
+namespace test_cases
+{
+ struct VDBMergerTestConfigProtect : VDBMergerTest
+ {
+ VDBMergerTestConfigProtect() : VDBMergerTest("config_protect") { }
+
+ static std::string file_contents(const FSEntry & f)
+ {
+ if (! f.is_regular_file())
+ return "";
+
+ std::ifstream stream(stringify(f).c_str());
+ if (! stream)
+ return "";
+
+ std::string contents;
+ stream >> contents;
+ return contents;
+ }
+
+ void run()
+ {
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file"), "bar");
+ TEST_CHECK(! (root_dir / "._cfg0000_protected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "unprotected_file"), "bar");
+ TEST_CHECK(! (root_dir / "._cfg0000_unprotected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file_not_really"), "bar");
+ TEST_CHECK(! (root_dir / "._cfg0000_protected_file_not_really").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file"), "bar");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_protected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file"), "bar");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unprotected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file_not_really"), "bar");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unprotected_file_not_really").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_already_needs_update"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_already_needs_update"), "baz");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0001_protected_file_already_needs_update").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unchanged_protected_file"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unchanged_protected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_same_as_existing_update"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_same_as_existing_update"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0001_protected_file_same_as_existing_update").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir/unprotected_file"), "bar");
+ TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir/._cfg0000_unprotected_file").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir_not_really/protected_file"), "bar");
+ TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir_not_really/._cfg0000_protected_file").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir_not_really/unprotected_file"), "bar");
+ TEST_CHECK(! (root_dir / "protected_dir_not_really/._cfg0000_unprotected_file").exists());
+
+ merger.merge();
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "._cfg0000_protected_file"), "foo");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "unprotected_file"), "foo");
+ TEST_CHECK(! (root_dir / "._cfg0000_unprotected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file_not_really"), "foo");
+ TEST_CHECK(! (root_dir / "._cfg0000_protected_file_not_really").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file"), "foo");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unprotected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file_not_really"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_unprotected_file_not_really"), "foo");
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_already_needs_update"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_already_needs_update"), "baz");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0001_protected_file_already_needs_update"), "foo");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unchanged_protected_file"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unchanged_protected_file").exists());
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_same_as_existing_update"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_same_as_existing_update"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir/._cfg0001_protected_file_same_as_existing_update").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir/unprotected_file"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir/._cfg0000_unprotected_file").exists());
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir_not_really/protected_file"), "bar");
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir_not_really/._cfg0000_protected_file"), "foo");
+
+ TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir_not_really/unprotected_file"), "foo");
+ TEST_CHECK(! (root_dir / "protected_dir_not_really/._cfg0000_unprotected_file").exists());
+ }
+ } test_vdb_merger_config_protect;
+}
+
diff --git a/paludis/repositories/e/vdb_merger_TEST_cleanup.sh b/paludis/repositories/e/vdb_merger_TEST_cleanup.sh
new file mode 100755
index 0000000..139f9fa
--- /dev/null
+++ b/paludis/repositories/e/vdb_merger_TEST_cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d vdb_merger_TEST_dir ] ; then
+ rm -fr vdb_merger_TEST_dir
+else
+ true
+fi
+
diff --git a/paludis/repositories/e/vdb_merger_TEST_setup.sh b/paludis/repositories/e/vdb_merger_TEST_setup.sh
new file mode 100755
index 0000000..f110faf
--- /dev/null
+++ b/paludis/repositories/e/vdb_merger_TEST_setup.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir vdb_merger_TEST_dir || exit 2
+cd vdb_merger_TEST_dir || exit 3
+
+mkdir -p config_protect/{image,root,CONTENTS} || exit 4
+
+cd config_protect/image
+
+echo foo >protected_file
+echo foo >unprotected_file
+echo foo >protected_file_not_really
+
+mkdir protected_dir
+echo foo >protected_dir/protected_file
+echo foo >protected_dir/unprotected_file
+echo foo >protected_dir/unprotected_file_not_really
+
+echo foo >protected_dir/protected_file_already_needs_update
+echo foo >protected_dir/unchanged_protected_file
+echo foo >protected_dir/protected_file_same_as_existing_update
+
+mkdir protected_dir/unprotected_dir
+echo foo >protected_dir/unprotected_dir/unprotected_file
+
+mkdir protected_dir/unprotected_dir_not_really
+echo foo >protected_dir/unprotected_dir_not_really/protected_file
+
+mkdir protected_dir_not_really
+echo foo >protected_dir_not_really/unprotected_file
+
+cd ../root
+
+echo bar >protected_file
+echo bar >unprotected_file
+echo bar >protected_file_not_really
+
+mkdir protected_dir
+echo bar >protected_dir/protected_file
+echo bar >protected_dir/unprotected_file
+echo bar >protected_dir/unprotected_file_not_really
+
+echo bar >protected_dir/protected_file_already_needs_update
+echo baz >protected_dir/._cfg0000_protected_file_already_needs_update
+echo foo >protected_dir/unchanged_protected_file
+echo bar >protected_dir/protected_file_same_as_existing_update
+echo foo >protected_dir/._cfg0000_protected_file_same_as_existing_update
+
+mkdir protected_dir/unprotected_dir
+echo bar >protected_dir/unprotected_dir/unprotected_file
+
+mkdir protected_dir/unprotected_dir_not_really
+echo bar >protected_dir/unprotected_dir_not_really/protected_file
+
+mkdir protected_dir_not_really
+echo bar >protected_dir_not_really/unprotected_file
+
+cd ../..
+
diff --git a/paludis/repositories/e/vdb_unmerger.cc b/paludis/repositories/e/vdb_unmerger.cc
index 126a43c..89ff8d1 100644
--- a/paludis/repositories/e/vdb_unmerger.cc
+++ b/paludis/repositories/e/vdb_unmerger.cc
@@ -35,6 +35,7 @@ using namespace paludis;
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/tokeniser.hh>
+#include <paludis/util/strip.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <libwrapiter/libwrapiter_output_iterator.hh>
@@ -170,13 +171,19 @@ VDBUnmerger::config_protected(const FSEntry & f) const
bool result(false);
for (std::list<std::string>::const_iterator c(_imp->config_protect.begin()),
c_end(_imp->config_protect.end()) ; c != c_end && ! result ; ++c)
- if (0 == tidy.compare(0, c->length(), *c))
+ {
+ std::string cc(strip_trailing(*c, "/") + "/");
+ if (tidy == *c || 0 == tidy.compare(0, cc.length(), cc))
result = true;
+ }
if (result)
for (std::list<std::string>::const_iterator c(_imp->config_protect_mask.begin()),
c_end(_imp->config_protect_mask.end()) ; c != c_end && result ; ++c)
- if (0 == tidy.compare(0, c->length(), *c))
+ {
+ std::string cc(strip_trailing(*c, "/") + "/");
+ if (tidy == *c || 0 == tidy.compare(0, cc.length(), cc))
result = false;
+ }
return result;
}
diff --git a/paludis/repositories/e/vdb_unmerger_TEST.cc b/paludis/repositories/e/vdb_unmerger_TEST.cc
index 83815d2..e52f9c9 100644
--- a/paludis/repositories/e/vdb_unmerger_TEST.cc
+++ b/paludis/repositories/e/vdb_unmerger_TEST.cc
@@ -70,8 +70,8 @@ namespace
.environment(&env)
.root(root_dir)
.contents_file("vdb_unmerger_TEST_dir/CONTENTS/" + what)
- .config_protect("")
- .config_protect_mask("")
+ .config_protect("/protected_file /protected_dir")
+ .config_protect_mask("/protected_dir/unprotected_file /protected_dir/unprotected_dir")
.package_id(tr1::shared_ptr<PackageID>()))
{
}
@@ -347,5 +347,43 @@ namespace test_cases
TEST_CHECK((root_dir / target).is_regular_file());
}
} test_vdb_unmerger_fifo_bad_type;
+
+ struct VDBUnmergerTestConfigProtect : VDBUnmergerTest
+ {
+ VDBUnmergerTestConfigProtect() : VDBUnmergerTest("config_protect") { }
+
+ void run()
+ {
+ TEST_CHECK((root_dir / "protected_file").is_regular_file());
+ TEST_CHECK((root_dir / "unprotected_file").is_regular_file());
+ TEST_CHECK((root_dir / "protected_file_not_really").is_regular_file());
+
+ TEST_CHECK((root_dir / "protected_dir/protected_file").is_regular_file());
+ TEST_CHECK((root_dir / "protected_dir/unprotected_file").is_regular_file());
+ TEST_CHECK((root_dir / "protected_dir/unprotected_file_not_really").is_regular_file());
+
+ TEST_CHECK((root_dir / "protected_dir/unprotected_dir/unprotected_file").is_regular_file());
+
+ TEST_CHECK((root_dir / "protected_dir/unprotected_dir_not_really/protected_file").is_regular_file());
+
+ TEST_CHECK((root_dir / "protected_dir_not_really/unprotected_file").is_regular_file());
+
+ unmerger.unmerge();
+
+ TEST_CHECK((root_dir / "protected_file").exists());
+ TEST_CHECK(! (root_dir / "unprotected_file").exists());
+ TEST_CHECK(! (root_dir / "protected_file_not_really").exists());
+
+ TEST_CHECK((root_dir / "protected_dir/protected_file").exists());
+ TEST_CHECK(! (root_dir / "protected_dir/unprotected_file").exists());
+ TEST_CHECK((root_dir / "protected_dir/unprotected_file_not_really").exists());
+
+ TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir/unprotected_file").exists());
+
+ TEST_CHECK((root_dir / "protected_dir/unprotected_dir_not_really/protected_file").exists());
+
+ TEST_CHECK(! (root_dir / "protected_dir_not_really/unprotected_file").exists());
+ }
+ } test_vdb_unmerger_config_protect;
}
diff --git a/paludis/repositories/e/vdb_unmerger_TEST_setup.sh b/paludis/repositories/e/vdb_unmerger_TEST_setup.sh
index 2930a48..3ef41e0 100755
--- a/paludis/repositories/e/vdb_unmerger_TEST_setup.sh
+++ b/paludis/repositories/e/vdb_unmerger_TEST_setup.sh
@@ -76,3 +76,25 @@ echo "fif /fifo_ with spaces" > "../CONTENTS/fifo_ with spaces"
> fifo_bad_type
echo "fif /fifo_bad_type" > "../CONTENTS/fifo_bad_type"
+touch protected_file
+touch unprotected_file
+touch protected_file_not_really
+
+mkdir protected_dir
+touch protected_dir/protected_file
+touch protected_dir/unprotected_file
+touch protected_dir/unprotected_file_not_really
+
+mkdir protected_dir/unprotected_dir
+touch protected_dir/unprotected_dir/unprotected_file
+
+mkdir protected_dir/unprotected_dir_not_really
+touch protected_dir/unprotected_dir_not_really/protected_file
+
+mkdir protected_dir_not_really
+touch protected_dir_not_really/unprotected_file
+
+find . -name '*protected*' -type f -print | while read file; do
+ echo obj "${file#.}" "$(md5sum "${file}" | cut -f1 -d' ')" "$(${PALUDIS_EBUILD_DIR}/utils/getmtime "${file}")"
+done >../CONTENTS/config_protect
+