mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
accounts: Call 'fdatasync' when writing databases.
* gnu/build/accounts.scm (catch-ENOSYS): New macro. (database-writer): Call 'fdatasync'.
This commit is contained in:
parent
ed8570dce3
commit
d088d5c484
1 changed files with 14 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
(define-module (gnu build accounts)
|
(define-module (gnu build accounts)
|
||||||
#:use-module (guix records)
|
#:use-module (guix records)
|
||||||
#:use-module (guix combinators)
|
#:use-module (guix combinators)
|
||||||
|
#:use-module ((guix build syscalls) #:select (fdatasync))
|
||||||
#:use-module (gnu system accounts)
|
#:use-module (gnu system accounts)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (srfi srfi-11)
|
#:use-module (srfi srfi-11)
|
||||||
|
@ -230,6 +231,14 @@ each field."
|
||||||
;; grab this lock with 'with-file-lock' when they access the databases.
|
;; grab this lock with 'with-file-lock' when they access the databases.
|
||||||
"/etc/.pwd.lock")
|
"/etc/.pwd.lock")
|
||||||
|
|
||||||
|
(define-syntax-rule (catch-ENOSYS exp)
|
||||||
|
(catch 'system-error
|
||||||
|
(lambda () exp)
|
||||||
|
(lambda args
|
||||||
|
(if (= ENOSYS (system-error-errno args))
|
||||||
|
#f
|
||||||
|
(apply throw args)))))
|
||||||
|
|
||||||
(define (database-writer file mode entry->string)
|
(define (database-writer file mode entry->string)
|
||||||
(lambda* (entries #:optional (file-or-port file))
|
(lambda* (entries #:optional (file-or-port file))
|
||||||
"Write ENTRIES to FILE-OR-PORT. When FILE-OR-PORT is a file name, write
|
"Write ENTRIES to FILE-OR-PORT. When FILE-OR-PORT is a file name, write
|
||||||
|
@ -249,6 +258,11 @@ to it atomically and set the appropriate permissions."
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(chmod port mode)
|
(chmod port mode)
|
||||||
(write-entries port)
|
(write-entries port)
|
||||||
|
|
||||||
|
;; XXX: When booting with the statically-linked Guile,
|
||||||
|
;; 'fdatasync' is unavailable.
|
||||||
|
(catch-ENOSYS (fdatasync port))
|
||||||
|
|
||||||
(close-port port)
|
(close-port port)
|
||||||
(rename-file template file-or-port))
|
(rename-file template file-or-port))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue