summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-10-04 12:29:09 -0700
committerZac Medico <zmedico@gentoo.org>2010-10-04 12:29:09 -0700
commit78d28f182fbe2b2618be4652763849d0fc289b16 (patch)
treedb750862589ad5de4865dd6d0f6e1a21254658c0
parent360778208e003d0644bab8b769e6ba02b82f2190 (diff)
downloadportage-78d28f182fbe2b2618be4652763849d0fc289b16.tar.gz
portage-78d28f182fbe2b2618be4652763849d0fc289b16.tar.bz2
portage-78d28f182fbe2b2618be4652763849d0fc289b16.zip
Bug #339642 - Use AF_UNSPEC for --sync addresses.
-rw-r--r--pym/_emerge/actions.py75
1 files changed, 40 insertions, 35 deletions
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index 6dad3785c..476e21372 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -11,6 +11,7 @@ import errno
import logging
import platform
import pwd
+import random
import re
import shutil
import signal
@@ -2082,45 +2083,49 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
extra_rsync_opts = portage.util.shlex_split(
settings.get("PORTAGE_RSYNC_EXTRA_OPTS",""))
all_rsync_opts.update(extra_rsync_opts)
- family = socket.AF_INET
- if "-4" in all_rsync_opts or "--ipv4" in all_rsync_opts:
- family = socket.AF_INET
- elif socket.has_ipv6 and \
- ("-6" in all_rsync_opts or "--ipv6" in all_rsync_opts):
- family = socket.AF_INET6
- ips=[]
+
+ ips_v4 = []
+ ips_v6 = []
+
+ try:
+ addrinfos = socket.getaddrinfo(hostname, None,
+ socket.AF_UNSPEC, socket.SOCK_STREAM)
+ except socket.error as e:
+ writemsg("!!! getaddrinfo failed: %s\n" % (e,), noiselevel=-1)
+ return 1
+
+ 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)
+
+ # 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
+
+ # reverse, for use with pop()
+ ips.reverse()
+
SERVER_OUT_OF_DATE = -1
EXCEEDED_MAX_RETRIES = -2
while (1):
if ips:
- del ips[0]
- if ips==[]:
- try:
- for addrinfo in socket.getaddrinfo(
- hostname, None, family, socket.SOCK_STREAM):
- if socket.has_ipv6 and addrinfo[0] == socket.AF_INET6:
- # IPv6 addresses need to be enclosed in square brackets
- ips.append("[%s]" % addrinfo[4][0])
- else:
- ips.append(addrinfo[4][0])
- from random import shuffle
- shuffle(ips)
- except SystemExit as e:
- raise # Needed else can't exit
- except Exception as e:
- print("Notice:",str(e))
- dosyncuri=syncuri
-
- if ips:
- try:
- dosyncuri = syncuri.replace(
- "//" + user_name + hostname + port + "/",
- "//" + user_name + ips[0] + port + "/", 1)
- except SystemExit as e:
- raise # Needed else can't exit
- except Exception as e:
- print("Notice:",str(e))
- dosyncuri=syncuri
+ dosyncuri = syncuri.replace(
+ "//" + user_name + hostname + port + "/",
+ "//" + user_name + ips.pop() + port + "/", 1)
+ else:
+ writemsg("!!! Exhausted addresses for %s\n" % \
+ hostname, noiselevel=-1)
+ return 1
if (retries==0):
if "--ask" in myopts: