deduplicate: Create the '.links' directory lazily.

This avoids repeated (mkdir-p "/gnu/store/.links") calls when
deduplicating lots of files.

* guix/store/deduplication.scm (deduplicate): Remove initial call to
'mkdir-p'.  Add ENOENT case in 'link' exception handler.  Reindent.
* tests/store-deduplication.scm ("deduplicate, ENOSPC"): Check
for (<= links 4) to account for the initial 'link' call.
This commit is contained in:
Ludovic Courtès 2020-12-11 15:48:02 +01:00
parent 9e6fe0e08f
commit 7530e491b5
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 51 additions and 47 deletions

View file

@ -159,7 +159,6 @@ (define* (deduplicate path hash #:key (store (%store-directory)))
(define links-directory (define links-directory
(string-append store "/.links")) (string-append store "/.links"))
(mkdir-p links-directory)
(let loop ((path path) (let loop ((path path)
(type (stat:type (lstat path))) (type (stat:type (lstat path)))
(hash hash)) (hash hash))
@ -195,6 +194,11 @@ (define links-directory
#:swap-directory #:swap-directory
links-directory links-directory
#:store store)) #:store store))
((= errno ENOENT)
;; This most likely means that LINKS-DIRECTORY does
;; not exist. Attempt to create it and try again.
(mkdir-p links-directory)
(loop path type hash))
((= errno ENOSPC) ((= errno ENOSPC)
;; There's not enough room in the directory index for ;; There's not enough room in the directory index for
;; more entries in .links, but that's fine: we can ;; more entries in .links, but that's fine: we can

View file

@ -95,7 +95,7 @@ (define-module (test-store-deduplication)
(lambda () (lambda ()
(set! link (lambda (old new) (set! link (lambda (old new)
(set! links (+ links 1)) (set! links (+ links 1))
(if (<= links 3) (if (<= links 4)
(true-link old new) (true-link old new)
(throw 'system-error "link" "~A" '("Whaaat?!") (throw 'system-error "link" "~A" '("Whaaat?!")
(list ENOSPC)))))) (list ENOSPC))))))