mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
apt-sync: download packages to tmp path first
Possible fixes tuna/issues#1116
This commit is contained in:
parent
4c66f70f99
commit
7d48e03dc6
@ -216,20 +216,22 @@ def apt_mirror(base_url: str, dist: str, repo: str, arch: str, dest_base_dir: Pa
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
pkg_url=f"{base_url}/{pkg_filename}"
|
pkg_url=f"{base_url}/{pkg_filename}"
|
||||||
|
dest_tmp_filename = dest_filename.with_name('._syncing_.' + dest_filename.name)
|
||||||
for retry in range(MAX_RETRY):
|
for retry in range(MAX_RETRY):
|
||||||
print(f"downloading {pkg_url} to {dest_filename}", flush=True)
|
print(f"downloading {pkg_url} to {dest_filename}", flush=True)
|
||||||
# break # dry run
|
# break # dry run
|
||||||
if check_and_download(pkg_url, dest_filename) != 0:
|
if check_and_download(pkg_url, dest_tmp_filename) != 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
sha = hashlib.sha256()
|
sha = hashlib.sha256()
|
||||||
with dest_filename.open("rb") as f:
|
with dest_tmp_filename.open("rb") as f:
|
||||||
for block in iter(lambda: f.read(1024**2), b""):
|
for block in iter(lambda: f.read(1024**2), b""):
|
||||||
sha.update(block)
|
sha.update(block)
|
||||||
if sha.hexdigest() != pkg_checksum:
|
if sha.hexdigest() != pkg_checksum:
|
||||||
print(f"Invalid checksum of {dest_filename}, expected {pkg_checksum}")
|
print(f"Invalid checksum of {dest_filename}, expected {pkg_checksum}")
|
||||||
dest_filename.unlink()
|
dest_tmp_filename.unlink()
|
||||||
continue
|
continue
|
||||||
|
dest_tmp_filename.rename(dest_filename)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(f"Failed to download {dest_filename}")
|
print(f"Failed to download {dest_filename}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user