From 101629628e0a62a72bbcb242dab75c31f8d557df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 3 May 2026 22:46:21 +0000 Subject: [PATCH] Simplify extension exclusion to use ends-with check instead of sub-extension iteration Agent-Logs-Url: https://github.com/rommapp/romm/sessions/a81b2023-a243-4721-bc5e-c6fa1a473a79 Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com> --- backend/handler/filesystem/base_handler.py | 22 +++++-------------- backend/handler/filesystem/roms_handler.py | 8 +++---- .../handler/filesystem/test_base_handler.py | 16 -------------- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/backend/handler/filesystem/base_handler.py b/backend/handler/filesystem/base_handler.py index 61b1c122c..bfcb48057 100644 --- a/backend/handler/filesystem/base_handler.py +++ b/backend/handler/filesystem/base_handler.py @@ -205,19 +205,6 @@ class FSHandler: match = EXTENSION_REGEX.search(file_name) return match.group(1) if match else "" - def iter_file_extensions(self, file_name: str) -> list[str]: - """Return all right-anchored sub-extensions for a filename. - - For "game.nds.enc.hash.txt" this yields: - ["nds.enc.hash.txt", "enc.hash.txt", "hash.txt", "txt"] - This allows exclusion rules like "hash.txt" to match multi-dot filenames. - """ - ext = self.parse_file_extension(file_name) - if not ext: - return [] - parts = ext.split(".") - return [".".join(parts[i:]) for i in range(len(parts))] - def extract_uuid_v4_from_filename(self, file_name: str) -> str: match = UUID_V4_REGEX.search(file_name) return match.group(0) if match else "" @@ -228,11 +215,12 @@ class FSHandler: excluded_files: list[str] = [] for file_name in files: - # Check all right-anchored sub-extensions so that rules like "hash.txt" - # match multi-dot filenames such as "game.nds.enc.hash.txt". + # Check whether the filename ends with any excluded extension entry. + # Using ends-with handles both simple rules ("txt") and compound rules + # ("hash.txt") against multi-dot filenames like "game.nds.enc.hash.txt". if any( - e.lower() in excluded_extensions - for e in self.iter_file_extensions(file_name) + file_name.lower().endswith("." + ext.lower()) + for ext in excluded_extensions ): excluded_files.append(file_name) diff --git a/backend/handler/filesystem/roms_handler.py b/backend/handler/filesystem/roms_handler.py index 90f0aa0c8..29c021c33 100644 --- a/backend/handler/filesystem/roms_handler.py +++ b/backend/handler/filesystem/roms_handler.py @@ -456,11 +456,11 @@ class FSRomsHandler(FSHandler): f"{abs_fs_path}/{rom.fs_name}", recursive=True ): # Check if file is excluded by extension. - # Check all right-anchored sub-extensions so that rules like "hash.txt" - # match multi-dot filenames such as "game.nds.enc.hash.txt". + # Using ends-with handles both simple rules ("txt") and compound + # rules ("hash.txt") for multi-dot filenames like "game.nds.enc.hash.txt". if any( - e.lower() in excluded_file_exts - for e in self.iter_file_extensions(file_name) + file_name.lower().endswith("." + ext.lower()) + for ext in excluded_file_exts ): continue diff --git a/backend/tests/handler/filesystem/test_base_handler.py b/backend/tests/handler/filesystem/test_base_handler.py index 5d9e329d4..3fe7efbd7 100644 --- a/backend/tests/handler/filesystem/test_base_handler.py +++ b/backend/tests/handler/filesystem/test_base_handler.py @@ -145,22 +145,6 @@ class TestFSHandler: assert handler.parse_file_extension("no_extension") == "" assert handler.parse_file_extension("file.with.dots.txt") == "with.dots.txt" - def test_iter_file_extensions(self, handler: FSHandler): - """Test that all right-anchored sub-extensions are returned""" - assert handler.iter_file_extensions("game.nds") == ["nds"] - assert handler.iter_file_extensions("game.nds.hash.txt") == [ - "nds.hash.txt", - "hash.txt", - "txt", - ] - assert handler.iter_file_extensions("game.nds.enc.hash.txt") == [ - "nds.enc.hash.txt", - "enc.hash.txt", - "hash.txt", - "txt", - ] - assert handler.iter_file_extensions("no_extension") == [] - def test_exclude_single_files(self, handler: FSHandler): """Test file exclusion functionality""" files = ["test.txt", "game.rom", "excluded.tmp", "data.json"]