mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 16:45:16 +00:00
properly handle exception when destination is not a dir
This commit is contained in:
@@ -115,7 +115,10 @@ class Installer:
|
|||||||
return cur == content
|
return cur == content
|
||||||
|
|
||||||
def _write(self, dst, content, rights):
|
def _write(self, dst, content, rights):
|
||||||
'''Write file'''
|
'''Write file
|
||||||
|
returns 0 for success,
|
||||||
|
1 when already exists
|
||||||
|
-1 when error'''
|
||||||
if self.dry:
|
if self.dry:
|
||||||
self.log.dry('would install %s' % (dst))
|
self.log.dry('would install %s' % (dst))
|
||||||
return 0
|
return 0
|
||||||
@@ -131,8 +134,12 @@ class Installer:
|
|||||||
if not self._create_dirs(base):
|
if not self._create_dirs(base):
|
||||||
self.log.err('creating directory for \"%s\"' % (dst))
|
self.log.err('creating directory for \"%s\"' % (dst))
|
||||||
return -1
|
return -1
|
||||||
with open(dst, 'wb') as f:
|
try:
|
||||||
f.write(content)
|
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)
|
os.chmod(dst, rights)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user