Archived
1
0
Fork 0

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:
Maciej Kalandyk 2023-11-18 01:30:39 +01:00 committed by Ludovic Courtès
parent da2dc98185
commit ce74e02078
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -114,14 +114,24 @@ alter table Packages
add column output text; add column output text;
"))) ")))
;; XXX: missing in guile-sqlite3@0.1.3
(define SQLITE_BUSY 5)
(define (call-with-database file proc) (define (call-with-database file proc)
(let ((db (sqlite-open file))) (catch 'sqlite-error
(dynamic-wind (lambda ()
(lambda () #t) (let ((db (sqlite-open file)))
(lambda () (dynamic-wind
(ensure-latest-database-schema db) (lambda () #t)
(proc db)) (lambda ()
(lambda () (sqlite-close db))))) (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) (define (ensure-latest-database-schema db)
"Ensure DB follows the latest known version of the schema." "Ensure DB follows the latest known version of the schema."