From 8cbfa2dced6a70484181dea4f55ec379e241d553 Mon Sep 17 00:00:00 2001 From: Lenoch <81lennoch@gmail.com> Date: Sun, 8 Sep 2024 22:57:54 +0200 Subject: [PATCH] Fix case sensitivity issue for file paths on Linux Updated file path handling to account for case sensitivity on Linux. Added support for lowercase and uppercase `tid` values when searching for retro game forwarders to prevent crashes on case-sensitive filesystems. --- main.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index de8ee59..666c1f1 100644 --- a/main.py +++ b/main.py @@ -68,15 +68,15 @@ async def dispatch(self, request: Request, call_next): cache = {} cache_max_size = 128 def find_id_type(tid: str): - tid = str(tid).upper() + tid = str(tid) # Check if result is in cache if tid in cache: return cache[tid] - base_path = os.path.join(config['database-path'], 'base', f'{tid}.json') - dlc_path = os.path.join(config['database-path'], 'dlc', f'{tid}.json') - update_path = os.path.join(config['database-path'], 'update', f'{tid}.json') + base_path = os.path.join(config['database-path'], 'base', f'{tid.upper()}.json') + dlc_path = os.path.join(config['database-path'], 'dlc', f'{tid.upper()}.json') + update_path = os.path.join(config['database-path'], 'update', f'{tid.upper()}.json') if os.path.exists(base_path): result = ('nx', 'base', base_path) @@ -87,13 +87,23 @@ def find_id_type(tid: str): else: retro_path = os.path.join(config['database-path'], 'retro') if os.path.exists(retro_path): + # Try with lowercase tid first for retro + tid_lower = tid.lower() for console in os.listdir(retro_path): - console_path = os.path.join(retro_path, console, f'{tid}.json') + console_path = os.path.join(retro_path, console, f'{tid_lower}.json') if os.path.exists(console_path): result = (console, 'retro', console_path) break else: - result = (None, None, None) + # If not found, try with uppercase tid + tid_upper = tid.upper() + for console in os.listdir(retro_path): + console_path = os.path.join(retro_path, console, f'{tid_upper}.json') + if os.path.exists(console_path): + result = (console, 'retro', console_path) + break + else: + result = (None, None, None) else: result = (None, None, None) @@ -104,7 +114,6 @@ def find_id_type(tid: str): cache[tid] = result return result - # Custom cache for game screenshots screenshot_cache = {} screenshot_cache_max_size = 128