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

pre-action must succeed for dotfile to install (#111)

This commit is contained in:
deadc0de6
2019-03-28 07:40:42 +01:00
parent db57a01227
commit a75d49e56c
2 changed files with 10 additions and 5 deletions

View File

@@ -83,7 +83,7 @@ def cmd_install(o):
if not o.install_temporary and \
Cfg.key_actions_post in dotfile.actions:
actions = dotfile.actions[Cfg.key_actions_post]
# execute action
# execute post action
for action in actions:
if o.dry:
LOG.dry('would execute action: {}'.format(action))

View File

@@ -202,7 +202,8 @@ class Installer:
if not self._create_dirs(base):
self.log.err('creating directory for {}'.format(dst))
return []
self._exec_pre_actions(actions)
if not self._exec_pre_actions(actions):
return []
# re-check in case action created the file
if os.path.lexists(dst):
msg = 'Remove "{}" for link creation?'.format(dst)
@@ -320,7 +321,8 @@ class Installer:
return -1
if self.debug:
self.log.dbg('write content to {}'.format(dst))
self._exec_pre_actions(actions)
if not self._exec_pre_actions(actions):
return -1
# re-check in case action created the file
if self.safe and not overwrite and os.path.lexists(dst):
if not self.log.ask('Overwrite \"{}\"'.format(dst)):
@@ -388,15 +390,18 @@ class Installer:
def _exec_pre_actions(self, actions):
"""execute pre-actions if any"""
if self.action_executed:
return
return True
for action in actions:
if self.dry:
self.log.dry('would execute action: {}'.format(action))
else:
if self.debug:
self.log.dbg('executing pre action {}'.format(action))
action.execute()
if not action.execute():
self.log.err('pre-action {} failed'.format(action.key))
return False
self.action_executed = True
return True
def _install_to_temp(self, templater, src, dst, tmpdir):
"""install a dotfile to a tempdir"""