Skip to content

Commit

Permalink
Merge pull request #505 from freedomofpress/504-ubuntu-dbgsym
Browse files Browse the repository at this point in the history
fix: handle mismatch between a `dbgsym` package's extension and `buildinfo` record
  • Loading branch information
legoktm authored Dec 10, 2024
2 parents b2edd0e + 5080a07 commit 0433b45
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions scripts/check-buildinfo
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Example:
./check-buildinfo package.deb package.buildinfo
"""

import argparse
import hashlib
import subprocess
Expand All @@ -21,11 +22,15 @@ def lookup_buildinfos(buildinfos: Path) -> dict:
data = {}
for path in buildinfos.glob("**/*.buildinfo"):
info = BuildInfo(path.read_text())
for details in info['Checksums-Sha256']:
if details['name'].endswith('.deb'):
if details['name'] in data:
for details in info["Checksums-Sha256"]:
if details["name"].endswith(".deb") or details["name"].endswith(".ddeb"):
# If the package is debug symbols, coerce Ubuntu-style ".ddeb"
# to Debian-style ".deb".
if "dbgsym" in details["name"]:
details["name"] = details["name"].replace(".ddeb", ".deb")
if details["name"] in data:
raise ValueError(f"ERROR: duplicate checksum for {details['name']}")
data[details['name']] = details['sha256']
data[details["name"]] = details["sha256"]
return data


Expand All @@ -45,39 +50,45 @@ def check_package(package: Path, buildinfos: dict) -> bool:
return False


def added_files(against="origin/main") -> List[Path]:
def added_files(against: str) -> List[Path]:
"""Get list of added files compared to main"""
added = []
output = subprocess.check_output([
"git", "log",
# Only list added files
"--diff-filter=A",
# Set our terminal width to be huge so it doesn't truncate
"--stat=999999",
# Output nothing else
"--pretty=",
f"{against}..HEAD"
], text=True)
output = subprocess.check_output(
[
"git",
"log",
# Only list added files
"--diff-filter=A",
# Set our terminal width to be huge so it doesn't truncate
"--stat=999999",
# Output nothing else
"--pretty=",
f"{against}..HEAD",
],
text=True,
)
for line in output.splitlines():
if "|" not in line:
continue
path = Path(line.split("|", 1)[0].strip())
if path.name.endswith('.deb') and path.exists():
# Wasn't deleted in an intermediate commit
added.append(path)
if path.name.endswith(".deb") or path.name.endswith(".ddeb"):
if path.exists():
# Wasn't deleted in an intermediate commit
added.append(path)
added.sort(key=lambda x: x.name)
return added


def main():
parser = argparse.ArgumentParser(
description="Check packages against their buildinfo files"
)
parser = argparse.ArgumentParser(description="Check packages against their buildinfo files")
parser.add_argument("buildinfos", type=Path, help="Folder with buildinfo files")
parser.add_argument(
"--against", default="origin/main", type=str, help="Git ref from which to detect changes"
)
args = parser.parse_args()
buildinfos = lookup_buildinfos(args.buildinfos)
status = 0
added = added_files()
added = added_files(args.against)
if not added:
print("No new packages detected.")
sys.exit(0)
Expand All @@ -87,5 +98,5 @@ def main():
sys.exit(status)


if __name__ == '__main__':
if __name__ == "__main__":
main()

0 comments on commit 0433b45

Please sign in to comment.