From 8fd680ab8405c8d5d794093b87fc030c7233fd22 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Sat, 26 Oct 2024 01:07:27 -0300 Subject: [PATCH] fix: Make tar decompression only consider regular files The `tar` decompression function was failing for some users, with error message: ``` 'NoneType' object does not support the context manager protocol ``` As explained in the official documentation [1], the `extractfile` method returns `None` if the member is not a regular file or a link. This change skips any member that is not a regular file. [1] https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractfile --- backend/handler/filesystem/roms_handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/handler/filesystem/roms_handler.py b/backend/handler/filesystem/roms_handler.py index f53e32c84..6be4faa38 100644 --- a/backend/handler/filesystem/roms_handler.py +++ b/backend/handler/filesystem/roms_handler.py @@ -93,6 +93,10 @@ def read_tar_file(file_path: Path, mode: str = "r") -> 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 + # Ignore metadata files created by macOS if member.name.startswith("._"): continue