From 80c9045324e3148495f9c45b5ff80b5241d7bc8f Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Fri, 30 Nov 2012 17:15:58 +0000 Subject: Fix symlink directory check and tidy up copy_symlink() Fix the check on symlinks pointing to a directory (it needs to use an absolute path) and simplify the function and variable names. --- sos/plugins/__init__.py | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 63adc94c..cf0aa97d 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -198,42 +198,39 @@ class Plugin(object): def copy_symlink(self, srcpath, sub=None): # the target stored in the original symlink linkdest = os.readlink(srcpath) - self.soslog.debug("copying link %s pointing to %s with sub=%s" - % (srcpath, linkdest, sub)) - - if os.path.isdir(linkdest): - self.soslog.debug("link %s is a directory, skipping..." - % linkdest) - return - + # absolute path to the link target + absdest = os.path.normpath(os.path.join( + os.path.dirname(srcpath), linkdest)) # adjust the target used inside the report to always be relative if os.path.isabs(linkdest): - adjdest = os.path.relpath(linkdest, + reldest = os.path.relpath(linkdest, os.path.dirname(srcpath)) self.soslog.debug("made link target %s relative as %s" - % (linkdest, adjdest)) + % (linkdest, reldest)) else: - adjdest = linkdest + reldest = linkdest + + self.soslog.debug( + "copying link %s pointing to %s with sub=%s, isdir=%s" + % (srcpath, linkdest, sub, os.path.isdir(absdest))) + + if os.path.isdir(absdest): + self.soslog.debug("link %s is a directory, skipping..." + % linkdest) + return if sub: old, new = sub - adjdest = srcpath.replace(old, new) + reldest = srcpath.replace(old, new) - self.archive.add_link(adjdest,srcpath) + # use the relative target path in the tarball + self.archive.add_link(reldest,srcpath) # copy the symlink target translating relative targets # to absolute paths to pass to doCopyFileOrDir. - self.soslog.debug("copying target %s for link %s" - % (linkdest, srcpath)) - - if(os.path.isabs(linkdest)): - self.doCopyFileOrDir(linkdest) - else: - absdest = os.path.normpath(os.path.join( - os.path.dirname(srcpath), linkdest)) - self.soslog.debug("normalized link target %s as %s" - %(linkdest, absdest)) - self.doCopyFileOrDir(absdest) + self.soslog.debug("normalized link target %s as %s" + %(linkdest, absdest)) + self.doCopyFileOrDir(absdest) self.copiedFiles.append({ 'srcpath':srcpath, -- cgit