Merge branch 'cache-srcname-sha256' into 'master'

update: cache the SHA-256 of the src tarball

Closes #1290

See merge request fdroid/fdroidserver!1686
This commit is contained in:
Michael Pöhn 2025-07-28 21:10:40 +00:00
commit 058f0b7f6a
2 changed files with 16 additions and 4 deletions

View file

@ -595,7 +595,10 @@ def convert_version(version, app, repodir):
ver["file"]["ipfsCIDv1"] = ipfsCIDv1 ver["file"]["ipfsCIDv1"] = ipfsCIDv1
if "srcname" in version: if "srcname" in version:
ver["src"] = common.file_entry(os.path.join(repodir, version["srcname"])) ver["src"] = common.file_entry(
os.path.join(repodir, version["srcname"]),
version["srcnameSha256"],
)
if "obbMainFile" in version: if "obbMainFile" in version:
ver["obbMainFile"] = common.file_entry( ver["obbMainFile"] = common.file_entry(
@ -964,7 +967,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, signer_fingerprints
for k, v in sorted(package.items()): for k, v in sorted(package.items()):
if not v: if not v:
continue continue
if k in ('icon', 'icons', 'icons_src', 'ipfsCIDv1', 'name'): if k in ('icon', 'icons', 'icons_src', 'ipfsCIDv1', 'name', 'srcnameSha256'):
continue continue
if k == 'antiFeatures': if k == 'antiFeatures':
d[k] = sorted(v.keys()) d[k] = sorted(v.keys())

View file

@ -370,6 +370,11 @@ def get_cache():
v['antiFeatures'] = {k: {} for k in sorted(v['antiFeatures'])} v['antiFeatures'] = {k: {} for k in sorted(v['antiFeatures'])}
if 'added' in v: if 'added' in v:
v['added'] = datetime.fromtimestamp(v['added'], tz=timezone.utc) v['added'] = datetime.fromtimestamp(v['added'], tz=timezone.utc)
if v.get('srcname') and not v.get('srcnameSha256'):
f = f'archive/{v["srcname"]}'
if not os.path.exists(f):
f = f'repo/{v["srcname"]}'
v['srcnameSha256'] = common.sha256sum(f)
return apkcache return apkcache
@ -1570,8 +1575,10 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
repo_file['packageName'] = m.group(1) repo_file['packageName'] = m.group(1)
repo_file['versionCode'] = int(m.group(2)) repo_file['versionCode'] = int(m.group(2))
srcfilename = name + b'_src.tar.gz' srcfilename = name + b'_src.tar.gz'
if os.path.exists(os.path.join(repodir, srcfilename)): srcpath = os.path.join(repodir, srcfilename)
if os.path.exists(srcpath):
repo_file['srcname'] = srcfilename.decode() repo_file['srcname'] = srcfilename.decode()
repo_file['srcnameSha256'] = common.sha256sum(srcpath.decode())
repo_file['size'] = stat.st_size repo_file['size'] = stat.st_size
apkcache[name_utf8] = repo_file apkcache[name_utf8] = repo_file
@ -1989,8 +1996,10 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
apk['apkName'] = apkfilename apk['apkName'] = apkfilename
srcfilename = apkfilename[:-4] + "_src.tar.gz" srcfilename = apkfilename[:-4] + "_src.tar.gz"
if os.path.exists(os.path.join(repodir, srcfilename)): srcpath = os.path.join(repodir, srcfilename)
if os.path.exists(srcpath):
apk['srcname'] = srcfilename apk['srcname'] = srcfilename
apk['srcnameSha256'] = common.sha256sum(srcpath)
# verify the jar signature is correct, allow deprecated # verify the jar signature is correct, allow deprecated
# algorithms only if the APK is in the archive. # algorithms only if the APK is in the archive.