From 37fe107bf402232563e711798fc8977866223463 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 2 May 2018 16:37:23 +0200 Subject: [PATCH] properly handle exception when destination is not a dir --- dotdrop/installer.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 386e102..469f4d8 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -115,7 +115,10 @@ class Installer: return cur == content def _write(self, dst, content, rights): - '''Write file''' + '''Write file + returns 0 for success, + 1 when already exists + -1 when error''' if self.dry: self.log.dry('would install %s' % (dst)) return 0 @@ -131,8 +134,12 @@ class Installer: if not self._create_dirs(base): self.log.err('creating directory for \"%s\"' % (dst)) return -1 - with open(dst, 'wb') as f: - f.write(content) + try: + with open(dst, 'wb') as f: + f.write(content) + except NotADirectoryError as e: + self.log.err('opening dest file: %s' % (e)) + return -1 os.chmod(dst, rights) return 0