homebrew-bottles: use filename as dict key

several files share one common hash, thus
using hash as dict key would overlap each other.

No wonder USTC uses .by-hash/ and symlink.

Ref to https://github.com/tuna/issues/issues/1340
This commit is contained in:
Zenithal (at neo) 2021-09-29 23:02:36 +08:00
parent 347c69a45a
commit 225d555544
No known key found for this signature in database
GPG Key ID: 1189C659F3D04C1C

View File

@ -33,9 +33,10 @@ def bottles():
version = formula["versions"]["stable"] version = formula["versions"]["stable"]
revision = "" if formula["revision"] == 0 else f"_{formula['revision']}" revision = "" if formula["revision"] == 0 else f"_{formula['revision']}"
rebuild = "" if bs["rebuild"] == 0 else f".{bs['rebuild']}" rebuild = "" if bs["rebuild"] == 0 else f".{bs['rebuild']}"
b[sha256] = { file = f"{name}-{version}{revision}.{platform}.bottle{rebuild}.tar.gz"
b[file] = {
"url": url, "url": url,
"file": f"{name}-{version}{revision}.{platform}.bottle{rebuild}.tar.gz" "sha256": sha256,
} }
return b return b
@ -75,8 +76,8 @@ if __name__ == "__main__":
file.unlink() file.unlink()
b = bottles() b = bottles()
for sha256 in b: for file in b:
file = b[sha256]["file"] sha256 = b[file]["sha256"]
# dark magic for linuxbrew-bottles # dark magic for linuxbrew-bottles
if "https://formulae.brew.sh/api/formula-linux.json" == HOMEBREW_BOTTLE_DOMAIN and\ if "https://formulae.brew.sh/api/formula-linux.json" == HOMEBREW_BOTTLE_DOMAIN and\
@ -87,14 +88,14 @@ if __name__ == "__main__":
print(f"Downloading {file}", flush=True) print(f"Downloading {file}", flush=True)
dst_file = WORKING_DIR / file dst_file = WORKING_DIR / file
dst_tmp_file = TMP_DIR / file dst_tmp_file = TMP_DIR / file
ret = check_and_download(b[sha256]["url"], dst_file, dst_tmp_file) ret = check_and_download(b[file]["url"], dst_file, dst_tmp_file)
if ret == 0: if ret == 0:
dst_tmp_file.rename(dst_file) dst_tmp_file.rename(dst_file)
print(f"Downloaded {file}", flush=True) print(f"Downloaded {file}", flush=True)
elif ret == 2: elif ret == 2:
print(f"Exists {file}, Skip", flush=True) print(f"Exists {file}, Skip", flush=True)
files = list(map(lambda x: x["file"], b.values())) files = list(b.keys())
# garbage collection # garbage collection
for file in WORKING_DIR.glob("*.tar.gz"): for file in WORKING_DIR.glob("*.tar.gz"):
if file.name not in files: if file.name not in files: