From 3624a9936ed66313d961564f340fd776ec90a2db Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 13 Oct 2010 02:10:19 -0700 Subject: Bug #340817 - Handle --sync getaddrinfo failure. --- pym/_emerge/actions.py | 53 ++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 0d19ea9ae..133874118 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -2096,36 +2096,45 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): ("-6" in all_rsync_opts or "--ipv6" in all_rsync_opts): family = socket.AF_INET6 - ips_v4 = [] - ips_v6 = [] + uris = [] try: addrinfos = socket.getaddrinfo(hostname, None, family, socket.SOCK_STREAM) except socket.error as e: writemsg("!!! getaddrinfo failed: %s\n" % (e,), noiselevel=-1) - return 1 + # With some configurations we need to use the plain hostname + # rather than try to resolve the ip addresses (bug #340817). + uris.append(syncuri) + else: + ips_v4 = [] + ips_v6 = [] - for addrinfo in addrinfos: - if socket.has_ipv6 and addrinfo[0] == socket.AF_INET6: - # IPv6 addresses need to be enclosed in square brackets - ips_v6.append("[%s]" % addrinfo[4][0]) - else: - ips_v4.append(addrinfo[4][0]) + for addrinfo in addrinfos: + if socket.has_ipv6 and addrinfo[0] == socket.AF_INET6: + # IPv6 addresses need to be enclosed in square brackets + ips_v6.append("[%s]" % addrinfo[4][0]) + else: + ips_v4.append(addrinfo[4][0]) - random.shuffle(ips_v4) - random.shuffle(ips_v6) + random.shuffle(ips_v4) + random.shuffle(ips_v6) - # Give priority to the address family that - # getaddrinfo() returned first. - if socket.has_ipv6 and addrinfos and \ - addrinfos[0][0] == socket.AF_INET6: - ips = ips_v6 + ips_v4 - else: - ips = ips_v4 + ips_v6 + # Give priority to the address family that + # getaddrinfo() returned first. + if socket.has_ipv6 and addrinfos and \ + addrinfos[0][0] == socket.AF_INET6: + ips = ips_v6 + ips_v4 + else: + ips = ips_v4 + ips_v6 + + for ip in ips: + uris.append(syncuri.replace( + "//" + user_name + hostname + port + "/", + "//" + user_name + ip + port + "/", 1)) # reverse, for use with pop() - ips.reverse() + uris.reverse() effective_maxretries = maxretries if effective_maxretries < 0: @@ -2134,10 +2143,8 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): SERVER_OUT_OF_DATE = -1 EXCEEDED_MAX_RETRIES = -2 while (1): - if ips: - dosyncuri = syncuri.replace( - "//" + user_name + hostname + port + "/", - "//" + user_name + ips.pop() + port + "/", 1) + if uris: + dosyncuri = uris.pop() else: writemsg("!!! Exhausted addresses for %s\n" % \ hostname, noiselevel=-1) -- cgit v1.2.3-1-g7c22