aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-03-13 20:01:48 +0000
committerChristopher Baines <mail@cbaines.net>2023-03-13 20:01:48 +0000
commit659543cd9ad78f712b4b067863db0613423dd23b (patch)
tree66b17a12fd1a634c73d5db3d1948f7863c4dc546 /scripts
parent06b9a0363cc9286c747e70a8af109789a90f3d0c (diff)
downloadnar-herder-659543cd9ad78f712b4b067863db0613423dd23b.tar
nar-herder-659543cd9ad78f712b4b067863db0613423dd23b.tar.gz
Make import transactional for all the provided narinfos
As this will allow the --ensure-references-exist option to work properly where there are circular references.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/nar-herder.in82
1 files changed, 46 insertions, 36 deletions
diff --git a/scripts/nar-herder.in b/scripts/nar-herder.in
index c8726b8..9845e46 100644
--- a/scripts/nar-herder.in
+++ b/scripts/nar-herder.in
@@ -312,42 +312,52 @@
(call-with-progress-reporter progress
(lambda (report)
- (for-each (lambda (narinfo-file)
- (let ((narinfo
- (call-with-input-file narinfo-file
- (lambda (port)
- ;; Set url to a dummy value as this doesn't
- ;; matter
- (read-narinfo port
- "https://narherderdummyvalue")))))
-
- (when (assq-ref opts 'ensure-references-exist)
- (let ((self-reference
- (store-path-base
- (narinfo-path narinfo))))
- (for-each
- (lambda (reference)
- (when (and
- (not
- (string=? reference self-reference))
- (not
- (database-select-narinfo-by-hash
- database
- (string-take reference 32))))
- (error
- (simple-format (current-error-port)
- "missing reference to ~A\n"
- reference))))
- (narinfo-references narinfo))))
-
- (database-insert-narinfo
- database
- narinfo
- #:tags (or (assq-ref opts 'tags)
- '()))
-
- (report)))
- narinfos))))))
+ (database-call-with-transaction
+ database
+ (lambda (db)
+ (let ((read-narinfos
+ (map
+ (lambda (narinfo-file)
+ (let ((narinfo
+ (call-with-input-file narinfo-file
+ (lambda (port)
+ ;; Set url to a dummy value as this doesn't
+ ;; matter
+ (read-narinfo port
+ "https://narherderdummyvalue")))))
+
+ (database-insert-narinfo
+ database
+ narinfo
+ #:tags (or (assq-ref opts 'tags)
+ '()))
+
+ (report)
+
+ narinfo))
+ narinfos)))
+
+ (when (assq-ref opts 'ensure-references-exist)
+ (for-each
+ (lambda (narinfo)
+ (let ((self-reference
+ (store-path-base
+ (narinfo-path narinfo))))
+ (for-each
+ (lambda (reference)
+ (when (and
+ (not
+ (string=? reference self-reference))
+ (not
+ (database-select-narinfo-by-hash
+ database
+ (string-take reference 32))))
+ (error
+ (simple-format (current-error-port)
+ "missing reference to ~A\n"
+ reference))))
+ (narinfo-references narinfo))))
+ read-narinfos))))))))))
(("remove" rest ...)
(let* ((opts (parse-options %base-options
%base-option-defaults