Skip to content

Commit

Permalink
umu_bspatch: raise exception on verify failure
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Jan 25, 2025
1 parent 2439791 commit e6d2323
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions umu/umu_bspatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,19 @@ def result(self) -> list[Future]:
"""Return the currently submitted tasks."""
return self._futures

def _check_binaries(
self, proton: Path, item: ManifestEntry
) -> ManifestEntry | None:
def _check_binaries(self, proton: Path, item: ManifestEntry) -> ManifestEntry:
rpath: Path = proton.joinpath(item["name"])

try:
with rpath.open("rb") as fp:
stats: os.stat_result = os.fstat(fp.fileno())
xxhash: int = 0
if item["size"] != stats.st_size:
log.error(
"Expected size %s, received %s", item["size"], stats.st_size
)
return None
err: str = f"Expected size {item['size']}, received {stats.st_size}"
raise ValueError(err)
if item["mode"] != stats.st_mode:
log.error(
"Expected mode %s, received %s", item["mode"], stats.st_mode
)
return None
err: str = f"Expected mode {item['mode']}, received {stats.st_mode}"
raise ValueError(err)
if stats.st_size > MMAP_MIN:
with mmap(fp.fileno(), length=0, access=ACCESS_READ) as mm:
# Ignore. Passing an mmap is valid here
Expand All @@ -245,11 +239,11 @@ def _check_binaries(
else:
xxhash = xxh3_64_intdigest(fp.read())
if item["xxhash"] != xxhash:
log.error("Expected xxhash %s, received %s", item["xxhash"], xxhash)
return None
err: str = f"Expected xxhash {item['xxhash']}, received {xxhash}"
raise ValueError(err)
except FileNotFoundError:
log.debug("Aborting partial update, file not found: %s", rpath)
return None
raise

return item

Expand Down

0 comments on commit e6d2323

Please sign in to comment.