mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
* fix(docker): boot when the container runs as a non-default UID Unraid runs the container as 99:100, which can't write to the image's /romm (owned by 1000, mode 755), only to the mounted subfolders. The PSP pending dir at /romm/cache/retroarch_sync was created at import time, so every gunicorn worker failed to boot. - Buffer pending PSP save files under the user's assets folder (assets/users/<user>/retroarch/psp_pending/), beside the other RetroArch Cloud Sync files and outside the client-reachable blob categories. - Move the zip and rom-converto download caches to /tmp/romm/cache, and point nginx's internal /cache/ alias there. - Put gunicorn's control socket in /tmp/gunicorn instead of $HOME/.gunicorn, since HOME is / for that UID. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(docker): honor ROMM_TMP_PATH for caches, explain an unwritable sync folder - The download caches live under $ROMM_TMP_PATH/cache when it's set, so installs with a small Docker disk (Unraid's docker.img) can point them at a share. The entrypoint exports the same path for nginx's /cache/ alias. - With ENABLE_SYNC_FOLDER_WATCHER on and /romm/sync not writable, /init warns and skips the watcher instead of dying on mkdir under errexit. - The compose example lists the /romm/sync mount the sync features need. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(sync): cover reading back and clearing buffered PSP files Addresses Greptile's review on #5189. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(sync): apply code-review findings to PSP pending buffer Remove the emptied psp_pending folder after a merge, define the sync folder path once in init, update the architecture doc's PSP and blob locations, and drop a stale .gitignore entry. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(sync): apply simplify findings to PSP pending cleanup Clear the buffered folder with remove_directory, let the startup check own creating the sync folder, and reword the test fixture docstring. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(sync): cap buffered PSP files and drop them on delete Buffered files for an unresolved save folder now count against the bundle limits, so a folder can't fill the assets share and then fail every merge once it resolves. A DELETE also removes the buffered copy, so a deleted file isn't merged back when the folder resolves. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(docker): check the sync folder for push-pull sync too ENABLE_SYNC_PUSH_PULL keeps SSH keys and device saves under /romm/sync as well, so an unwritable folder now disables it with the watcher and warns at boot instead of failing when the task runs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(docker): strip whitespace from env vars like the backend does The backend strips every variable it reads, while the init script and nginx templates used raw values, so a padded ROMM_TMP_PATH sent nginx's /cache/ alias somewhere the backend never writes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore(config): drop the CACHE_BASE_PATH comment Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(docker): say which backend config strips env whitespace Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * revert(docker): drop the entrypoint env whitespace trimming Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(sync): apply pr-ready code-review findings Gate push-pull on its SSH keys path rather than a writable sync folder, accept the same truthy values as the backend, and clear only the merged PSP pending files so another worker's buffered file survives. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor: apply pr-ready simplify findings Share one truthy pattern across init's flag checks (the watcher gates now accept the same values as the backend), disable gunicorn's unused control socket instead of placing it, derive the converts redirect from its own cache path, and factor the unknown PSP folder in tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(docker): apply pr-ready humanizer pass to the sync mount note Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(fs): create handler base folders on first write, skip leftover temp files FSHandler no longer mkdirs its base path when constructed, so a module-level handler rooted at an unmounted or unwritable folder can't take down boot; every write path already creates its parent folders. Blob listings skip .romm_tmp_ files a crashed write left behind, so they are never merged into a PSP bundle or advertised in the sync manifest. The prefix now lives in one TEMP_FILE_PREFIX constant. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
128 lines
4.4 KiB
Python
128 lines
4.4 KiB
Python
import asyncio
|
|
|
|
from exceptions.fs_exceptions import (
|
|
RomAlreadyExistsException,
|
|
RomListedByPlaylistException,
|
|
)
|
|
from handler.database import db_rom_handler
|
|
from handler.filesystem import fs_rom_handler
|
|
from handler.redis_handler import redis_lock
|
|
from logger.formatter import BLUE
|
|
from logger.formatter import highlight as hl
|
|
from logger.logger import log
|
|
from models.rom import Rom
|
|
from utils.filesystem import TEMP_FILE_PREFIX
|
|
from utils.m3u import listing_playlist
|
|
|
|
# Parallel uploads each promote the ROM, maybe on different gunicorn workers.
|
|
# Keyed by the target folder, since lone files sharing a stem promote into one.
|
|
PROMOTION_LOCK_TIMEOUT_SECONDS = 600
|
|
|
|
|
|
def promotion_lock_key(rom: Rom) -> str:
|
|
return f"rom_promotion:{rom.fs_path}/{rom.fs_name_no_ext}"
|
|
|
|
|
|
def assert_promotable(rom: Rom) -> None:
|
|
"""Refuse to move a lone file into a folder when a playlist beside it lists it.
|
|
|
|
Raises:
|
|
RomListedByPlaylistException: An .m3u in the file's folder lists it.
|
|
"""
|
|
if not rom.has_simple_single_file:
|
|
return
|
|
playlist = listing_playlist(fs_rom_handler.validate_path(rom.full_path))
|
|
if playlist:
|
|
raise RomListedByPlaylistException(playlist)
|
|
|
|
|
|
async def promote_single_file_to_folder(rom: Rom) -> Rom:
|
|
"""Promote a simple single-file ROM to a folder ROM in place, keeping rom.id
|
|
and every relation. Idempotent; raises RomAlreadyExistsException on a
|
|
folder-name collision and RomListedByPlaylistException when an .m3u lists it.
|
|
"""
|
|
async with redis_lock(
|
|
promotion_lock_key(rom), timeout_seconds=PROMOTION_LOCK_TIMEOUT_SECONDS
|
|
):
|
|
return await _promote(db_rom_handler.get_rom(rom.id) or rom)
|
|
|
|
|
|
async def _promote(rom: Rom) -> Rom:
|
|
if not rom.has_simple_single_file:
|
|
return rom
|
|
await asyncio.to_thread(assert_promotable, rom)
|
|
|
|
folder = rom.fs_name_no_ext
|
|
fs_path = rom.fs_path
|
|
fs_name = rom.fs_name
|
|
origin = f"{fs_path}/{fs_name}"
|
|
dest_dir = f"{fs_path}/{folder}"
|
|
final = f"{dest_dir}/{fs_name}"
|
|
staged = f"{fs_path}/{TEMP_FILE_PREFIX}{fs_name}"
|
|
extensionless = folder == fs_name
|
|
|
|
# Extensionless dest_dir is the file's own path; only a directory collides.
|
|
dest_path = fs_rom_handler.validate_path(dest_dir)
|
|
collision = dest_path.is_dir() if extensionless else dest_path.exists()
|
|
if collision:
|
|
raise RomAlreadyExistsException(folder)
|
|
|
|
# A promotion racing this one from another worker can win the move and own
|
|
# the folder, so undo only what this call did. Removal is recursive, and a
|
|
# folder with anything left in it holds someone else's ROM.
|
|
moved = False
|
|
|
|
async def _drop_dir() -> None:
|
|
path = fs_rom_handler.validate_path(dest_dir)
|
|
if path.is_dir() and not any(path.iterdir()):
|
|
await fs_rom_handler.remove_directory(dest_dir)
|
|
|
|
async def _restore() -> None:
|
|
"""Return the lone file to its original path and drop the new folder."""
|
|
src = next(
|
|
(
|
|
p
|
|
for p in (final, staged)
|
|
if moved and fs_rom_handler.validate_path(p).exists()
|
|
),
|
|
None,
|
|
)
|
|
if src is not None and extensionless:
|
|
if src != staged:
|
|
await fs_rom_handler.move_file_or_folder(src, staged)
|
|
await _drop_dir()
|
|
await fs_rom_handler.move_file_or_folder(staged, origin)
|
|
elif src is not None:
|
|
await fs_rom_handler.move_file_or_folder(src, origin)
|
|
await _drop_dir()
|
|
else:
|
|
await _drop_dir()
|
|
|
|
try:
|
|
if extensionless:
|
|
await fs_rom_handler.move_file_or_folder(origin, staged)
|
|
moved = True
|
|
await fs_rom_handler.make_directory(dest_dir)
|
|
await fs_rom_handler.move_file_or_folder(staged, final)
|
|
else:
|
|
await fs_rom_handler.make_directory(dest_dir)
|
|
await fs_rom_handler.move_file_or_folder(origin, final)
|
|
moved = True
|
|
db_rom_handler.convert_rom_to_folder(rom.id, folder, dest_dir)
|
|
except Exception:
|
|
try:
|
|
await _restore()
|
|
except Exception:
|
|
log.error(f"Failed to roll back folder conversion for ROM {rom.id}")
|
|
raise
|
|
|
|
refetched = db_rom_handler.get_rom(rom.id)
|
|
if refetched is None:
|
|
return rom
|
|
|
|
log.info(
|
|
f"Converted {hl(rom.name or 'ROM', color=BLUE)} [{hl(fs_name)}] "
|
|
f"to folder ROM [{hl(folder)}]"
|
|
)
|
|
return refetched
|