From 8fb476977654bcb623ec1d95df1cfd7ea20fd20a Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Wed, 13 Aug 2025 14:03:45 -0400 Subject: [PATCH] changes from code review --- backend/handler/filesystem/roms_handler.py | 14 ++++++-------- backend/utils/archive_7zip.py | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/handler/filesystem/roms_handler.py b/backend/handler/filesystem/roms_handler.py index ccddc7d4f..1c7155ee4 100644 --- a/backend/handler/filesystem/roms_handler.py +++ b/backend/handler/filesystem/roms_handler.py @@ -141,15 +141,13 @@ def read_tar_file( ) -> Iterator[bytes]: try: with tarfile.open(file_path, mode) as f: - for member in f.getmembers(): - # Ignore directories and any other non-regular files - if not member.isfile(): - continue + regular_files = [member for member in f.getmembers() if member.isfile()] - largest_file = max(f.getmembers(), key=lambda x: x.size) - with f.extractfile(largest_file) as ef: # type: ignore - while chunk := ef.read(FILE_READ_CHUNK_SIZE): - yield chunk + # Find the largest file among regular files only + largest_file = max(regular_files, key=lambda x: x.size) + with f.extractfile(largest_file) as ef: # type: ignore + while chunk := ef.read(FILE_READ_CHUNK_SIZE): + yield chunk except tarfile.ReadError: for chunk in read_basic_file(file_path): yield chunk diff --git a/backend/utils/archive_7zip.py b/backend/utils/archive_7zip.py index 726e68080..add7abcaf 100644 --- a/backend/utils/archive_7zip.py +++ b/backend/utils/archive_7zip.py @@ -79,7 +79,8 @@ def process_file_7z( shell=False, # trunk-ignore(bandit/B603): 7z path is hardcoded, args are validated ) - extracted_file = temp_path / largest_file.split("/")[-1] + # Get the first file in temp_path + extracted_file = next(temp_path.iterdir()) if extracted_file.exists(): with open(extracted_file, "rb") as f: while chunk := f.read(FILE_READ_CHUNK_SIZE):