Skip to content

Commit

Permalink
Fix case sensitivity issue for file paths on Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lenochxd committed Sep 8, 2024
1 parent 6202543 commit 8cbfa2d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 8cbfa2d

Please sign in to comment.