check for broken symlinks when using --force

This commit is contained in:
npetrov 2010-06-09 17:27:09 +02:00 committed by Jesse Keating
parent c6f01468c3
commit 6703e700ba
2 changed files with 10 additions and 1 deletions

View File

@ -925,7 +925,11 @@ class Pungi(pypungi.PungiBase):
for regex in fileres:
if regex.match(filename) and not os.path.exists(os.path.join(self.topdir, filename)):
self.logger.info("Linking release note file %s" % filename)
pypungi.util._link(os.path.join(dirpath, filename), os.path.join(self.topdir, filename), self.logger)
pypungi.util._link(os.path.join(dirpath, filename),
os.path.join(self.topdir, filename),
self.logger,
force=self.config.getboolean('pungi',
'force'))
self.common_files.append(filename)
# Walk the tree for our dirs

View File

@ -41,6 +41,11 @@ def _link(local, target, logger, force=False):
if os.path.exists(target) and force:
os.remove(target)
#check for broken links
if force and os.path.islink(target):
if not os.path.exists(os.readlink(target)):
os.remove(target)
try:
os.link(local, target)
except OSError, e: