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