From e04564e06b8410ea9335fa8bd227a12209d0f213 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 17 Jun 2018 11:07:52 +0200 Subject: [PATCH] properly handle dead symlink --- dotdrop/dotdrop.py | 6 +++--- dotdrop/installer.py | 8 ++++---- dotdrop/utils.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 37051ee..8f68a42 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 56d3801..540c3cc 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -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: diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 54f6415..5a39c22 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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)