mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 14:04:17 +00:00
properly handle dead symlink
This commit is contained in:
@@ -208,7 +208,7 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
|
|
||||||
def update(opts, conf, path):
|
def update(opts, conf, path):
|
||||||
"""update the dotfile from 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))
|
LOG.err('\"{}\" does not exist!'.format(path))
|
||||||
return False
|
return False
|
||||||
home = os.path.expanduser(TILD)
|
home = os.path.expanduser(TILD)
|
||||||
@@ -228,7 +228,7 @@ def update(opts, conf, path):
|
|||||||
LOG.err('multiple dotfiles found: {}'.format(found))
|
LOG.err('multiple dotfiles found: {}'.format(found))
|
||||||
return False
|
return False
|
||||||
dotfile = subs[0]
|
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 \
|
if os.path.isfile(src) and \
|
||||||
Templategen.get_marker() in open(src, 'r').read():
|
Templategen.get_marker() in open(src, 'r').read():
|
||||||
LOG.warn('\"{}\" uses template, please update manually'.format(src))
|
LOG.warn('\"{}\" uses template, please update manually'.format(src))
|
||||||
@@ -259,7 +259,7 @@ def importer(opts, conf, paths):
|
|||||||
home = os.path.expanduser(TILD)
|
home = os.path.expanduser(TILD)
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not os.path.exists(path):
|
if not os.path.lexists(path):
|
||||||
LOG.err('\"{}\" does not exist, ignored !'.format(path))
|
LOG.err('\"{}\" does not exist, ignored !'.format(path))
|
||||||
continue
|
continue
|
||||||
dst = path.rstrip(os.sep)
|
dst = path.rstrip(os.sep)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Installer:
|
|||||||
"""set src as the link target of dst"""
|
"""set src as the link target of dst"""
|
||||||
src = os.path.join(self.base, os.path.expanduser(src))
|
src = os.path.join(self.base, os.path.expanduser(src))
|
||||||
dst = os.path.join(self.base, os.path.expanduser(dst))
|
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):
|
if os.path.realpath(dst) == os.path.realpath(src):
|
||||||
self.log.dbg('ignoring "{}", link exists'.format(dst))
|
self.log.dbg('ignoring "{}", link exists'.format(dst))
|
||||||
return []
|
return []
|
||||||
@@ -131,7 +131,7 @@ class Installer:
|
|||||||
if self.dry:
|
if self.dry:
|
||||||
self.log.dry('would install {}'.format(dst))
|
self.log.dry('would install {}'.format(dst))
|
||||||
return 0
|
return 0
|
||||||
if os.path.exists(dst):
|
if os.path.lexists(dst):
|
||||||
samerights = os.stat(dst).st_mode == rights
|
samerights = os.stat(dst).st_mode == rights
|
||||||
if self.diff and self._fake_diff(dst, content) and samerights:
|
if self.diff and self._fake_diff(dst, content) and samerights:
|
||||||
self.log.dbg('{} is the same'.format(dst))
|
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)):
|
if self.safe and not self.log.ask('Overwrite \"{}\"'.format(dst)):
|
||||||
self.log.warn('ignoring \"{}\", already present'.format(dst))
|
self.log.warn('ignoring \"{}\", already present'.format(dst))
|
||||||
return 1
|
return 1
|
||||||
if self.backup and os.path.exists(dst):
|
if self.backup and os.path.lexists(dst):
|
||||||
self._backup(dst)
|
self._backup(dst)
|
||||||
base = os.path.dirname(dst)
|
base = os.path.dirname(dst)
|
||||||
if not self._create_dirs(base):
|
if not self._create_dirs(base):
|
||||||
@@ -196,7 +196,7 @@ class Installer:
|
|||||||
src = os.path.expanduser(src)
|
src = os.path.expanduser(src)
|
||||||
dst = os.path.expanduser(dst)
|
dst = os.path.expanduser(dst)
|
||||||
self.log.dbg('comparing {} and {}'.format(src, 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
|
# destination dotfile does not exist
|
||||||
retval = False, '\"{}\" does not exist on local\n'.format(dst)
|
retval = False, '\"{}\" does not exist on local\n'.format(dst)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ def get_tmpfile():
|
|||||||
|
|
||||||
def remove(path):
|
def remove(path):
|
||||||
"""remove a file/directory/symlink"""
|
"""remove a file/directory/symlink"""
|
||||||
if not os.path.exists(path):
|
if not os.path.lexists(path):
|
||||||
raise OSError("File not found: {}".format(path))
|
raise OSError("File not found: {}".format(path))
|
||||||
if os.path.islink(path) or os.path.isfile(path):
|
if os.path.islink(path) or os.path.isfile(path):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user