1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-store-deduplication)
20 #:use-module (guix tests)
21 #:use-module (guix store deduplication)
22 #:use-module (guix hash)
23 #:use-module ((guix utils) #:select (call-with-temporary-directory))
24 #:use-module (guix build utils)
25 #:use-module (rnrs bytevectors)
26 #:use-module (ice-9 binary-ports)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-64))
30 (test-begin "store-deduplication")
32 (test-equal "deduplicate"
33 (cons* #t #f ;inode comparisons
34 2 (make-list 5 6)) ;'nlink' values
36 (call-with-temporary-directory
38 (let ((data (string->utf8 "Hello, world!"))
39 (identical (map (lambda (n)
40 (string-append store "/" (number->string n)))
42 (unique (string-append store "/unique")))
43 (for-each (lambda (file)
44 (call-with-output-file file
46 (put-bytevector port data))))
48 (call-with-output-file unique
50 (put-bytevector port (string->utf8 "This is unique."))))
52 (for-each (lambda (file)
53 (deduplicate file (sha256 data) #:store store))
55 (deduplicate unique (nar-sha256 unique) #:store store)
57 ;; (system (string-append "ls -lRia " store))
58 (cons* (apply = (map (compose stat:ino stat) identical))
59 (= (stat:ino (stat unique))
60 (stat:ino (stat (car identical))))
61 (stat:nlink (stat unique))
62 (map (compose stat:nlink stat) identical))))))
64 (test-end "store-deduplication")