1
0
Fork 0
mirror of synced 2024-11-22 16:25:34 -05:00

Fix bug with forced links not working in all cases

This commit fixes a bug where forced links did not work on certain types
of bad links. Until this fix, forced links only worked if the original
was a real file or directory. This commit fixes this, so that the forced
link option also works when the original is a broken or incorrect
symbolic link.
This commit is contained in:
Anish Athalye 2014-11-09 09:00:19 -05:00
parent 33d602bb93
commit bc43348f42

View file

@ -27,7 +27,7 @@ class Linker(Executor):
if create: if create:
success &= self._create(destination) success &= self._create(destination)
if force: if force:
success &= self._delete(destination) success &= self._delete(path, destination)
else: else:
path = source path = source
success &= self._link(path, destination) success &= self._link(path, destination)
@ -71,9 +71,11 @@ class Linker(Executor):
self._log.lowinfo('Creating directory %s' % parent) self._log.lowinfo('Creating directory %s' % parent)
return success return success
def _delete(self, path): def _delete(self, source, path):
success = True success = True
if self._exists(path) and not self._is_link(path): source = os.path.join(self._base_directory, source)
if ((self._is_link(path) and self._link_destination(path) != source) or
(self._exists(path) and not self._is_link(path))):
fullpath = os.path.expanduser(path) fullpath = os.path.expanduser(path)
try: try:
if os.path.isdir(fullpath): if os.path.isdir(fullpath):