aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-05-18 18:12:41 +0100
committerChristopher Baines <mail@cbaines.net>2024-05-19 10:38:28 +0100
commitbbf5119200b844fdb59b54d87fa01cc6abee46c2 (patch)
treea2acd0802eebaa72f9242e43f90832d07ea4f388 /scripts
parentbb8209bf7e238baedd0bdabe11d09518d2f44eee (diff)
downloadnar-herder-bbf5119200b844fdb59b54d87fa01cc6abee46c2.tar
nar-herder-bbf5119200b844fdb59b54d87fa01cc6abee46c2.tar.gz
Move nars to storage when importing narinfos
If they're not in the storage directory.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/nar-herder.in64
1 files changed, 43 insertions, 21 deletions
diff --git a/scripts/nar-herder.in b/scripts/nar-herder.in
index ce91fcd..7f5db5c 100644
--- a/scripts/nar-herder.in
+++ b/scripts/nar-herder.in
@@ -403,27 +403,49 @@
(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)))
+ (let* ((canonical-storage
+ (and=> (assq-ref opts 'storage)
+ canonicalize-path))
+ (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")))))
+
+ (when canonical-storage
+ (for-each
+ (lambda (uri)
+ (unless (string=? canonical-storage
+ (dirname narinfo-file))
+ (let ((source
+ (string-append
+ (dirname narinfo-file)
+ "/" (uri-decode (uri-path uri))))
+ (dest
+ (string-append
+ canonical-storage
+ "/" (uri-decode (uri-path uri)))))
+ (simple-format (current-error-port)
+ "moving ~A to ~A\n"
+ source dest)
+ (rename-file source dest))))
+ (narinfo-uris narinfo)))
+
+ (database-insert-narinfo
+ database
+ narinfo
+ #:tags (or (assq-ref opts 'tags)
+ '()))
+
+ (report)
+
+ narinfo))
+ narinfos)))
(when (assq-ref opts 'ensure-references-exist)
(for-each