plugin: fix zip reproducibility and legacy-tag log spam
Two issues found while verifying the live install: 1. pack.py produced a different zip MD5 for identical content, because zip records file mtimes. Re-running pack.py would have rewritten the manifest checksum while the already-published asset stayed the same, and Jellyfin would then refuse the install with "The checksum of the received data doesn't match." The zip entry now carries a fixed 1980-01-01 timestamp, and --publish downloads the published asset back and compares its MD5 with the manifest checksum before reporting success. 2. The legacy deploy.py tag lives in the on-disk index.html, so it was stripped from every single response and logged at INFO each time (6 lines and counting per boot on the live server). The message is now emitted once, and says what it actually means: the tag is still on disk, run deploy.py rollback to clean it up. Verified: 21/21 rewrite checks pass, including a regression case built from the tag actually present on the server.
This commit is contained in:
@@ -240,6 +240,24 @@ def head_ok(url):
|
||||
return e.code, None
|
||||
|
||||
|
||||
def fetch_md5(url):
|
||||
"""Download the published asset and hash it -- exactly what Jellyfin does.
|
||||
|
||||
This is the check that catches a manifest whose checksum no longer matches the
|
||||
uploaded zip (a real failure mode: the install then dies with
|
||||
"The checksum of the received data doesn't match.").
|
||||
"""
|
||||
h = hashlib.md5()
|
||||
req = urllib.request.Request(url, method="GET")
|
||||
with urllib.request.urlopen(req, timeout=300) as resp:
|
||||
while True:
|
||||
chunk = resp.read(1 << 20)
|
||||
if not chunk:
|
||||
break
|
||||
h.update(chunk)
|
||||
return h.hexdigest().upper()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- steps
|
||||
|
||||
|
||||
@@ -275,11 +293,25 @@ def verify_embedded(dll):
|
||||
|
||||
|
||||
def make_zip(dll, target_abi):
|
||||
"""Package the DLL the way Jellyfin expects: one file, named after the assembly.
|
||||
|
||||
The entry gets a fixed timestamp on purpose. zip stores mtimes, so packaging
|
||||
the same DLL twice would otherwise produce different bytes, a different MD5,
|
||||
and a manifest checksum that no longer matches the already-uploaded asset.
|
||||
"""
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
asset = "%s_%s.zip" % (ASSEMBLY, target_abi)
|
||||
path = os.path.join(OUT_DIR, asset)
|
||||
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
zf.write(dll, ASSEMBLY + ".dll")
|
||||
|
||||
info = zipfile.ZipInfo(ASSEMBLY + ".dll", date_time=(1980, 1, 1, 0, 0, 0))
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
info.external_attr = 0o644 << 16
|
||||
|
||||
with open(dll, "rb") as fh:
|
||||
payload = fh.read()
|
||||
with zipfile.ZipFile(path, "w") as zf:
|
||||
zf.writestr(info, payload)
|
||||
|
||||
print("packaged %s (%d bytes)" % (path, os.path.getsize(path)))
|
||||
return path, asset
|
||||
|
||||
@@ -383,6 +415,13 @@ def main():
|
||||
if status != 200:
|
||||
sys.exit("the asset is not downloadable -- is the release a draft?")
|
||||
|
||||
# What Jellyfin will do at install time: download it and compare MD5.
|
||||
live = fetch_md5(entry["sourceUrl"])
|
||||
if live != checksum:
|
||||
sys.exit("published asset md5 %s != manifest checksum %s -- install would fail"
|
||||
% (live, checksum))
|
||||
print("asset md5 matches the manifest checksum (%s)" % live)
|
||||
|
||||
if not args.no_push:
|
||||
run(["git", "add", "manifest.json", "plugin/build.yaml"], cwd=HERE)
|
||||
dirty = subprocess.run(
|
||||
|
||||
Reference in New Issue
Block a user