aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2022-03-16 17:52:51 +0100
committerJake Hunsaker <jhunsake@redhat.com>2022-03-25 12:54:16 -0400
commit938fefdd06817781f9d9a76915648be61117c84b (patch)
tree7ae83b71fdca7527e5a09ee588795e145ee60264
parentdeea7e14ee3915e624ec85b63eebea5db2c66a06 (diff)
downloadsos-938fefdd06817781f9d9a76915648be61117c84b.tar.gz
[archive] Dont obfuscate tmpdir path of final archive
When renaming the sosreport directory (inside the /var/tmp/sos.* working directory), apply cleaner obfuscation to the sosreport directory but not to the working directory path. This is achieved by proper setting of FileCacheArchive._name that should have the relative directory name only without the leading path. Resolves: #2887 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r--sos/archive.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/sos/archive.py b/sos/archive.py
index e92d5d60..8a4e23aa 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -135,6 +135,9 @@ class FileCacheArchive(Archive):
def __init__(self, name, tmpdir, policy, threads, enc_opts, sysroot,
manifest=None):
self._name = name
+ # truncate the name just relative to the tmpdir in case of full path
+ if os.path.commonprefix([self._name, tmpdir]) == tmpdir:
+ self._name = os.path.relpath(name, tmpdir)
self._tmp_dir = tmpdir
self._policy = policy
self._threads = threads
@@ -652,7 +655,7 @@ class TarFileArchive(FileCacheArchive):
# this can be used to set permissions if using the
# tarfile.add() interface to add directory trees.
def copy_permissions_filter(self, tarinfo):
- orig_path = tarinfo.name[len(os.path.split(self._name)[-1]):]
+ orig_path = tarinfo.name[len(os.path.split(self._archive_root)[-1]):]
if not orig_path:
orig_path = self._archive_root
try:
@@ -674,7 +677,7 @@ class TarFileArchive(FileCacheArchive):
return None
def name(self):
- return "%s.%s" % (self._name, self._suffix)
+ return "%s.%s" % (self._archive_root, self._suffix)
def name_max(self):
# GNU Tar format supports unlimited file name length. Just return
@@ -696,7 +699,7 @@ class TarFileArchive(FileCacheArchive):
**kwargs)
# we need to pass the absolute path to the archive root but we
# want the names used in the archive to be relative.
- tar.add(self._archive_root, arcname=os.path.split(self._name)[1],
+ tar.add(self._archive_root, arcname=self._name,
filter=self.copy_permissions_filter)
tar.close()
self._suffix += ".%s" % _comp_mode