fix(hashing): address trunk lint issues in composite archive hashing

- Use AnyioPath.stat() instead of os.path.getmtime in async context (ASYNC240)
- Add assert to narrow rom_md5_h/rom_sha1_h from HASH|None to HASH (mypy/union-attr)
- Auto-formatted long log.error calls in archive_7zip.py (ruff)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Spinnich
2026-05-23 12:14:39 +00:00
parent c20d48bbf8
commit a9f9ea2edc
2 changed files with 13 additions and 4 deletions

View File

@@ -678,7 +678,8 @@ class FSRomsHandler(FSHandler):
)
if archive_entries:
archive_mtime = os.path.getmtime(rom_dir)
archive_mtime = (await AnyioPath(rom_dir).stat()).st_mtime
assert rom_md5_h is not None and rom_sha1_h is not None
for internal_name, entry_size, chunks in archive_entries:
crc_c = 0
md5_h = hashlib.md5(usedforsecurity=False)

View File

@@ -117,7 +117,11 @@ def read_7z_archive_files(
timeout=SEVEN_ZIP_TIMEOUT,
shell=False, # trunk-ignore(bandit/B603)
)
except (subprocess.TimeoutExpired, subprocess.CalledProcessError, FileNotFoundError) as e:
except (
subprocess.TimeoutExpired,
subprocess.CalledProcessError,
FileNotFoundError,
) as e:
log.error(f"Error listing 7z archive {file_path}: {e}")
return []
@@ -169,11 +173,15 @@ def read_7z_archive_files(
while chunk := process.stdout.read(FILE_READ_CHUNK_SIZE):
if time.monotonic() - start_time > SEVEN_ZIP_TIMEOUT:
process.terminate()
log.error("7z extraction timed out during multi-file archive read")
log.error(
"7z extraction timed out during multi-file archive read"
)
return output
chunks.append(chunk)
if process.returncode != 0:
log.error(f"7z extraction of {name} failed with code {process.returncode}")
log.error(
f"7z extraction of {name} failed with code {process.returncode}"
)
continue
except (OSError, ValueError) as e:
log.error(f"Error extracting {name} from {file_path}: {e}")