mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 00:27:41 +01:00
changes from code review
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user