From b6952cad8dadd40f0fa44d4997583991acf8cb3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Thu, 22 Aug 2013 17:14:20 +0200
Subject: [PATCH] substitute-binary: Try hard to avoid port buffering.

* guix/scripts/substitute-binary.scm (fetch): In the `file' case, open
  with the `b' flag, so that the coding cookie reading thing doesn't
  lead to buffering some of the data (on 2.0.5).
* tests/utils.scm ("filtered-port, file"): Open with `r0b'.  Fixes a
  test failure with Guile 2.0.5 whereby the first byte of FILE would be
  missing from DECOMPRESSED.
---
 guix/scripts/substitute-binary.scm | 5 ++---
 tests/utils.scm                    | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/guix/scripts/substitute-binary.scm b/guix/scripts/substitute-binary.scm
index 0fdec456f6b..4a013fe2771 100755
--- a/guix/scripts/substitute-binary.scm
+++ b/guix/scripts/substitute-binary.scm
@@ -143,9 +143,8 @@ (define* (fetch uri #:key (buffered? #t) (timeout? #t))
 provide."
   (case (uri-scheme uri)
     ((file)
-     (let ((port (open-input-file (uri-path uri))))
-       (unless buffered?
-         (setvbuf port _IONBF))
+     (let ((port (open-file (uri-path uri)
+                            (if buffered? "rb" "r0b"))))
        (values port (stat:size (stat port)))))
     ((http)
      ;; On Guile 2.0.5, `http-fetch' fetches the whole thing at once.  So
diff --git a/tests/utils.scm b/tests/utils.scm
index e8549204d07..3be60e443d3 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -103,7 +103,7 @@ (define-module (test-utils)
 
 (test-assert "filtered-port, file"
   (let* ((file  (search-path %load-path "guix.scm"))
-         (input (open-file file "r0")))
+         (input (open-file file "r0b")))
     (let*-values (((compressed pids1)
                    (filtered-port `(,%gzip "-c" "--fast") input))
                   ((decompressed pids2)
-- 
GitLab