mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
locate: Gracefully handle busy-database error conditions.
* guix/scripts/locate.scm (SQLITE_BUSY): New variable. (call-with-database): Catch 'sqlite-error and call ‘leave’ upon SQLITE_BUSY. Change-Id: Iebe76c75d45e70317bd18d2c176dcdeaf9d6964c Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
da2dc98185
commit
ce74e02078
1 changed files with 17 additions and 7 deletions
|
@ -114,14 +114,24 @@ (define schema-to-migrate '((1 . "
|
|||
add column output text;
|
||||
")))
|
||||
|
||||
;; XXX: missing in guile-sqlite3@0.1.3
|
||||
(define SQLITE_BUSY 5)
|
||||
|
||||
(define (call-with-database file proc)
|
||||
(let ((db (sqlite-open file)))
|
||||
(dynamic-wind
|
||||
(lambda () #t)
|
||||
(lambda ()
|
||||
(ensure-latest-database-schema db)
|
||||
(proc db))
|
||||
(lambda () (sqlite-close db)))))
|
||||
(catch 'sqlite-error
|
||||
(lambda ()
|
||||
(let ((db (sqlite-open file)))
|
||||
(dynamic-wind
|
||||
(lambda () #t)
|
||||
(lambda ()
|
||||
(ensure-latest-database-schema db)
|
||||
(proc db))
|
||||
(lambda () (sqlite-close db)))))
|
||||
(lambda (key who code errmsg)
|
||||
(if (= code SQLITE_BUSY)
|
||||
(leave (G_ "~a: database is locked by another process~%")
|
||||
file)
|
||||
(throw key who code errmsg)))))
|
||||
|
||||
(define (ensure-latest-database-schema db)
|
||||
"Ensure DB follows the latest known version of the schema."
|
||||
|
|
Loading…
Reference in a new issue