Make downloading a little more careful for races
As we're downloading packages in parallel, it could happen that we copy a file that isn't fully copied yet
This commit is contained in:
parent
bd5bd5a444
commit
7bc4d6c8b1
@ -1,5 +1,6 @@
|
|||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@ -169,11 +170,12 @@ class OBS:
|
|||||||
with (dirpath / name).open("wb") as f:
|
with (dirpath / name).open("wb") as f:
|
||||||
f.write(self._download(project, package, name, revision).read())
|
f.write(self._download(project, package, name, revision).read())
|
||||||
|
|
||||||
shutil.copy(dirpath / name, cached_file)
|
|
||||||
|
|
||||||
# Validate the MD5 of the downloaded file
|
# Validate the MD5 of the downloaded file
|
||||||
if md5(cached_file) != file_md5:
|
if md5(dirpath / name) != file_md5:
|
||||||
raise Exception(f"Download error in {name}")
|
raise Exception(f"Download error in {name}")
|
||||||
|
|
||||||
|
shutil.copy(dirpath / name, cached_file.with_suffix(".new"))
|
||||||
|
os.rename(cached_file.with_suffix(".new"), cached_file)
|
||||||
else:
|
else:
|
||||||
shutil.copy(cached_file, dirpath / name)
|
shutil.copy(cached_file, dirpath / name)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user