Blame SOURCES/sos-bz1474976-regexp-sub.patch

b72d26
From b96bdab03f06408e162b1733b20e8ba9fbf8e012 Mon Sep 17 00:00:00 2001
b72d26
From: "Bryn M. Reeves" <bmr@redhat.com>
b72d26
Date: Mon, 2 Jul 2018 12:01:04 +0100
b72d26
Subject: [PATCH] [archive] fix add_string()/do_*_sub() regression
b72d26
b72d26
A change in the handling of add_string() operations in the archive
b72d26
class causes the Plugin string substitution methods to fail (since
b72d26
the archive was enforcing a check that the path did not already
b72d26
exist - for substitutions this is always the case).
b72d26
b72d26
Maintain the check for content that is being copied into the
b72d26
archive anew, but make the add_string() method override this and
b72d26
disable the existence checks.
b72d26
b72d26
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
b72d26
---
b72d26
 sos/archive.py         | 14 ++++++++++----
b72d26
 tests/archive_tests.py | 12 ++----------
b72d26
 2 files changed, 12 insertions(+), 14 deletions(-)
b72d26
b72d26
diff --git a/sos/archive.py b/sos/archive.py
b72d26
index d53baf41..e153c09a 100644
b72d26
--- a/sos/archive.py
b72d26
+++ b/sos/archive.py
b72d26
@@ -158,7 +158,7 @@ class FileCacheArchive(Archive):
b72d26
             name = name.lstrip(os.sep)
b72d26
         return (os.path.join(self._archive_root, name))
b72d26
 
b72d26
-    def _check_path(self, src, path_type, dest=None):
b72d26
+    def _check_path(self, src, path_type, dest=None, force=False):
b72d26
         """Check a new destination path in the archive.
b72d26
 
b72d26
             Since it is possible for multiple plugins to collect the same
b72d26
@@ -185,6 +185,7 @@ class FileCacheArchive(Archive):
b72d26
             :param src: the source path to be copied to the archive
b72d26
             :param path_type: the type of object to be copied
b72d26
             :param dest: an optional destination path
b72d26
+            :param force: force file creation even if the path exists
b72d26
             :returns: An absolute destination path if the path should be
b72d26
                       copied now or `None` otherwise
b72d26
         """
b72d26
@@ -208,6 +209,9 @@ class FileCacheArchive(Archive):
b72d26
                 stat.ISSOCK(mode)
b72d26
             ])
b72d26
 
b72d26
+        if force:
b72d26
+            return dest
b72d26
+
b72d26
         # Check destination path presence and type
b72d26
         if os.path.exists(dest):
b72d26
             # Use lstat: we care about the current object, not the referent.
b72d26
@@ -274,9 +278,11 @@ class FileCacheArchive(Archive):
b72d26
         with self._path_lock:
b72d26
             src = dest
b72d26
 
b72d26
-            dest = self._check_path(dest, P_FILE)
b72d26
-            if not dest:
b72d26
-                return
b72d26
+            # add_string() is a special case: it must always take precedence
b72d26
+            # over any exixting content in the archive, since it is used by
b72d26
+            # the Plugin postprocessing hooks to perform regex substitution
b72d26
+            # on file content.
b72d26
+            dest = self._check_path(dest, P_FILE, force=True)
b72d26
 
b72d26
             f = codecs.open(dest, 'w', encoding='utf-8')
b72d26
             if isinstance(content, bytes):