diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2018-09-12 12:02:33 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-09-12 12:04:57 +0100 |
commit | c065be9715dc845b6411a9a0b2d6171bbeb1c390 (patch) | |
tree | 5dd05357e4d34388eef343931671fd7d8f032d1d | |
parent | 2e3e1479df19aca58d8bd9f80ef3d6e7a9641211 (diff) | |
download | sos-c065be9715dc845b6411a9a0b2d6171bbeb1c390.tar.gz |
[plugin] canonicalize link target path in Plugin._copy_symlink()
Since we may be dealing with paths that contain intermediate
symlinked directories, it is necessary to canonicalize the path
for the link target in order to eliminate additional levels of
symbolic links, and to calculate the correct relative path to
use within the archive.
Related: #1404
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index ac2c0bc8..7d011a02 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -353,7 +353,10 @@ class Plugin(object): absdest = os.path.normpath(dest) # adjust the target used inside the report to always be relative if os.path.isabs(linkdest): - reldest = os.path.relpath(linkdest, os.path.dirname(srcpath)) + # Canonicalize the link target path to avoid additional levels + # of symbolic links (that would affect the path nesting level). + realdir = os.path.realpath(os.path.dirname(srcpath)) + reldest = os.path.relpath(linkdest, start=realdir) # trim leading /sysroot if self.use_sysroot(): reldest = reldest[len(os.sep + os.pardir):] |