guix-commits
[Top][All Lists]
Advanced

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

branch master updated: scripts: discover: Remove file locks.


From: guix-commits
Subject: branch master updated: scripts: discover: Remove file locks.
Date: Sun, 13 Dec 2020 07:24:23 -0500

This is an automated email from the git hooks/post-receive script.

mothacehe pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new 1f49ab6  scripts: discover: Remove file locks.
1f49ab6 is described below

commit 1f49ab6ee22abf31654e865deb89c52026c99b29
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Mon Dec 7 14:12:06 2020 +0100

    scripts: discover: Remove file locks.
    
    * guix/scripts/discover.scm (call-with-read-file-lock, with-read-file-lock):
    Remove them.
    (write-publish-file): Use "with-atomic-file-output" instead of
    "with-file-lock".
    (read-substitute-urls): Remove file lock.
---
 guix/scripts/discover.scm | 57 ++++++++++++++---------------------------------
 1 file changed, 17 insertions(+), 40 deletions(-)

diff --git a/guix/scripts/discover.scm b/guix/scripts/discover.scm
index 007db0d..2b5b564 100644
--- a/guix/scripts/discover.scm
+++ b/guix/scripts/discover.scm
@@ -21,6 +21,7 @@
   #:use-module (guix config)
   #:use-module (guix scripts)
   #:use-module (guix ui)
+  #:use-module (guix utils)
   #:use-module (guix build syscalls)
   #:use-module (guix build utils)
   #:use-module (guix scripts publish)
@@ -78,47 +79,27 @@ CACHE-DIRECTORY."
 (define* (write-publish-file #:key (file (%publish-file)))
   "Dump the content of %PUBLISH-SERVICES hash table into FILE.  Use a write
 lock on FILE to synchronize with any potential readers."
-  (with-file-lock file
-    (call-with-output-file file
-      (lambda (port)
-        (hash-for-each
-         (lambda (name service)
-           (format port "http://~a:~a~%";
-                   (avahi-service-address service)
-                   (avahi-service-port service)))
-         %publish-services)))
-        (chmod file #o644)))
-
-(define (call-with-read-file-lock file thunk)
-  "Call THUNK with a read lock on FILE."
-  (let ((port #f))
-    (dynamic-wind
-      (lambda ()
-        (set! port
-              (let ((port (open-file file "r0")))
-                (fcntl-flock port 'read-lock)
-                port)))
-      thunk
-      (lambda ()
-        (when port
-          (unlock-file port))))))
-
-(define-syntax-rule (with-read-file-lock file exp ...)
-  "Wait to acquire a read lock on FILE and evaluate EXP in that context."
-  (call-with-read-file-lock file (lambda () exp ...)))
+  (with-atomic-file-output file
+    (lambda (port)
+      (hash-for-each
+       (lambda (name service)
+         (format port "http://~a:~a~%";
+                 (avahi-service-address service)
+                 (avahi-service-port service)))
+       %publish-services)))
+  (chmod file #o644))
 
 (define* (read-substitute-urls #:key (file (%publish-file)))
   "Read substitute urls list from FILE and return it.  Use a read lock on FILE
 to synchronize with the writer."
   (if (file-exists? file)
-      (with-read-file-lock file
-        (call-with-input-file file
-          (lambda (port)
-            (let loop ((url (read-line port))
-                       (urls '()))
-              (if (eof-object? url)
-                  urls
-                  (loop (read-line port) (cons url urls)))))))
+      (call-with-input-file file
+        (lambda (port)
+          (let loop ((url (read-line port))
+                     (urls '()))
+            (if (eof-object? url)
+                urls
+                (loop (read-line port) (cons url urls))))))
       '()))
 
 
@@ -158,7 +139,3 @@ to synchronize with the writer."
         (mkdir-p (dirname publish-file))
         (avahi-browse-service-thread service-proc
                                      #:types %services)))))
-
-;;; Local Variables:
-;;; eval: (put 'with-read-file-lock 'scheme-indent-function 1)
-;;; End:



reply via email to

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