Database locked error: Closes #5663

This patch resolves a potential hole when rolling back a transaction
when it's been cancelled (leaving the database locked).  It also
fixes some minor bugs I found while investigating.
This commit is contained in:
Jim Nelson 2012-08-14 16:06:33 -07:00
parent dd865890e6
commit fe46262903
3 changed files with 7 additions and 6 deletions

View file

@ -325,19 +325,21 @@ public class Geary.Db.Connection : Geary.Db.Context {
throw err;
}
// If transaction throws an Error, must rollback, always
TransactionOutcome outcome = TransactionOutcome.ROLLBACK;
Error? caught_err = null;
try {
// perform the transaction
outcome = cb(this, cancellable);
} catch (Error err) {
debug("Connection.exec_transaction: transaction threw error %s", err.message);
debug("Connection.exec_transaction: transaction threw error: %s", err.message);
caught_err = err;
}
// commit/rollback
// commit/rollback ... don't use Cancellable for TransactionOutcome because it's SQL *must*
// execute in order to unlock the database
try {
exec(outcome.sql(), cancellable);
exec(outcome.sql());
} catch (Error err) {
debug("Connection.exec_transaction: Unable to %s transaction: %s", outcome.to_string(),
err.message);

View file

@ -32,10 +32,10 @@ public class Geary.Db.Result : Geary.Db.Context {
* Returns true if results are waiting, false if finished, or throws a DatabaseError.
*/
public bool next(Cancellable? cancellable = null) throws Error {
check_cancelled("Result.step", cancellable);
check_cancelled("Result.next", cancellable);
if (!finished) {
finished = (throw_on_error("Result.step", statement.stmt.step())) != Sqlite.ROW;
finished = (throw_on_error("Result.next", statement.stmt.step())) != Sqlite.ROW;
log(finished ? "NO ROW" : "ROW");
}

View file

@ -382,7 +382,6 @@ private class Geary.ImapDB.Account : Object {
}
} catch (Error err) {
debug("Error attempting to clear duplicate folders from account: %s", err.message);
breakpoint();
}
if (count > 0)