Skip to content

gallery: report unlistable sub-folders in the model/texture listings instead of silently skipping them - #4529

Open
SebSilent wants to merge 1 commit into
ItsNotRexed:mainfrom
SebSilent:fix/gallery-walk-scan-errors
Open

SebSilent wants to merge 1 commit into
ItsNotRexed:mainfrom
SebSilent:fix/gallery-walk-scan-errors

Conversation

@SebSilent

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #4421 (comment)

What and why

gallery.py _serve_models_json and _serve_textures_json walk the models/textures folders with os.walk
and no onerror. os.walk silently skips a sub-folder it cannot list, so /api/models and /api/textures
returned fewer items with no indication the scan was incomplete. Reproduced on 03b09a0: a models_dir with a
.glb in the root and in a sub-folder lists both; after chmod 000 on the sub-folder the listing drops it and
still returns 200 with no error field. Both walks now pass an onerror that collects the unlistable paths,
and each payload gains a scan_errors list (empty when the scan is complete). This is the os.walk/onerror
completeness gap of #4190 / #4433, adapted to a request handler: surface the skipped folders in the JSON
rather than exit mid-request. #3909 changes the routing only, not these walks.

Tested

Linux, Python 3.14.10, CPU only, no game files (synthetic .glb/.png, local TCPServer as the existing tests).

  • New tests/test_gallery.py::TestGalleryServer::test_unlistable_subfolder_is_reported_not_silently_skipped:
    chmod 000 a models and a textures sub-folder, /api/models and /api/textures report the folders in
    scan_errors while still listing the root assets (skips when the folders are still listable, e.g. running
    as root or on Windows). Red on the base: scan_errors absent (KeyError). Green: whole file 4 OK.
  • python -m compileall -q make_game.py tools tests, git diff --check clean.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (no translator rule changed)
  • Docs updated for any new flag, tool or workflow. (no new flag; the JSON gains an additive scan_errors field)

AI-assisted (Tacit).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 9716c111 on Windows 11: python -I tests/test_gallery.py -> 4 tests, OK (1 skipped); git diff --check clean.

The gallery now reports an unlistable sub-folder in the model/texture listings instead of silently skipping it, and the endpoint/category tests pass. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 9716c111d4 on Linux, Python 3.10, CPU only, synthetic fixtures, no game files: pass.

  • python -I tests/test_gallery.py → 4/4.
  • Negative control on main's tools/gallery.py: 1 error, so the unlistable-sub-folder reporting is covered.
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 9716c11 merged with main 03b09a0 (already up to date) on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass for the code; the new test itself could not run in my environments.

  • tests/test_gallery.py: Windows 4 tests, OK (1 skipped: the new test skips where chmod 000 does not block listing). On my Linux box loopback connections are refused, so the server-based tests fail the same way on main (test_endpoints ConnectionRefused with main's files too); I therefore could not run the new test as written.
  • Instead I drove StudioHandler in-process over a socketpair with the same fixture (a root model, a model sub-folder and a texture sub-folder with mode 000): PR gives /api/models count 1 with scan_errors naming locked_models, and /api/textures with scan_errors naming locked_tex. Negative control: tools/gallery.py from main, same script: the scan_errors key is absent from both responses.
  • Read the diff: the onerror callback only records the path; the walk continues, so the root listing is unchanged. Fixtures are synthetic.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 9716c11. os.walk errors are surfaced in the response for model and texture scans, and the test verifies both endpoints while preserving the accessible root listing.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9716c11 on Windows 11, CPython 3.14.7, CPU only (no GPU, no game files).

python -I tests/test_gallery.py gives 4 tests, OK, with 1 skipped. The skipped test is the new one, because os.chmod does not make a folder unlistable on Windows. Thus I ran the server with two sub-folders that icacls <folder> /deny <user>:(RD) makes unlistable.
At this head, /api/models gives status 200, count 1 and scan_errors with locked_models. /api/textures gives count 1 and scan_errors with locked_tex. With tools/gallery.py from main 03b09a08, the two responses have count 1 and no scan_errors key.

One thing is not complete. The page does not show the new field.
viewer/studio.html is the only reader of these responses. It reads data.models and data.categories at lines 754 to 757, and data.textures at line 894. It does not read scan_errors (git grep -n scan_errors finds it only in tools/gallery.py and tests/test_gallery.py).
Thus a person who uses the gallery sees the same incomplete list as before, with no message.

AI-assisted.

…instead of silently skipping them

os.walk() without onerror drops a directory it cannot list, so the gallery
served a 200 with a short asset list and no hint the scan was incomplete.
Both walks now collect the failure into a scan_errors field the UI can show.

Two regressions: the chmod case (skips where chmod is not enforced) and a
scandir-forced case that runs on every platform.
@SebSilent
SebSilent force-pushed the fix/gallery-walk-scan-errors branch from 9716c11 to 1b195d5 Compare November 23, 2026 03:06
@SebSilent

Copy link
Copy Markdown
Contributor Author

Same story here, chmod does nothing on the runner. Added a scandir-forced regression so the scan_errors guard is exercised on Windows and under root: it locks both sub-folders the same way os.walk would see them and checks the API reports each failure while still listing the root assets. The chmod case stays as the real-filesystem check.

Red/green on the new case: fails against main's gallery.py (no scan_errors in the payload), passes with the fix. Full file: 5 tests OK. Rebased on d0835dd, head now 1b195d5.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 1b195d5 merged with main 98fa503 on Linux (Python 3.12.16): pass for the code, with a coverage limit - tests/test_gallery.py 5 tests: 2 OK, 3 ERROR with ConnectionRefusedError, the 3 that open a loopback HTTP server (test_endpoints, which also fails on main here, and the two new unlistable-subfolder tests); I could not connect to my own 127.0.0.1 listener in this environment at all, so I did not get them to run. Instead I called _serve_models_json/_serve_textures_json directly on a handler stub with os.scandir forced to raise PermissionError for a sub-folder: with the PR each returns count 1 and scan_errors listing the locked folder; with upstream/main tools/gallery.py the same script gives count 1 and no scan_errors key. So the behaviour is confirmed; the HTTP tests themselves are unrun here.

@memorypressure

Copy link
Copy Markdown

Merges cleanly with current main: tools/gallery.py now passes an onerror hook to both os.walk calls and reports failures in a new scan_errors field; test_gallery runs 5 green here with the chmod case executing (re-run). Additive JSON field and only that one test parses the endpoints. No game data; fixtures binary-mode generated bytes. The PR shows no CI checks — worth triggering. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants