aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-11-30 17:15:58 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-11-30 17:15:58 +0000
commit80c9045324e3148495f9c45b5ff80b5241d7bc8f (patch)
treeb4b3edc3d3e3954561040e4ce753446efe573b1c
parentcc5313646f61a5272073bfac012e7bf6c1367311 (diff)
downloadsos-80c9045324e3148495f9c45b5ff80b5241d7bc8f.tar.gz
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.
-rw-r--r--sos/plugins/__init__.py45
1 files 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,