diff options
-rw-r--r-- | scripts/nar-herder.in | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/scripts/nar-herder.in b/scripts/nar-herder.in index 7326526..a0e3127 100644 --- a/scripts/nar-herder.in +++ b/scripts/nar-herder.in @@ -417,6 +417,18 @@ (read-narinfo port "https://narherderdummyvalue"))))) + (define (check-size! file size) + (let ((actual-size (stat:size (stat file)))) + (unless (= size actual-size) + (error + (simple-format + #f + "error importing ~A, ~A should be ~A bytes but is ~A" + narinfo-file + file + size + actual-size))))) + (database-insert-narinfo database narinfo @@ -425,22 +437,27 @@ (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))) + (lambda (uri size) + (let* ((nar-path + (uri-decode (uri-path uri))) + (source + (string-append + (dirname narinfo-file) "/" nar-path))) + (if (string=? canonical-storage + (dirname narinfo-file)) + (check-size! source size) + (let ((dest + (string-append + canonical-storage "/" nar-path))) + (check-size! source size) + (simple-format (current-error-port) + "moving ~A to ~A\n" + source dest) + (rename-file source dest) + ;; Re-check file size + (check-size! dest size))))) + (narinfo-uris narinfo) + (narinfo-file-sizes narinfo))) (report) |