Skip to content

bink_names: name the mount directory it could not read - #7440

Open
fiestorra wants to merge 1 commit into
ItsNotRexed:mainfrom
fiestorra:bink-names-cannot-read-directory
Open

fiestorra wants to merge 1 commit into
ItsNotRexed:mainfrom
fiestorra:bink-names-cannot-read-directory

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

Claimed in the coordination thread after reporting it as a finding: here and here.

What the tool prints

tools/bink_names.py reported a mount directory it could not read by printing the exception:

    except (OSError, ValueError) as error:
        print(f"bink_names: error: {error}", file=sys.stderr)

str(OSError) renders the filename with %r, so on Windows the separators come out doubled. Measured on 5c56d61e2, with os.walk's onerror handed a PermissionError(13, "permission denied", <tmp>\mount\blocked) the way tests/test_bink_names.py does:

bink_names: error: [Errno 13] permission denied: 'C:\\Users\\…\\mount\\blocked'

tests/test_bink_names.py:340 checks that the blocked directory is named, which is the part a person reading the error needs. It passes on POSIX because those paths have no separators to escape, so this only shows up on Windows: the run there ends Ran 33 tests … FAILED (failures=1) on AssertionError: '…\mount\blocked' not found in …. The exit code (1) and the preserved previous report are already correct, and test_unreadable_mount_directory_preserves_the_report checks both; only the wording of that line was wrong.

What it does now

The same shape bink_index.py:392-394 already uses for a failed directory walk — take the path from error.filename, print the reason separately, and fall back to what was asked for when the exception carries no filename:

    except OSError as error:
        path = error.filename or ", ".join(a.mount)
        print(f"bink_names: error: cannot read {path}: {error.strerror or error}", file=sys.stderr)
        return 1
    except ValueError as error:
        print(f"bink_names: error: {error}", file=sys.stderr)
        return 1

The ValueError branch, which carries the bad-row messages the other tests assert, is unchanged. The two other handlers in this tool (--source and --pins) already name their input explicitly, so they were left alone even though the exception text after them repeats the path — repeating is noisy, naming nothing is wrong, and this change is the second case.

The tool's line now reads:

bink_names: error: cannot read C:\Users\…\mount\blocked: permission denied

Tested

CPU-only on 5c56d61e2, Windows 11, CPython 3.13. No device, no game data.

  • python -I tests/test_bink_names.py → Ran 33 tests … OK with the change; with it stashed on the same commit, FAILED (failures=1) on test_unreadable_mount_directory_preserves_the_report — the negative control the file's own docstring describes.
  • python -I -m unittest discover -s tests -p "test_bink_*.py" → Ran 74 tests, one failure, test_bink_index.TestCommandLine.test_a_single_named_file_that_is_not_a_stream_or_rpf_is_refused, which is the stale message expectation tests: match the two expectations bink_index's named-file refusal left behind #7408 fixes; it is red on 5c56d61e2 with nothing applied here, and this branch does not carry that change.
  • docs/dev-tools.md describes --mount as taking list files, an archive or a directory, so the fallback names the --mount arguments when the exception has no filename; the message shape is the one bink_index, awc_names and the other tools in this family already use.

AI-assisted.

An unreadable directory under --mount is reported with the exception's own text, and str(OSError) renders the
filename with %r: on Windows the path comes out as 'C:\\\\Users\\\\...\\\\blocked', with the separators doubled, so it
is no longer the path the user wrote. tests/test_bink_names.py checks that the blocked directory is named and
passes on POSIX because those paths have no separators to escape, which is why the difference only shows up on
Windows. bink_index already handles this shape by taking error.filename and printing the reason itself; this does
the same for read_mount_lists, and keeps the ValueError branch untouched. The exit code and the preserved report
are unchanged; only the wording of that one line.

Verified on 5c56d61: python -I tests/test_bink_names.py is 33/33 OK with the change and fails the same
subtest without it. CPU-only: no device, no game data.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent Windows CPU verification at 7d81daf5d15feb35a42237a8f8ae8a5a015e9909.

Environment & Test Suite

  • Platform: Native Windows 11 x64, Python 3.12 / 3.13, CPU-only.
  • Clean-room: Pure synthetic test fixtures only, zero game data (scripts/check_no_game_data.py passes with exit 0).

Verification

  • Confirmed baseline failure on upstream/main (e36d4c456):
    • python -I tests/test_bink_names.py: test_unreadable_mount_directory_preserves_the_report failed on Windows due to str(OSError) formatting error.filename with %r, escaping backslashes (C:\\Users... vs C:\\\\Users...).
  • With PR #7440 applied:
    • python -I tests/test_bink_names.py: 33/33 passed in 0.24s, OK.
    • Verified error line format: bink_names: error: cannot read <path>: <reason> properly preserves the unescaped path as written, aligning with bink_index.py.
  • Merges cleanly into current upstream/main (e36d4c456) with zero conflicts.
  • python -I -m compileall tools/bink_names.py tests/test_bink_names.py: clean, exit 0.
  • git diff --check: clean (0).

LGTM. Approved.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified: passes all 33 tests in tests/test_bink_names.py. Using error.filename and strerror formatting avoids Python %r repr escaping on Windows paths, matching the clean error reporting in bink_index.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown

Independent Windows/Python 3.10 review on 7d81daf5d15feb35a42237a8f8ae8a5a015e9909:

  • git diff --check HEAD^ HEAD is clean.
  • Passed python -I tests/test_bink_names.py: 33/33.
  • The change correctly separates OSError from the existing ValueError path; error.filename preserves the readable Windows path while strerror preserves the actual reason.

The wider test_bink_*.py discovery run has one failure in test_bink_index on a stale expected wording (Bink 2 stream vs Bink 2 stream (KB2)). It reproduces outside this one-file PR and is unrelated to the bink_names change.

@MiguelMatMar

Copy link
Copy Markdown

Tested 7d81daf on Windows 11 Pro es-ES, CPython 3.14.2, CPU only, no game data: pass.

  • python -I tests/test_bink_names.py: 33 tests OK on this head.
  • With only tools/bink_names.py reverted to main: failures=3 on Windows (test_unreadable_mount_directory_preserves_the_report and both subtests of test_refuses_to_overwrite_input_inside_source_or_mount_directory). So main is red here on Windows today, and this PR fixes it.

Code read: error.filename or ', '.join(a.mount) keeps a message for an OSError without a filename, and ValueError keeps its old one-line form. LGTM.

(AI-assisted check, Claude Code.)

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.

5 participants