aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-28 20:25:09 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-28 20:25:09 +0000
commit3f222cab4150e1b7aea7e528525b63427ff62871 (patch)
tree22e48c29c24457c5cc4fb6b0b860b573a34d8d0a
parenta7c0c9d36e1989a52b7e4bef7827c1c03a1a9ad2 (diff)
downloadpaludis-3f222cab4150e1b7aea7e528525b63427ff62871.tar.gz
paludis-3f222cab4150e1b7aea7e528525b63427ff62871.tar.xz
Re-enable config protect support
-rw-r--r--ebuild/builtin_unmerge.bash3
-rw-r--r--ebuild/utils/unmerge.cc39
2 files changed, 42 insertions, 0 deletions
diff --git a/ebuild/builtin_unmerge.bash b/ebuild/builtin_unmerge.bash
index d616c3d..ca9e6b2 100644
--- a/ebuild/builtin_unmerge.bash
+++ b/ebuild/builtin_unmerge.bash
@@ -50,6 +50,9 @@ builtin_unmerge()
CONFIG_PROTECT_MASK=${PALUDIS_EBUILD_OVERRIDE_CONFIG_PROTECT_MASK}
fi
+ export CONFIG_PROTECT="${CONFIG_PROTECT}"
+ export CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK}"
+
${PALUDIS_EBUILD_MODULES_DIR}/utils/unmerge "${ROOT}/" "${dbdir}/CONTENTS" \
|| die "unmerge failed"
diff --git a/ebuild/utils/unmerge.cc b/ebuild/utils/unmerge.cc
index 2b74347..118f376 100644
--- a/ebuild/utils/unmerge.cc
+++ b/ebuild/utils/unmerge.cc
@@ -38,6 +38,7 @@
#include <cstdlib>
#include <errno.h>
#include <fcntl.h>
+#include <fnmatch.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -61,6 +62,42 @@ namespace
};
};
+ std::vector<std::string>
+ get_config_var(const std::string & var)
+ {
+ std::vector<std::string> result;
+ WhitespaceTokeniser::get_instance()->tokenise(getenv_with_default(var, ""),
+ std::back_inserter(result));
+ return result;
+ }
+
+ bool
+ is_config_protected(const FSEntry & root, const FSEntry & file)
+ {
+ static std::vector<std::string> cfg_pro(get_config_var("CONFIG_PROTECT")),
+ cfg_pro_mask(get_config_var("CONFIG_PROTECT_MASK"));
+
+ std::string file_str(stringify(file)), root_str(stringify(root));
+ if (0 != file_str.compare(0, root_str.length(), root_str))
+ throw Failure("is_config_protected confused: '" + root_str + "' '" + file_str + "'");
+ file_str.erase(0, root_str.length());
+ if (file_str.empty())
+ file_str = "/";
+
+ bool result(false);
+ for (std::vector<std::string>::const_iterator c(cfg_pro.begin()),
+ c_end(cfg_pro.end()) ; c != c_end && ! result ; ++c)
+ if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
+ result = true;
+
+ for (std::vector<std::string>::const_iterator c(cfg_pro_mask.begin()),
+ c_end(cfg_pro_mask.end()) ; c != c_end && result ; ++c)
+ if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
+ result = false;
+
+ return result;
+ }
+
template <typename Iter_>
void unmerge_contents(const FSEntry & root, const Iter_ begin, const Iter_ end)
{
@@ -97,6 +134,8 @@ namespace
}
else if (strip_trailing(md5, "\n") != tokens.at(2))
cout << "--- [!md5 ] " << tokens.at(1) << endl;
+ else if (is_config_protected(root, root / tokens.at(1)))
+ cout << "--- [cfgpr] " << tokens.at(1) << endl;
else
{
cout << "<<< " << tokens.at(1) << endl;