From a97096ef962f64d98d70e92ec21f9edb4842985a Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Tue, 15 Jul 2014 18:25:53 -0700 Subject: [PATCH] Make Linker check for existence of targets Linker now reports an error when links are configured to point to nonexistent targets. This fixes the old behavior where Linker silently created invalid links. --- dotbot/executor/linker.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dotbot/executor/linker.py b/dotbot/executor/linker.py index 662683f..0e25838 100644 --- a/dotbot/executor/linker.py +++ b/dotbot/executor/linker.py @@ -55,10 +55,11 @@ class Linker(Executor): ''' success = False source = os.path.join(self._base_directory, source) - if not self._exists(link_name) and self._is_link(link_name): + if (not self._exists(link_name) and self._is_link(link_name) and + self._link_destination(link_name) != source): self._log.warning('Invalid link %s -> %s' % (link_name, self._link_destination(link_name))) - elif not self._exists(link_name): + elif not self._exists(link_name) and self._exists(source): self._log.lowinfo('Creating link %s -> %s' % (link_name, source)) os.symlink(source, os.path.expanduser(link_name)) success = True @@ -66,9 +67,16 @@ class Linker(Executor): self._log.warning( '%s already exists but is a regular file or directory' % link_name) - elif self._link_destination(link_name) != source: + elif self._is_link(link_name) and self._link_destination(link_name) != source: self._log.warning('Incorrect link %s -> %s' % (link_name, self._link_destination(link_name))) + elif not self._exists(source): + if self._is_link(link_name): + self._log.warning('Nonexistant target %s -> %s' % + (link_name, source)) + else: + self._log.warning('Nonexistant target for %s : %s' % + (link_name, source)) else: self._log.lowinfo('Link exists %s -> %s' % (link_name, source)) success = True