From 23255c9d45f87e9f0eeca7d4c9c300cfdce18d87 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 12 Feb 2019 18:32:51 +0100 Subject: [PATCH] properly handle dead symlink --- dotdrop/installer.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 6142d45..8185ed9 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -6,6 +6,7 @@ handle the installation of dotfiles """ import os +import errno # local imports from dotdrop.logger import Logger @@ -287,7 +288,14 @@ class Installer: self.log.dry('would install {}'.format(dst)) return 0 if os.path.lexists(dst): - samerights = os.stat(dst).st_mode == rights + samerights = False + try: + samerights = os.stat(dst).st_mode == rights + except OSError as e: + if e.errno == errno.ENOENT: + # broken symlink + self.log.err('broken symlink {}'.format(dst)) + return -1 if self.diff and self._fake_diff(dst, content) and samerights: if self.debug: self.log.dbg('{} is the same'.format(dst))