Skip to content

Commit 41b24d4

Browse files
committed
Reset primary_url on HTTP 404
When we read repomd.xml, we got an URL for a primary.xml.gz that's not available in the repository. This could be caused by an update to the repository at the same time we access it.
1 parent 190ab22 commit 41b24d4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

obs_maven/repo.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import time
2121
import tempfile
2222
import urllib.request
23+
import urllib.error
2324
import xml.sax
2425
import xml.sax.handler
2526
import xml.etree.ElementTree as ET
@@ -57,10 +58,9 @@ def find_primary(self):
5758

5859
def parse_primary(self):
5960
primary_url = self.find_primary()
60-
logging.debug("Parsing primary %s", primary_url)
6161
for cnt in range(1, 4):
6262
try:
63-
logging.debug("Getting primary try %s", cnt)
63+
logging.debug("Parsing primary %s, try %s", primary_url, cnt)
6464

6565
# Download the primary.xml.gz to a file first to avoid
6666
# connection resets
@@ -84,6 +84,15 @@ def parse_primary(self):
8484
parser.parse(input_source)
8585
self._rpms = handler.rpms.values()
8686
break
87+
except urllib.error.HTTPError as e:
88+
# We likely hit the repo while it changed:
89+
# At the time we read repomd.xml refered to an primary.xml.gz
90+
# that does not exist anymore.
91+
if cnt < 3 and e.code == 404:
92+
primary_url = self.find_primary()
93+
time.sleep(2)
94+
else:
95+
raise
8796
except OSError:
8897
if cnt < 3:
8998
time.sleep(2)

0 commit comments

Comments
 (0)