database: Register each store item only once.

Fixes <https://bugs.gnu.org/32600>.
Reported by Leo Famulari.

* guix/store/database.scm (register-items): Check whether TO-REGISTER is
in DB by calling 'path-id',  and skip the reset-timestamps,
registration, and deduplication phases when it is.
This commit is contained in:
Ludovic Courtès 2018-09-23 23:11:30 +02:00
parent f0addd6461
commit bb3b6ccb05
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 14 additions and 10 deletions

View File

@ -290,9 +290,13 @@ Write a progress report to LOG-PORT."
(define real-file-name (define real-file-name
(string-append store-dir "/" (basename (store-info-item item)))) (string-append store-dir "/" (basename (store-info-item item))))
(let-values (((hash nar-size) (nar-sha256 real-file-name))) ;; When TO-REGISTER is already registered, skip it. This makes a
;; significant differences when 'register-closures' is called
;; consecutively for overlapping closures such as 'system' and 'bootcfg'.
(unless (path-id db to-register)
(when reset-timestamps? (when reset-timestamps?
(reset-timestamps real-file-name)) (reset-timestamps real-file-name))
(let-values (((hash nar-size) (nar-sha256 real-file-name)))
(sqlite-register db #:path to-register (sqlite-register db #:path to-register
#:references (store-info-references item) #:references (store-info-references item)
#:deriver (store-info-deriver item) #:deriver (store-info-deriver item)
@ -301,7 +305,7 @@ Write a progress report to LOG-PORT."
#:nar-size nar-size #:nar-size nar-size
#:time registration-time) #:time registration-time)
(when deduplicate? (when deduplicate?
(deduplicate real-file-name hash #:store store-dir)))) (deduplicate real-file-name hash #:store store-dir)))))
(mkdir-p db-dir) (mkdir-p db-dir)
(parameterize ((sql-schema schema)) (parameterize ((sql-schema schema))