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

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