diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-12-10 10:56:48 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2022-12-10 10:56:48 +0100 |
| commit | b129026e2e242e9068158ae6e6fcd8d7c5ea092e (patch) | |
| tree | ac52d64670ae247fd54c2b9550c3ff0c15a7d17c | |
| parent | 591af24ade1021d91a3e7c62fcc7a8c90f00d4bb (diff) | |
deduplicate: Use 'sendfile' for small file copies.
* guix/store/deduplication.scm (dump-file/deduplicate): Use 'sendfile'
instead of 'dump-port'.
* tests/store-deduplication.scm ("copy-file/deduplicate, below %deduplication-minimum-size"):
New test.
| -rw-r--r-- | guix/store/deduplication.scm | 4 | ||||
| -rw-r--r-- | tests/store-deduplication.scm | 17 |
2 files changed, 18 insertions, 3 deletions
diff --git a/guix/store/deduplication.scm b/guix/store/deduplication.scm index ab982e3b3d2..9953675319a 100644 --- a/guix/store/deduplication.scm +++ b/guix/store/deduplication.scm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2017 Caleb Ristvedt <caleb.ristvedt@cune.org> | 2 | ;;; Copyright © 2017 Caleb Ristvedt <caleb.ristvedt@cune.org> |
| 3 | ;;; Copyright © 2018-2021 Ludovic Courtès <ludo@gnu.org> | 3 | ;;; Copyright © 2018-2022 Ludovic Courtès <ludo@gnu.org> |
| 4 | ;;; | 4 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 6 | ;;; |
| @@ -262,7 +262,7 @@ down the road." | |||
| 262 | (deduplicate file (dump-and-compute-hash) #:store store) | 262 | (deduplicate file (dump-and-compute-hash) #:store store) |
| 263 | (call-with-output-file file | 263 | (call-with-output-file file |
| 264 | (lambda (output) | 264 | (lambda (output) |
| 265 | (dump-port input output size))))) | 265 | (sendfile output input size 0))))) |
| 266 | 266 | ||
| 267 | (define* (copy-file/deduplicate source target | 267 | (define* (copy-file/deduplicate source target |
| 268 | #:key (store (%store-directory))) | 268 | #:key (store (%store-directory))) |
diff --git a/tests/store-deduplication.scm b/tests/store-deduplication.scm index 2950fbc1a3e..f1845035d89 100644 --- a/tests/store-deduplication.scm +++ b/tests/store-deduplication.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2018, 2020-2021 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2018, 2020-2022 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -136,6 +136,21 @@ | |||
| 136 | (cons (apply = (map (compose stat:ino stat) identical)) | 136 | (cons (apply = (map (compose stat:ino stat) identical)) |
| 137 | (map (compose stat:nlink stat) identical)))))) | 137 | (map (compose stat:nlink stat) identical)))))) |
| 138 | 138 | ||
| 139 | (test-assert "copy-file/deduplicate, below %deduplication-minimum-size" | ||
| 140 | (call-with-temporary-directory | ||
| 141 | (lambda (store) | ||
| 142 | (let ((source (string-append store "/input"))) | ||
| 143 | (call-with-output-file source | ||
| 144 | (lambda (port) | ||
| 145 | (display "Hello!\n" port))) | ||
| 146 | (copy-file/deduplicate source | ||
| 147 | (string-append store "/a") | ||
| 148 | #:store store) | ||
| 149 | (and (not (directory-exists? (string-append store "/.links"))) | ||
| 150 | (file=? source (string-append store "/a")) | ||
| 151 | (not (= (stat:ino (stat (string-append store "/a"))) | ||
| 152 | (stat:ino (stat source))))))))) | ||
| 153 | |||
| 139 | (test-assert "copy-file/deduplicate" | 154 | (test-assert "copy-file/deduplicate" |
| 140 | (call-with-temporary-directory | 155 | (call-with-temporary-directory |
| 141 | (lambda (store) | 156 | (lambda (store) |
