in src/buildstream_plugins/sources/cargo.py [0:0]
def _download(self, url, auth_scheme):
# We do not use etag in case what we have in cache is
# not matching ref in order to be able to recover from
# corrupted download.
if self.sha:
etag = self._get_etag(self.sha)
else:
etag = None
with self.cargo.tempdir() as td:
local_file, etag, error = download_file(url, etag, td, auth_scheme)
if error:
raise SourceError("{}: Error mirroring {}: {}".format(self, url, error), temporary=True)
# Make sure url-specific mirror dir exists.
os.makedirs(self._get_mirror_dir(), exist_ok=True)
# Store by sha256sum
sha256 = utils.sha256sum(local_file)
# Even if the file already exists, move the new file over.
# In case the old file was corrupted somehow.
os.rename(local_file, self._get_mirror_file(sha256))
if etag:
self._store_etag(sha256, etag)
return sha256