From bc43348f42fa4beba2d60a1dfe9c3c6cfde78efa Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Sun, 9 Nov 2014 09:00:19 -0500 Subject: [PATCH] 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. --- dotbot/executor/linker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dotbot/executor/linker.py b/dotbot/executor/linker.py index c3d6dc5..8f38c95 100644 --- a/dotbot/executor/linker.py +++ b/dotbot/executor/linker.py @@ -27,7 +27,7 @@ class Linker(Executor): if create: success &= self._create(destination) if force: - success &= self._delete(destination) + success &= self._delete(path, destination) else: path = source success &= self._link(path, destination) @@ -71,9 +71,11 @@ class Linker(Executor): self._log.lowinfo('Creating directory %s' % parent) return success - def _delete(self, path): + def _delete(self, source, path): 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) try: if os.path.isdir(fullpath):