From a9f9ea2edc67bb85aa29f5c827ff74e900fee063 Mon Sep 17 00:00:00 2001 From: Spinnich Date: Sat, 23 May 2026 12:14:39 +0000 Subject: [PATCH] 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 --- backend/handler/filesystem/roms_handler.py | 3 ++- backend/utils/archive_7zip.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/handler/filesystem/roms_handler.py b/backend/handler/filesystem/roms_handler.py index 719e0c98c..d1b6f4d88 100644 --- a/backend/handler/filesystem/roms_handler.py +++ b/backend/handler/filesystem/roms_handler.py @@ -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) diff --git a/backend/utils/archive_7zip.py b/backend/utils/archive_7zip.py index 6f00bee85..7377a7769 100644 --- a/backend/utils/archive_7zip.py +++ b/backend/utils/archive_7zip.py @@ -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}")