Blame SOURCES/sos-bz1728214-symlink-dirs-in-container.patch

5baea9
From 3006f467e6e3908193d28d76bddcc372c4b98875 Mon Sep 17 00:00:00 2001
5baea9
From: Pavel Moravec <pmoravec@redhat.com>
5baea9
Date: Tue, 9 Jul 2019 13:35:28 +0200
5baea9
Subject: [PATCH] [archive] Handle checking container sysroot in
5baea9
 _make_leading_paths
5baea9
5baea9
Previously, in _make_leading_paths(), checking host file paths did not
5baea9
account for non / sysroots, for situations where sos is run in a
5baea9
container and the host's / is actually mounted under /host for example.
5baea9
This would lead to copy errors when trying to copy symlinks.
5baea9
5baea9
This method now will use sysroot if one is set, thus avoiding copy
5baea9
errors.
5baea9
5baea9
Resolves: #1705
5baea9
5baea9
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
5baea9
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
5baea9
---
5baea9
 sos/archive.py         | 17 +++++++++++++----
5baea9
 sos/sosreport.py       |  4 ++--
5baea9
 tests/archive_tests.py |  3 ++-
5baea9
 3 files changed, 17 insertions(+), 7 deletions(-)
5baea9
5baea9
diff --git a/sos/archive.py b/sos/archive.py
5baea9
index dcd6908d1..7ab36ce45 100644
5baea9
--- a/sos/archive.py
5baea9
+++ b/sos/archive.py
5baea9
@@ -139,12 +139,13 @@ class FileCacheArchive(Archive):
5baea9
     _archive_root = ""
5baea9
     _archive_name = ""
5baea9
 
5baea9
-    def __init__(self, name, tmpdir, policy, threads, enc_opts):
5baea9
+    def __init__(self, name, tmpdir, policy, threads, enc_opts, sysroot):
5baea9
         self._name = name
5baea9
         self._tmp_dir = tmpdir
5baea9
         self._policy = policy
5baea9
         self._threads = threads
5baea9
         self.enc_opts = enc_opts
5baea9
+        self.sysroot = sysroot
5baea9
         self._archive_root = os.path.join(tmpdir, name)
5baea9
         with self._path_lock:
5baea9
             os.makedirs(self._archive_root, 0o700)
5baea9
@@ -156,6 +157,13 @@ def dest_path(self, name):
5baea9
             name = name.lstrip(os.sep)
5baea9
         return (os.path.join(self._archive_root, name))
5baea9
 
5baea9
+    def join_sysroot(self, path):
5baea9
+        if path.startswith(self.sysroot):
5baea9
+            return path
5baea9
+        if path[0] == os.sep:
5baea9
+            path = path[1:]
5baea9
+        return os.path.join(self.sysroot, path)
5baea9
+
5baea9
     def _make_leading_paths(self, src, mode=0o700):
5baea9
         """Create leading path components
5baea9
 
5baea9
@@ -191,7 +199,8 @@ def in_archive(path):
5baea9
             src_dir = src
5baea9
         else:
5baea9
             # Host file path
5baea9
-            src_dir = src if os.path.isdir(src) else os.path.split(src)[0]
5baea9
+            src_dir = (src if os.path.isdir(self.join_sysroot(src))
5baea9
+                       else os.path.split(src)[0])
5baea9
 
5baea9
         # Build a list of path components in root-to-leaf order.
5baea9
         path = src_dir
5baea9
@@ -675,9 +684,9 @@ class TarFileArchive(FileCacheArchive):
5baea9
     method = None
5baea9
     _with_selinux_context = False
5baea9
 
5baea9
-    def __init__(self, name, tmpdir, policy, threads, enc_opts):
5baea9
+    def __init__(self, name, tmpdir, policy, threads, enc_opts, sysroot):
5baea9
         super(TarFileArchive, self).__init__(name, tmpdir, policy, threads,
5baea9
-                                             enc_opts)
5baea9
+                                             enc_opts, sysroot)
5baea9
         self._suffix = "tar"
5baea9
         self._archive_name = os.path.join(tmpdir, self.name())
5baea9
 
5baea9
diff --git a/sos/sosreport.py b/sos/sosreport.py
5baea9
index cd61b6257..04cb86155 100644
5baea9
--- a/sos/sosreport.py
5baea9
+++ b/sos/sosreport.py
5baea9
@@ -379,12 +379,12 @@ def _set_archive(self):
5baea9
             auto_archive = self.policy.get_preferred_archive()
5baea9
             self.archive = auto_archive(archive_name, self.tmpdir,
5baea9
                                         self.policy, self.opts.threads,
5baea9
-                                        enc_opts)
5baea9
+                                        enc_opts, self.sysroot)
5baea9
 
5baea9
         else:
5baea9
             self.archive = TarFileArchive(archive_name, self.tmpdir,
5baea9
                                           self.policy, self.opts.threads,
5baea9
-                                          enc_opts)
5baea9
+                                          enc_opts, self.sysroot)
5baea9
 
5baea9
         self.archive.set_debug(True if self.opts.debug else False)
5baea9
 
5baea9
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
5baea9
index e5b329b5f..350220b92 100644
5baea9
--- a/tests/archive_tests.py
5baea9
+++ b/tests/archive_tests.py
5baea9
@@ -20,7 +20,7 @@ class TarFileArchiveTest(unittest.TestCase):
5baea9
     def setUp(self):
5baea9
         self.tmpdir = tempfile.mkdtemp()
5baea9
         enc = {'encrypt': False}
5baea9
-        self.tf = TarFileArchive('test', self.tmpdir, Policy(), 1, enc)
5baea9
+        self.tf = TarFileArchive('test', self.tmpdir, Policy(), 1, enc, '/')
5baea9
 
5baea9
     def tearDown(self):
5baea9
         shutil.rmtree(self.tmpdir)
5baea9
@@ -113,6 +113,7 @@ def test_make_link(self):
5baea9
     def test_compress(self):
5baea9
         self.tf.finalize("auto")
5baea9
 
5baea9
+
5baea9
 if __name__ == "__main__":
5baea9
     unittest.main()
5baea9