1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 07:23:48 +00:00

properly handle dead symlink

This commit is contained in:
deadc0de6
2018-06-17 11:07:52 +02:00
parent cd2e4e6299
commit e04564e06b
3 changed files with 8 additions and 8 deletions

View File

@@ -208,7 +208,7 @@ def compare(opts, conf, tmp, focus=None):
def update(opts, conf, path):
"""update the dotfile from path"""
if not os.path.exists(path):
if not os.path.lexists(path):
LOG.err('\"{}\" does not exist!'.format(path))
return False
home = os.path.expanduser(TILD)
@@ -228,7 +228,7 @@ def update(opts, conf, path):
LOG.err('multiple dotfiles found: {}'.format(found))
return False
dotfile = subs[0]
src = os.path.join(conf.get_abs(opts['dotpath']), dotfile.src)
src = os.path.join(conf.abs_dotpath(opts['dotpath']), dotfile.src)
if os.path.isfile(src) and \
Templategen.get_marker() in open(src, 'r').read():
LOG.warn('\"{}\" uses template, please update manually'.format(src))
@@ -259,7 +259,7 @@ def importer(opts, conf, paths):
home = os.path.expanduser(TILD)
cnt = 0
for path in paths:
if not os.path.exists(path):
if not os.path.lexists(path):
LOG.err('\"{}\" does not exist, ignored !'.format(path))
continue
dst = path.rstrip(os.sep)

View File

@@ -45,7 +45,7 @@ class Installer:
"""set src as the link target of dst"""
src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.join(self.base, os.path.expanduser(dst))
if os.path.exists(dst):
if os.path.lexists(dst):
if os.path.realpath(dst) == os.path.realpath(src):
self.log.dbg('ignoring "{}", link exists'.format(dst))
return []
@@ -131,7 +131,7 @@ class Installer:
if self.dry:
self.log.dry('would install {}'.format(dst))
return 0
if os.path.exists(dst):
if os.path.lexists(dst):
samerights = os.stat(dst).st_mode == rights
if self.diff and self._fake_diff(dst, content) and samerights:
self.log.dbg('{} is the same'.format(dst))
@@ -139,7 +139,7 @@ class Installer:
if self.safe and not self.log.ask('Overwrite \"{}\"'.format(dst)):
self.log.warn('ignoring \"{}\", already present'.format(dst))
return 1
if self.backup and os.path.exists(dst):
if self.backup and os.path.lexists(dst):
self._backup(dst)
base = os.path.dirname(dst)
if not self._create_dirs(base):
@@ -196,7 +196,7 @@ class Installer:
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
self.log.dbg('comparing {} and {}'.format(src, dst))
if not os.path.exists(dst):
if not os.path.lexists(dst):
# destination dotfile does not exist
retval = False, '\"{}\" does not exist on local\n'.format(dst)
else:

View File

@@ -44,7 +44,7 @@ def get_tmpfile():
def remove(path):
"""remove a file/directory/symlink"""
if not os.path.exists(path):
if not os.path.lexists(path):
raise OSError("File not found: {}".format(path))
if os.path.islink(path) or os.path.isfile(path):
os.unlink(path)