diff options
author | Christopher Baines <mail@cbaines.net> | 2024-06-15 21:18:39 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2024-06-15 21:18:39 +0100 |
commit | e15befc369b08279c372f284da2d2c60ecc84e59 (patch) | |
tree | 07b7715552154d53e51a46e603bc4655fe430cd5 /scripts | |
parent | 35275d44086a1b0d78dc3b177da0448c4bfd35a4 (diff) | |
download | nar-herder-e15befc369b08279c372f284da2d2c60ecc84e59.tar nar-herder-e15befc369b08279c372f284da2d2c60ecc84e59.tar.gz |
Check nar file sizes on import
Diffstat (limited to 'scripts')
-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) |