1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 23:49:48 +00:00

recheck file existence for #84

This commit is contained in:
deadc0de6
2019-02-03 14:37:43 +01:00
parent 39195ed44c
commit 7245ea730d

View File

@@ -182,6 +182,18 @@ class Installer:
self.log.err('creating directory for {}'.format(dst))
return []
self._exec_pre_actions(actions)
# re-check in case action created the file
if os.path.lexists(dst):
msg = 'Remove "{}" for link creation?'.format(dst)
if self.safe and not self.log.ask(msg):
msg = 'ignoring "{}", link was not created'
self.log.warn(msg.format(dst))
return []
try:
utils.remove(dst)
except OSError as e:
self.log.err('something went wrong with {}: {}'.format(src, e))
return []
os.symlink(src, dst)
self.log.sub('linked {} to {}'.format(dst, src))
return [(src, dst)]
@@ -279,6 +291,12 @@ class Installer:
if self.debug:
self.log.dbg('write content to {}'.format(dst))
self._exec_pre_actions(actions)
# re-check in case action created the file
if os.path.lexists(dst) and self.safe:
if not self.log.ask('Overwrite \"{}\"'.format(dst)):
self.log.warn('ignoring {}'.format(dst))
return 1
# write the file
try:
with open(dst, 'wb') as f:
f.write(content)