guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/04: locate: Gracefully handle busy-database error conditions.


From: guix-commits
Subject: 03/04: locate: Gracefully handle busy-database error conditions.
Date: Sun, 26 Nov 2023 17:36:31 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit ce74e02078b4d2753bf0205fae205a1b704b15d4
Author: Maciej Kalandyk <m.kalandyk@outlook.com>
AuthorDate: Sat Nov 18 01:30:39 2023 +0100

    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>
---
 guix/scripts/locate.scm | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/guix/scripts/locate.scm b/guix/scripts/locate.scm
index 92af3509bf..963ff2bf57 100644
--- a/guix/scripts/locate.scm
+++ b/guix/scripts/locate.scm
@@ -114,14 +114,24 @@ alter table Packages
 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."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]