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