union: Do not compare directories upon collision.
* guix/build/union.scm (file=?): Return #f if FILE1 and FILE2 are not regular files. Fixes a bug whereby collisions among directories would lead to the invocation of 'file=?' and thus 'call-with-input-file' on directories. Reported by Mark H. Weaver <mhw@netris.org>.
This commit is contained in:
parent
2de227af4b
commit
6ede17ca69
@ -1,5 +1,5 @@
|
|||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; GNU Guix --- Functional package management for GNU
|
||||||
;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
|
;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
@ -103,21 +103,26 @@ single leaf."
|
|||||||
(leaf leaf))))
|
(leaf leaf))))
|
||||||
|
|
||||||
(define (file=? file1 file2)
|
(define (file=? file1 file2)
|
||||||
"Return #t if the contents of FILE1 and FILE2 are identical, #f otherwise."
|
"Return #t if FILE1 and FILE2 are regular files and their contents are
|
||||||
(and (= (stat:size (stat file1)) (stat:size (stat file2)))
|
identical, #f otherwise."
|
||||||
(call-with-input-file file1
|
(let ((st1 (stat file1))
|
||||||
(lambda (port1)
|
(st2 (stat file2)))
|
||||||
(call-with-input-file file2
|
(and (eq? (stat:type st1) 'regular)
|
||||||
(lambda (port2)
|
(eq? (stat:type st2) 'regular)
|
||||||
(define len 8192)
|
(= (stat:size st1) (stat:size st2))
|
||||||
(define buf1 (make-bytevector len))
|
(call-with-input-file file1
|
||||||
(define buf2 (make-bytevector len))
|
(lambda (port1)
|
||||||
(let loop ()
|
(call-with-input-file file2
|
||||||
(let ((n1 (get-bytevector-n! port1 buf1 0 len))
|
(lambda (port2)
|
||||||
(n2 (get-bytevector-n! port2 buf2 0 len)))
|
(define len 8192)
|
||||||
(and (equal? n1 n2)
|
(define buf1 (make-bytevector len))
|
||||||
(or (eof-object? n1)
|
(define buf2 (make-bytevector len))
|
||||||
(loop)))))))))))
|
(let loop ()
|
||||||
|
(let ((n1 (get-bytevector-n! port1 buf1 0 len))
|
||||||
|
(n2 (get-bytevector-n! port2 buf2 0 len)))
|
||||||
|
(and (equal? n1 n2)
|
||||||
|
(or (eof-object? n1)
|
||||||
|
(loop))))))))))))
|
||||||
|
|
||||||
(define* (union-build output directories
|
(define* (union-build output directories
|
||||||
#:key (log-port (current-error-port)))
|
#:key (log-port (current-error-port)))
|
||||||
|
Loading…
Reference in New Issue
Block a user