download: Correctly detect "No route to host" conditions.

* guix/build/download.scm (open-connection-for-uri): Delete addrinfos
  with the same address.  Always open SOCK_STREAM/IPPROTO_IP sockets.
  Fix the error handler's condition to determine what to do.
  Reported by Nikita Karetnikov <nikita.karetnikov@gmail.com> at
  <http://lists.gnu.org/archive/html/bug-guix/2012-12/msg00150.html>.
This commit is contained in:
Ludovic Courtès 2012-12-17 00:14:30 +01:00
parent 868fce7c4a
commit 3c738d6bd8
1 changed files with 9 additions and 6 deletions

View File

@ -60,15 +60,18 @@ which is not available during bootstrap."
((http) 80) ; /etc/services, not for me! ((http) 80) ; /etc/services, not for me!
(else (else
(error "unsupported URI scheme" uri)))))) (error "unsupported URI scheme" uri))))))
(getaddrinfo (uri-host uri) (delete-duplicates (getaddrinfo (uri-host uri)
(number->string port) (number->string port)
AI_NUMERICSERV))) AI_NUMERICSERV)
(lambda (ai1 ai2)
(equal? (addrinfo:addr ai1)
(addrinfo:addr ai2))))))
(let loop ((addresses addresses)) (let loop ((addresses addresses))
(let* ((ai (car addresses)) (let* ((ai (car addresses))
(s (with-fluids ((%default-port-encoding #f)) (s (with-fluids ((%default-port-encoding #f))
(socket (addrinfo:fam ai) (addrinfo:socktype ai) ;; Restrict ourselves to TCP.
(addrinfo:protocol ai))))) (socket (addrinfo:fam ai) SOCK_STREAM IPPROTO_IP))))
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(connect s (addrinfo:addr ai)) (connect s (addrinfo:addr ai))
@ -81,7 +84,7 @@ which is not available during bootstrap."
(lambda args (lambda args
;; Connection failed, so try one of the other addresses. ;; Connection failed, so try one of the other addresses.
(close s) (close s)
(if (null? addresses) (if (null? (cdr addresses))
(apply throw args) (apply throw args)
(loop (cdr addresses)))))))) (loop (cdr addresses))))))))