commit:     ae355c93fd2760970c92cd4e9d2daa68f216adfa
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 25 00:59:39 2014 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Oct 27 09:39:26 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ae355c93

CONFIG_PROTECT: handle non-existent files

This fixes the ConfigProtect class, etc-update, and dispatch-conf to
account for non-existent files (rather than directories) that are
listed directly in CONFIG_PROTECT. It has been valid to list files
directly in CONFIG_PROTECT since bug #14321. However, the support for
non-existent files added for bug #523684 did not include support for
non-existent files listed directly in CONFIG_PROTECT.

Fixes: 5f7b4865ecaf ("dblink.mergeme: implement bug #523684")
X-Gentoo-Bug: 523684
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=523684
Acked-by: Alexander Berntsen <bernalex <AT> gentoo.org>

---
 bin/dispatch-conf            | 10 ++++++----
 bin/etc-update               |  5 ++++-
 pym/portage/util/__init__.py |  6 ++++--
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index fb0a8af..6d2ae94 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -116,13 +116,15 @@ class dispatch:
         for path in config_paths:
             path = portage.normalize_path(
                  os.path.join(config_root, path.lstrip(os.sep)))
-            try:
-                mymode = os.stat(path).st_mode
-            except OSError:
+
+            # Protect files that don't exist (bug #523684). If the
+            # parent directory doesn't exist, we can safely skip it.
+            if not os.path.isdir(os.path.dirname(path)):
                 continue
+
             basename = "*"
             find_opts = "-name '.*' -type d -prune -o"
-            if not stat.S_ISDIR(mymode):
+            if not os.path.isdir(path):
                 path, basename = os.path.split(path)
                 find_opts = "-maxdepth 1"
 

diff --git a/bin/etc-update b/bin/etc-update
index 1a99231..7ac6f0b 100755
--- a/bin/etc-update
+++ b/bin/etc-update
@@ -74,7 +74,10 @@ scan() {
                path="${EROOT%/}${path}"
 
                if [[ ! -d ${path} ]] ; then
-                       [[ ! -f ${path} ]] && continue
+                       # Protect files that don't exist (bug #523684). If the
+                       # parent directory doesn't exist, we can safely skip it.
+                       path=${path%/}
+                       [[ -d ${path%/*} ]] || continue
                        local my_basename="${path##*/}"
                        path="${path%/*}"
                        find_opts=( -maxdepth 1 -name 
"._cfg????_${my_basename}" )

diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 4105c19..fe79942 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -1572,12 +1572,14 @@ class ConfigProtect(object):
                for x in self.protect_list:
                        ppath = normalize_path(
                                os.path.join(self.myroot, 
x.lstrip(os.path.sep)))
+                       # Protect files that don't exist (bug #523684). If the
+                       # parent directory doesn't exist, we can safely skip it.
+                       if os.path.isdir(os.path.dirname(ppath)):
+                               self.protect.append(ppath)
                        try:
                                if stat.S_ISDIR(os.stat(ppath).st_mode):
                                        self._dirs.add(ppath)
-                               self.protect.append(ppath)
                        except OSError:
-                               # If it doesn't exist, there's no need to 
protect it.
                                pass
 
                self.protectmask = []

Reply via email to