me
/
guix
Archived
1
0
Fork 0

nar: 'write-file' can write to non-file ports.

* guix/nar.scm (write-contents): Use 'sendfile' only when P is a file
  port.
* tests/nar.scm ("write-file supports non-file output ports"): New test.
master
Ludovic Courtès 2014-02-21 17:37:55 +01:00
parent 86d07a5514
commit a93e91ff48
2 changed files with 9 additions and 1 deletions

View File

@ -112,7 +112,8 @@
(write-long-long size p) (write-long-long size p)
(call-with-binary-input-file file (call-with-binary-input-file file
;; Use `sendfile' when available (Guile 2.0.8+). ;; Use `sendfile' when available (Guile 2.0.8+).
(if (compile-time-value (defined? 'sendfile)) (if (and (compile-time-value (defined? 'sendfile))
(file-port? p))
(cut sendfile p <> size 0) (cut sendfile p <> size 0)
(cut dump <> p size))) (cut dump <> p size)))
(write-padding size p)) (write-padding size p))

View File

@ -183,6 +183,13 @@
(test-begin "nar") (test-begin "nar")
(test-assert "write-file supports non-file output ports"
(let ((input (string-append (dirname (search-path %load-path "guix.scm"))
"/guix"))
(output (%make-void-port "w")))
(write-file input output)
#t))
(test-assert "write-file + restore-file" (test-assert "write-file + restore-file"
(let* ((input (string-append (dirname (search-path %load-path "guix.scm")) (let* ((input (string-append (dirname (search-path %load-path "guix.scm"))
"/guix")) "/guix"))