summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-07-20 14:49:34 +0200
committerLudovic Courtès <ludo@gnu.org>2018-07-20 15:01:33 +0200
commite4752118691e41ae8307649d1abfd4739b3e4bfa (patch)
treeeb1c1d4b794e3e00dad9ce0f10d959d12b870bcd
parent4f89a8eec69491b925f084381ea4de37527c9310 (diff)
database: Reset timestamps to one second after the Epoch.
Previously, store items registered in the database by this code (for instance, store items retrieved by 'guix offload' and passed to 'restore-file-set') would have an mtime of 0 instead of 1. This would cause problems for things like .go files: Guile would consider them to be older than the corresponding .scm file, and consequently it would ignore them and possibly use another (incorrect) .go file. Reported by Ricardo Wurmus. * guix/store/database.scm (reset-timestamps): Pass 1, not 0, to 'utime'. * tests/store-database.scm ("register-path"): Check the mtime of FILE and REF.
-rw-r--r--guix/store/database.scm8
-rw-r--r--tests/store-database.scm7
2 files changed, 10 insertions, 5 deletions
diff --git a/guix/store/database.scm b/guix/store/database.scm
index 8f35b63e37e..0879a95d0b1 100644
--- a/guix/store/database.scm
+++ b/guix/store/database.scm
@@ -190,12 +190,14 @@ Every store item in REFERENCES must already be registered."
190(define (reset-timestamps file) 190(define (reset-timestamps file)
191 "Reset the modification time on FILE and on all the files it contains, if 191 "Reset the modification time on FILE and on all the files it contains, if
192it's a directory. While at it, canonicalize file permissions." 192it's a directory. While at it, canonicalize file permissions."
193 ;; Note: We're resetting to one second after the Epoch like 'guix-daemon'
194 ;; has always done.
193 (let loop ((file file) 195 (let loop ((file file)
194 (type (stat:type (lstat file)))) 196 (type (stat:type (lstat file))))
195 (case type 197 (case type
196 ((directory) 198 ((directory)
197 (chmod file #o555) 199 (chmod file #o555)
198 (utime file 0 0 0 0) 200 (utime file 1 1 0 0)
199 (let ((parent file)) 201 (let ((parent file))
200 (for-each (match-lambda 202 (for-each (match-lambda
201 (("." . _) #f) 203 (("." . _) #f)
@@ -209,10 +211,10 @@ it's a directory. While at it, canonicalize file permissions."
209 (type type)))))) 211 (type type))))))
210 (scandir* parent)))) 212 (scandir* parent))))
211 ((symlink) 213 ((symlink)
212 (utime file 0 0 0 0 AT_SYMLINK_NOFOLLOW)) 214 (utime file 1 1 0 0 AT_SYMLINK_NOFOLLOW))
213 (else 215 (else
214 (chmod file (if (executable-file? file) #o555 #o444)) 216 (chmod file (if (executable-file? file) #o555 #o444))
215 (utime file 0 0 0 0))))) 217 (utime file 1 1 0 0)))))
216 218
217(define* (register-path path 219(define* (register-path path
218 #:key (references '()) deriver prefix 220 #:key (references '()) deriver prefix
diff --git a/tests/store-database.scm b/tests/store-database.scm
index fcae66e2de9..4d918842505 100644
--- a/tests/store-database.scm
+++ b/tests/store-database.scm
@@ -32,7 +32,8 @@
32 32
33(test-begin "store-database") 33(test-begin "store-database")
34 34
35(test-assert "register-path" 35(test-equal "register-path"
36 '(1 1)
36 (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f) 37 (let ((file (string-append (%store-prefix) "/" (make-string 32 #\f)
37 "-fake"))) 38 "-fake")))
38 (when (valid-path? %store file) 39 (when (valid-path? %store file)
@@ -50,7 +51,9 @@
50 (and (valid-path? %store file) 51 (and (valid-path? %store file)
51 (equal? (references %store file) (list ref)) 52 (equal? (references %store file) (list ref))
52 (null? (valid-derivers %store file)) 53 (null? (valid-derivers %store file))
53 (null? (referrers %store file)))))) 54 (null? (referrers %store file))
55 (list (stat:mtime (lstat file))
56 (stat:mtime (lstat ref)))))))
54 57
55(test-equal "new database" 58(test-equal "new database"
56 (list 1 2) 59 (list 1 2)