diff options
-rw-r--r-- | sos/archive.py | 6 | ||||
-rw-r--r-- | sos/report/plugins/__init__.py | 14 | ||||
-rw-r--r-- | tests/unittests/plugin_tests.py | 2 |
3 files changed, 14 insertions, 8 deletions
diff --git a/sos/archive.py b/sos/archive.py index 11d8b343..d76b7aa0 100644 --- a/sos/archive.py +++ b/sos/archive.py @@ -73,7 +73,7 @@ class Archive(object): # this is our contract to clients of the Archive class hierarchy. # All sub-classes need to implement these methods (or inherit concrete # implementations from a parent class. - def add_file(self, src, dest=None): + def add_file(self, src, dest=None, force=False): raise NotImplementedError def add_string(self, content, dest, mode='w'): @@ -344,12 +344,12 @@ class FileCacheArchive(Archive): self.log_debug("caught '%s' setting attributes of '%s'" % (e, dest)) - def add_file(self, src, dest=None): + def add_file(self, src, dest=None, force=False): with self._path_lock: if not dest: dest = src - dest = self.check_path(dest, P_FILE) + dest = self.check_path(dest, P_FILE, force=force) if not dest: return diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py index 9426b9bd..80d53e2f 100644 --- a/sos/report/plugins/__init__.py +++ b/sos/report/plugins/__init__.py @@ -1287,7 +1287,7 @@ class Plugin(): result, replacements = re.subn(regexp, subst, content, flags=re.IGNORECASE) if replacements: - self.archive.add_string(result, srcpath) + self.archive.add_string(result, self.strip_sysroot(srcpath)) else: replacements = 0 except (OSError, IOError) as e: @@ -1380,7 +1380,11 @@ class Plugin(): # skip recursive copying of symlink pointing to itself. if (absdest != srcpath): - self._do_copy_path(absdest) + # this allows for ensuring we collect the host's file when copying + # a symlink from within a container that is within the set sysroot + force = (absdest.startswith(self.sysroot) and + self.policy._in_container) + self._do_copy_path(absdest, force=force) else: self._log_debug("link '%s' points to itself, skipping target..." % linkdest) @@ -1442,7 +1446,7 @@ class Plugin(): self.archive.add_node(path, mode, os.makedev(dev_maj, dev_min)) # Methods for copying files and shelling out - def _do_copy_path(self, srcpath, dest=None): + def _do_copy_path(self, srcpath, dest=None, force=False): """Copy file or directory to the destination tree. If a directory, then everything below it is recursively copied. A list of copied files are saved for use later in preparing a report. @@ -1494,7 +1498,7 @@ class Plugin(): # FIXME: reflect permissions in archive self.archive.add_string("", dest) else: - self.archive.add_file(srcpath, dest) + self.archive.add_file(srcpath, dest, force=force) self.copied_files.append({ 'srcpath': srcpath, @@ -1502,6 +1506,8 @@ class Plugin(): 'symlink': "no" }) + return + def add_forbidden_path(self, forbidden): """Specify a path, or list of paths, to not copy, even if it's part of an ``add_copy_spec()`` call diff --git a/tests/unittests/plugin_tests.py b/tests/unittests/plugin_tests.py index 8170a1dd..49784514 100644 --- a/tests/unittests/plugin_tests.py +++ b/tests/unittests/plugin_tests.py @@ -45,7 +45,7 @@ class MockArchive(TarFileArchive): def name(self): return "mock.archive" - def add_file(self, src, dest=None): + def add_file(self, src, dest=None, force=False): if not dest: dest = src self.m[src] = dest |