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.
This commit is contained in:
parent
4feb4845e8
commit
fc2fa2d5ef
1 changed files with 11 additions and 3 deletions
|
@ -55,10 +55,11 @@ class Linker(Executor):
|
||||||
'''
|
'''
|
||||||
success = False
|
success = False
|
||||||
source = os.path.join(self._base_directory, source)
|
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' %
|
self._log.warning('Invalid link %s -> %s' %
|
||||||
(link_name, self._link_destination(link_name)))
|
(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))
|
self._log.lowinfo('Creating link %s -> %s' % (link_name, source))
|
||||||
os.symlink(source, os.path.expanduser(link_name))
|
os.symlink(source, os.path.expanduser(link_name))
|
||||||
success = True
|
success = True
|
||||||
|
@ -66,9 +67,16 @@ class Linker(Executor):
|
||||||
self._log.warning(
|
self._log.warning(
|
||||||
'%s already exists but is a regular file or directory' %
|
'%s already exists but is a regular file or directory' %
|
||||||
link_name)
|
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' %
|
self._log.warning('Incorrect link %s -> %s' %
|
||||||
(link_name, self._link_destination(link_name)))
|
(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:
|
else:
|
||||||
self._log.lowinfo('Link exists %s -> %s' % (link_name, source))
|
self._log.lowinfo('Link exists %s -> %s' % (link_name, source))
|
||||||
success = True
|
success = True
|
||||||
|
|
Loading…
Reference in a new issue