Skip to content

NSP script: a game folder on an exFAT drive (AppleDouble files, rmtree) - #476

Closed
v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:nsp-external-drive
Closed

v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:nsp-external-drive

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

What and why

NX2Apple users keep their games on exFAT / FAT external drives, and the fork carries two patches for what that does to scripts/build_ipa_from_nsp.py. This moves them upstream so forks can drop them (#388).

  • AppleDouble files. macOS writes ._<name> beside every file on such a drive. ._Update [<title ID>800].nsp is 4 KB of metadata, but scan_nsps lists files by extension and reads the title ID from the name, so it counted as another update (an untagged update then read as two and was left out of the build). scan_nsps is the only place the script lists game files; it skips names starting with ._.
  • rmtree. On the volume ._x goes away when x is deleted, so the walk lists ._x and then finds it gone. Before Python 3.13 shutil.rmtree passed that FileNotFoundError to the caller, which aborted the removal and left a half-deleted folder that the next copytree / rename failed on. The script's rmtree ("make this path gone") now passes ENOENT and raises every other error. Python 3.13 and later tolerate this in the standard library; the project floor is 3.12, so the handler is still needed.

Part of #388.

Checked

  • Tests: dm/tools/tests/test_nsp_external_drive.py (new: scan with ._ copies of an NSP, XCI, NSZ and XCZ beside the real files; rmtree where deleting x removes ._x, simulated; rmtree still raises PermissionError), with test_docs.py and the other test_nsp_*.py: 81 pass. On Python 3.12 the new rmtree and scan tests fail without the change; on 3.14 only the scan test does, since the standard library already tolerates the race there.
  • Games run: none (no game files needed).
  • Devices and OS: macOS, Python 3.12 and 3.14.

Docs

  • One line in docs/development.md (game folders on exFAT / FAT drives)
  • No game files, keys or data extracted from a game in the change or the attachments

…tolerate entries that vanish in rmtree

macOS writes an AppleDouble `._<name>` beside every file on an exFAT / FAT drive. Its name carries the
game's [title ID], so scan_nsps read `._Update [..800].nsp` as a second update and the folder was
ambiguous. `._*` is skipped now.

The kernel also drops `._x` when `x` is deleted, so shutil.rmtree's walk could list `._x` and then find
it gone; before Python 3.13 that FileNotFoundError aborted the removal and left the folder half deleted.
The script's rmtree now passes ENOENT (the goal, "gone", is reached) and raises everything else.

Part of seedds#388.
seedds added a commit that referenced this pull request Oct 28, 2026
…nd survives their removal (#476)

exFAT and FAT have no extended attributes, so macOS keeps a file's (a
download's quarantine flag) in an AppleDouble `._<name>` beside it and
deletes it with the file. Two things went wrong on such a drive:

- scan_nsps listed `._Update [<title ID>800].nsp`, 4 KB of metadata whose
  name carries the title ID, as a second update; an untagged update then
  read as two and was left out. Names starting with `._` are skipped.
- Deleting `x` takes `._x` with it, so shutil.rmtree's later unlink of the
  listed `._x` raised FileNotFoundError, which before Python 3.13 ended the
  removal and left a half-deleted folder. The script's rmtree passes ENOENT
  through an onexc hook (Python 3.12 is the floor) and raises every other
  error.

Nothing is keyed to a game. On top of the PR: the pre-3.12 onerror branch
is dropped, the test's stand-in unlink joins the partner's directory (it
was correct only for the dir_fd walk), and docs/reference/packing.md has
the entry, linked from docs/development.md and the symptom index.

Checked: on an exFAT disk image (hdiutil -fs ExFAT) main's scan_nsps listed
the `._` copy as an update and deleting `a` removed `._a`; the patched scan
finds one update and rmtree removes a tree holding 55 `._` files.
test_nsp_external_drive.py passes on Python 3.14 and 3.15, all 148
test_nsp_* and test_docs.py pass, and the pinned lint ratchet reports 0 new
findings. Python 3.12 was not available here; the author ran the tests on
3.12, where the rmtree and scan tests fail without the change.

Co-authored-by: v0lumehi <[email protected]>
@seedds

seedds commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Thanks — merged into main as a0b8bdb, with you as co-author.

Both bugs were confirmed on main using an exFAT disk image (hdiutil create -fs ExFAT):

  • scan_nsps listed the ._Update […800].nsp copy as a second loose update, so the real update was left out.
  • Deleting a also removed ._a, so a later delete of ._a failed with ENOENT.

The design is kept as you wrote it. Changes on top:

  • Dead branch removed: the pre-3.12 onerror branch is dropped, since Python 3.12 is the minimum. rmtree now passes onexc=_gone, and _gone takes the exception directly.
  • Test: the stand-in unlink now joins the partner's directory. Before, it found the ._ partner by bare name, which only worked for the dir_fd walk.
  • Docs: an entry in docs/reference/packing.md under "External drives", linked from docs/development.md and the symptom index.

Checked: on the exFAT image, the patched scan finds one update and rmtree removes a tree holding 55 ._ files. The new test passes on 3.14 and 3.15, all test_nsp_* tests and test_docs.py pass, and the pinned lint ratchet shows 0 new findings. Python 3.12 wasn't available here, so the 3.12 run is yours.

@seedds seedds closed this Oct 28, 2026
seedds added a commit that referenced this pull request Oct 28, 2026
title_of falls back to the [title ID] in a file's name when the file holds
no ticket, so scan_nsps took any file with a game's extension and tag for
one of its packages: an AppleDouble `._` copy on an exFAT drive (#476), a
failed download saved under the game's name, a file cut off before its
header. One such file beside an untagged update made it one of two and left
it out.

is_package checks what nx_extract's OpenNsp opens: an XCI / XCZ by the card
header's HEAD at 0x100, else a PFS0 (NSP, NSZ). scan_nsps skips any other
file with a line saying why; `._` files are still skipped without one.
Nothing is keyed to a game.

Checked: dm/tools/tests/test_nsp_scan.py (an XCI base without a ticket, a
tagged HTML page and a truncated XCI beside a real update, a quiet `._`
skip) fails without the change and passes with it; all 150 test_nsp_*,
test_docs.py and test_bug_report.py pass; the pinned lint ratchet reports 0
new findings. is_package accepts all 339 packages on the T7 drive (336 NSPs,
3 XCIs); no NSZ / XCZ there, those are covered by the tests only.
MIsaacM added a commit to MIsaacM/nxnative-lab that referenced this pull request Oct 30, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…nd survives their removal (seedds#476)

exFAT and FAT have no extended attributes, so macOS keeps a file's (a
download's quarantine flag) in an AppleDouble `._<name>` beside it and
deletes it with the file. Two things went wrong on such a drive:

- scan_nsps listed `._Update [<title ID>800].nsp`, 4 KB of metadata whose
  name carries the title ID, as a second update; an untagged update then
  read as two and was left out. Names starting with `._` are skipped.
- Deleting `x` takes `._x` with it, so shutil.rmtree's later unlink of the
  listed `._x` raised FileNotFoundError, which before Python 3.13 ended the
  removal and left a half-deleted folder. The script's rmtree passes ENOENT
  through an onexc hook (Python 3.12 is the floor) and raises every other
  error.

Nothing is keyed to a game. On top of the PR: the pre-3.12 onerror branch
is dropped, the test's stand-in unlink joins the partner's directory (it
was correct only for the dir_fd walk), and docs/reference/packing.md has
the entry, linked from docs/development.md and the symptom index.

Checked: on an exFAT disk image (hdiutil -fs ExFAT) main's scan_nsps listed
the `._` copy as an update and deleting `a` removed `._a`; the patched scan
finds one update and rmtree removes a tree holding 55 `._` files.
test_nsp_external_drive.py passes on Python 3.14 and 3.15, all 148
test_nsp_* and test_docs.py pass, and the pinned lint ratchet reports 0 new
findings. Python 3.12 was not available here; the author ran the tests on
3.12, where the rmtree and scan tests fail without the change.

Co-authored-by: v0lumehi <[email protected]>
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
title_of falls back to the [title ID] in a file's name when the file holds
no ticket, so scan_nsps took any file with a game's extension and tag for
one of its packages: an AppleDouble `._` copy on an exFAT drive (seedds#476), a
failed download saved under the game's name, a file cut off before its
header. One such file beside an untagged update made it one of two and left
it out.

is_package checks what nx_extract's OpenNsp opens: an XCI / XCZ by the card
header's HEAD at 0x100, else a PFS0 (NSP, NSZ). scan_nsps skips any other
file with a line saying why; `._` files are still skipped without one.
Nothing is keyed to a game.

Checked: dm/tools/tests/test_nsp_scan.py (an XCI base without a ticket, a
tagged HTML page and a truncated XCI beside a real update, a quiet `._`
skip) fails without the change and passes with it; all 150 test_nsp_*,
test_docs.py and test_bug_report.py pass; the pinned lint ratchet reports 0
new findings. is_package accepts all 339 packages on the T7 drive (336 NSPs,
3 XCIs); no NSZ / XCZ there, those are covered by the tests only.
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.

2 participants