From 93058611026b5ce420ae641c04f662cc9afc0afe Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 1 Dec 2020 23:00:11 +0100 Subject: [PATCH] Bugfix (consider porting): undo triggered Transaction::cancel was sometimes triggering an undo: when the current transaction was empty, "commit" did just remove it which made the subsequent undo act on the *previous* transaction. --- src/db/db/dbManager.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/db/db/dbManager.cc b/src/db/db/dbManager.cc index 405c0f45b..5e53b1a83 100644 --- a/src/db/db/dbManager.cc +++ b/src/db/db/dbManager.cc @@ -147,15 +147,24 @@ Manager::last_transaction_id () const void Manager::cancel () { + // equivalent to commit and undo. But takes care that an empty commit is not followed by undo + // (which would undo the previous transaction!) if (m_enabled) { - // commit and undo - revert changes done so far - commit (); - undo (); + tl_assert (m_opened); + tl_assert (! m_replay); + m_opened = false; - // delete all following transactions - erase_transactions (m_current, m_transactions.end ()); - m_current = m_transactions.end (); + if (m_current->first.begin () != m_current->first.end ()) { + + ++m_current; + undo (); + + } else { + // empty transactions .. just delete + erase_transactions (m_current, m_transactions.end ()); + m_current = m_transactions.end (); + } } }