Skip to content

Report directory scan failures in AWC shorts export - #6664

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
david-x3d:fix/awc-shorts-walk
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
david-x3d:fix/awc-shorts-walk

Conversation

@david-x3d

Copy link
Copy Markdown
Contributor

Stop on a source directory traversal error instead of silently omitting the inaccessible subtree and publishing a partial catalog.

Coordination claim

Testing

13 passed; simulated a permission error and confirmed no output directory was created.

Linux, CPU-only, using synthetic inputs.

@AsgerCode

Copy link
Copy Markdown

Tested a493d0c on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass (the code is correct, but it duplicates #2900, see below)

What I ran:

  • python -I tests/test_awc_shorts.py: 13 tests, OK. tests/test_csv_line_endings.py (2) and tests/test_pool_workers.py (11), which also use awc_shorts: OK. python -m compileall -q tools/awc_shorts.py: OK.
  • Merge with current main: clean. The PR is based on main 1cc6e3c, and main has no new commits.
  • Negative control: the PR adds no test, so no test fails with main's awc_shorts.py. The 13 existing tests pass with both versions.

By hand, with a real scan error and no mocks. C:\System Volume Information cannot be listed by this account (WinError 5), and a junction to it needs no admin rights. The source tree was one synthetic bank (build_music_bank from the tests) plus locked as a junction to that folder:

Case this PR main
source is C:\System Volume Information exit 2, cannot list C:\System Volume Information: Access is denied, no out exit 0, 0 banks, header-only shorts.csv written
junction src\locked, --jobs 1 and --jobs 2 exit 2, cannot list ...\src\locked: Access is denied, no out exit 0, 1 banks, partial catalog
same, with an old shorts.csv in out exit 2, old catalog kept exit 0, old catalog replaced by the partial one
same tree without the junction exit 0, 1 row exit 0, 1 row

Points:

  1. No regression test. Here is a test that passes on this head and fails on main (AssertionError: 0 != 2). It patches os.scandir for one real subfolder, so the catalog staging (tempfile cleanup, which also uses os.walk) still works:
    def test_unlistable_subdirectory_stops_before_any_output(self):
        src = os.path.join(self.tmp.name, "banks")
        blocked = os.path.join(src, "blocked")
        os.makedirs(blocked)
        self.write(os.path.join("banks", "good.awc"), 0xFC, 480000)
        real_scandir = os.scandir
        def scandir(path="."):
            if os.path.normcase(os.fspath(path)) == os.path.normcase(blocked):
                raise PermissionError(13, "Permission denied", blocked)
            return real_scandir(path)
        with mock.patch.object(shorts.os, "scandir", scandir), \
                contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()) as err:
            status = shorts.main([src, self.out, "--jobs", "1"])
        self.assertEqual(status, 2)
        self.assertIn("blocked", err.getvalue())
        self.assertFalse(os.path.exists(self.out))
  2. The exit code is 2. In this tool, the other runtime OSError cases (an unreadable bank, cannot create, cannot write) return 1. The same scan failure also returns 1 in tools/awc_opus.py and tools/awc_manifest.py.

Overlap: #2900 (awc_shorts: create per-bank folders only on export and surface scan errors) makes this same change: onerror that raises in _banks, and OSError caught in main() before shorts.csv. #2900 also has a test for it and returns 1. It was claimed and opened on 2026-11-22, one day before this PR. The two PRs conflict in tools/awc_shorts.py. #2900 also conflicts with main now, in export_bank. This PR merges cleanly with the other open awc_shorts PRs (#6647, #6775, #5529, #6822).

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested a493d0c merged with main 8575d36 on Linux/Python 3.12.16: pass

Merge was clean (tools/awc_shorts.py only). The PR adds no test, so I exercised the change by hand.

  • python -I tests/test_awc_shorts.py (existing): OK.
  • Source folder holding ok/a.awc (empty file) and a subfolder locked/ with mode 000, run as python -I tools/awc_shorts.py <src> <out>: with the PR it prints awc_shorts: cannot list <src>/locked: Permission denied and exits 2. Control (tools/awc_shorts.py restored from upstream/main, same inputs): the unreadable folder is skipped silently, skip ok/a: not a little-endian AWC, 1 banks: 0 short ..., exit 0. PR version restored afterwards.

Diff read: os.walk gets an onerror that re-raises, and main catches the OSError and exits 2 with one message, so an unreadable subfolder no longer yields a partial bank list that looks like a clean run. The no-test caveat stands: nothing in the repository pins this behaviour.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

tools/awc_shorts.py::_banks passes onerror=scan_failed to os.walk, re-raising directory errors instead of silently treating unreadable folders as empty. main wraps the _banks call and reports awc_shorts: cannot list <path>: <reason> on stderr with exit 2. Previously a permission failure produced an incomplete bank list that looked like a successful but empty export.

Why merge

An unreadable directory under the source tree currently vanishes from results with a zero exit status, so a partial export is indistinguishable from a complete one. Surfacing the exact failing path makes the failure actionable. The change is confined to the directory-scanning path; file discovery order and export logic are unchanged.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

tools/awc_shorts.py::_banks passes onerror=scan_failed to os.walk, re-raising directory errors instead of silently treating unreadable folders as empty. main wraps the _banks call and reports awc_shorts: cannot list <path>: <reason> on stderr with exit 2. Previously a permission failure produced an incomplete bank list that looked like a successful but empty export.

Why merge

An unreadable directory under the source tree currently vanishes from results with a zero exit status, so a partial export is indistinguishable from a complete one. Surfacing the exact failing path makes the failure actionable. The change is confined to the directory-scanning path; file discovery order and export logic are unchanged.

Verdict: Approve

@shayderrr
shayderrr merged commit 55ba30c into ItsNotRexed:main Nov 23, 2026
Kosmabb8 added a commit to Kosmabb8/Leonida that referenced this pull request Nov 23, 2026
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.

4 participants