1 ;; A simple script that adds each file given from the command-line into the
2 ;; store and checks them if it's the same.
8 ;; This is based from tests/derivations.scm from Guix source code.
9 (define* (directory-contents dir #:optional (slurp get-bytevector-all))
10 "Return an alist representing the contents of DIR"
11 (define prefix-len (string-length dir))
12 (sort (file-system-fold (const #t)
13 (lambda (path stat result)
14 (alist-cons (string-drop path prefix-len)
15 (call-with-input-file path slurp)
17 (lambda (path stat result) result)
18 (lambda (path stat result) result)
19 (lambda (path stat result) result)
20 (lambda (path stat errno result) result)
24 (string<? (car e1) (car e2)))))
26 (define* (check-if-same store drv path)
27 "Check if the given path and its store item are the same"
28 (let* ((filetype (stat:type (stat drv))))
31 (and (valid-path? store drv)
32 (equal? (call-with-input-file path get-bytevector-all)
33 (call-with-input-file drv get-bytevector-all))))
35 (and (valid-path? store drv)
36 (equal? (directory-contents path)
37 (directory-contents drv))))
40 (define* (add-and-check-item-to-store store path)
41 "Add PATH to STORE and check if the contents are the same"
42 (let* ((store-item (add-to-store store
45 (is-same (check-if-same store store-item path)))
51 (add-and-check-item-to-store store (readlink* path)))
52 (cdr (command-line))))