From 6d5ef25c17ce3c05cd0a7de3a276e50150c462e6 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Tue, 9 Jan 2024 09:39:51 -0500 Subject: [PATCH] Hotfix excluding files with no extensions --- backend/utils/__init__.py | 10 +++++----- backend/utils/fs.py | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/utils/__init__.py b/backend/utils/__init__.py index 586766c5d..3ea6e401b 100644 --- a/backend/utils/__init__.py +++ b/backend/utils/__init__.py @@ -127,11 +127,11 @@ def normalize_search_term(search_term: str) -> str: def get_file_extension(rom: dict) -> str: - return ( - re.search(EXTENSION_REGEX, rom["file_name"]).group(1) - if not rom["multi"] - else "" - ) + if rom["multi"]: + return "" + + match = re.search(EXTENSION_REGEX, rom["file_name"]) + return match.group(1) if match else "" def get_version() -> str | None: diff --git a/backend/utils/fs.py b/backend/utils/fs.py index 79c7bee9e..1ec0977d7 100644 --- a/backend/utils/fs.py +++ b/backend/utils/fs.py @@ -25,11 +25,11 @@ from config import ( from config.config_loader import config from exceptions.fs_exceptions import ( PlatformsNotFoundException, - PlatformNotFoundException, RomsNotFoundException, RomNotFoundError, RomAlreadyExistsException, ) +from . import get_file_extension # ========= Resources utils ========= @@ -230,26 +230,26 @@ def get_roms_structure(fs_slug: str): def _exclude_files(files, filetype) -> list[str]: excluded_extensions = config[f"EXCLUDED_{filetype.upper()}_EXT"] excluded_names = config[f"EXCLUDED_{filetype.upper()}_FILES"] - filtered_files: list = [] + excluded_files: list = [] for file in files: # Split the file name to get the extension. - parts = file.split(".") + ext = get_file_extension({"file_name": file, "multi": False}) # Exclude the file if it has no extension or the extension is in the excluded list. - if len(parts) == 1 or parts[-1] in excluded_extensions: - filtered_files.append(file) + if not ext or ext in excluded_extensions: + excluded_files.append(file) # Additionally, check if the file name mathes a pattern in the excluded list. if len(excluded_names) > 0: [ - filtered_files.append(file) + excluded_files.append(file) for name in excluded_names if file == name or fnmatch.fnmatch(file, name) ] # Return files that are not in the filtered list. - return [f for f in files if f not in filtered_files] + return [f for f in files if f not in excluded_files] def _exclude_multi_roms(roms) -> list[str]: