Commit 89e96176 authored by Jacek Sowiński's avatar Jacek Sowiński

Revert TodoList changes if Transaction fails

This will prevent from leaving TodoList and todo.txt file in
inconsistent state whenever first Command.execute() inside Transaction
succeeds and any subsequent fails for whatever reason.
parent ffdd292f
...@@ -324,6 +324,8 @@ class UIApplication(CLIApplicationBase): ...@@ -324,6 +324,8 @@ class UIApplication(CLIApplicationBase):
try: try:
if transaction.execute(): if transaction.execute():
self._post_execute() self._post_execute()
else:
self._rollback()
except TypeError: except TypeError:
# TODO: show error message # TODO: show error message
pass pass
...@@ -341,6 +343,12 @@ class UIApplication(CLIApplicationBase): ...@@ -341,6 +343,12 @@ class UIApplication(CLIApplicationBase):
if dirty or self.marked_todos: if dirty or self.marked_todos:
self._reset_state() self._reset_state()
def _rollback(self):
try:
self.backup.apply(self.todolist, p_archive=None)
except AttributeError:
pass
def _repeat_last_cmd(self, p_todo_id=None): def _repeat_last_cmd(self, p_todo_id=None):
try: try:
cmd, verbosity = self._last_cmd cmd, verbosity = self._last_cmd
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment