From d371828c47822d5bb379e91ada5b8ff1836e6ff1 Mon Sep 17 00:00:00 2001 From: Lukas Braun <lukas.braun@fau.de> Date: Tue, 31 Jan 2017 02:24:40 +0100 Subject: [PATCH] fix transaction_failed - sqlite3.ErrNo is not an sqlite3.Error, we have to unpack it first - an interrupted transaction in an in-memory database (with shared cache) leads to ErrLocked, while in a regular file-backed databes an ErrBusy is returned --- goatherd.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/goatherd.go b/goatherd.go index dc3ee6d..e702293 100644 --- a/goatherd.go +++ b/goatherd.go @@ -164,8 +164,10 @@ func get_otp(tx *sql.Tx, name string) (*hotp.HOTP, error) { } func transaction_failed(err error) bool { - // XXX: check type first? - return err == sqlite3.ErrBusy + if err, ok := err.(sqlite3.Error); ok { + return err.Code == sqlite3.ErrLocked || err.Code == sqlite3.ErrBusy + } + return false } // Retrieve secret and count for given username and try to find a match within -- GitLab