Skip to content

Commit

Permalink
re-try to download the binary on connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer authored and cbosdo committed Aug 31, 2022
1 parent a4ce56f commit d9377dc
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions obs_maven/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,19 @@ def get_binary(self, path, target, mtime):
"""
url = self.get_repo_path(path)
logging.debug("Getting binary from: %s", url)
f = urllib.request.urlopen(url)
target_f = open(target, "wb")
shutil.copyfileobj(f, target_f)
target_f.close()
f.close()
os.utime(target, (mtime, mtime))
for cnt in range(1, 4):
try:
f = urllib.request.urlopen(url)
target_f = open(target, "wb")
shutil.copyfileobj(f, target_f)
target_f.close()
f.close()
os.utime(target, (mtime, mtime))
break
except ConnectionResetError:
target_f.close()
f.close()
if cnt < 3:
logging.debug("Getting binary try {}".format(cnt + 1))
else:
raise

0 comments on commit d9377dc

Please sign in to comment.