changes from code review

This commit is contained in:
Georges-Antoine Assi
2025-08-13 14:03:45 -04:00
parent 81a04e4ab4
commit 8fb4769776
2 changed files with 8 additions and 9 deletions

View File

@@ -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

View File

@@ -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):