Skip to content

Commit

Permalink
Fix symlink directory check and tidy up copy_symlink()
Browse files Browse the repository at this point in the history
Fix the check on symlinks pointing to a directory (it needs to use
an absolute path) and simplify the function and variable names.
  • Loading branch information
bmr-cymru committed Nov 30, 2012
1 parent cc53136 commit 80c9045
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions sos/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,42 +198,39 @@ def _path_in_path_list(self, path, path_list):
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,
Expand Down

0 comments on commit 80c9045

Please sign in to comment.