Repository navigation
Conversation
A commit replaced the whole save folder: it swapped <id>.new and <id> with renameat2(RENAME_EXCHANGE), which gives <id> a new inode. Sync tools such as Syncthing watch the folder with inotify, so their watch stayed on the replaced folder and they missed every save until their next full rescan (hourly by default). plat_rename_swap no longer swaps folders. Every commit now moves the new files into the existing folder one by one, using the crash-safe journal that shared storage already used. The folder stays the same, so sync tools see each new file. A commit cut short by a crash is finished at the next start, so the save is never left half old, half new. Checked: a new test, test_android_saves.py HostSwap, commits a version with a removed file and a new subfolder and checks that the folder keeps its inode, that it ends up with exactly the new files, and that no marker stays. It passes with the fix and fails on the old code. The whole test_android_saves.py passes, including the launcher's JVM tests (JDK 25). plat_android.c and hle_fs.c pass an NDK 28.2.13676358 syntax check with the host's flags (Link's Awakening profile), with no warnings. On an Odin 2 Portal (Snapdragon 8 Gen 2, Android 13), the journal code built with the NDK ran on f2fs (/data/local/tmp, as app-private storage) and on /sdcard, with an inotify watch on the save folder. With RENAME_EXCHANGE the folder got a new inode and the watch saw only IN_MOVE_SELF. With the fix the inode stays and the watch sees each delete, the new subfolder and each file moved in. Not checked: game runs on the phone (system driver, Turnip) with Syncthing, and lint_c.py tidy (no clang-tidy here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Fixes #485. On Android a save commit swapped
<id>.newand<id>withrenameat2(RENAME_EXCHANGE)where the filesystem has it (app-private ext4/f2fs). That gives the save folder a new inode. A sync tool such as Syncthing watches the folder with inotify, so its watch stayed on the replaced folder (which the commit then deletes) and it missed every save until its next full rescan (hourly by default).plat_rename_swap(dm/host/plat/plat_android.c) no longer exchanges folders: two lines removed. Every commit now uses the file-level roll-forward journal that shared storage (FUSE) already used (.pend1, delete what the new version lacks,.pend2, rename each new file over the old one, remove the marker). The folder keeps its inode and each file arrives as a rename into it. A crash after.pend1is finished at the next mount (plat_swap_recover), so the save is still all old or all new. The launcher's restore (SaveStore.java) already uses the same format.save_sync.c, which relies on a real swap, is built only for the Mac.Trade-off: on app-private storage a commit now costs a few marker writes and fsyncs plus one rename per file instead of one syscall. That is cheap for small saves but not for saves with many files (Breath of the Wild has 509). A follow-up PR makes commits copy and move only the changed files.
Not fixed here: on shared storage (FUSE), Android's media provider puts the old file's modification time back about two seconds after a file is renamed over it, so a changed file of the same size keeps its old time and a sync tool's full rescan can still skip it (#571). With this PR the inotify watch sees every commit; the follow-up PR fixes the times.
Reference entry: Commits keep the Android save folder itself; a line in the Link's Awakening note.
Checked
python3 -m unittest test_android_saves(indm/tools/tests) passes, including the launcher's JVM tests (JDK 25). The newHostSwap.test_commit_keeps_the_save_foldercommits a version with a removed file and a new subfolder and checks that the folder keeps its inode, ends up with exactly the new files, and has no marker left. It fails on the old code.plat_android.candhle_fs.cwith the host's flags (Link's Awakening profile): no errors, no warnings./data/local/tmp, the same filesystem as app-private storage) and on/sdcard, with an inotify watch on the save folder:RENAME_EXCHANGE) on f2fs: new inode, and the watch gets onlyIN_MOVE_SELF, no file events;-PnxApp=peanuts -PnxAppId=peanutstest -PnxGames=01006BB00C6F0000), The Legend of Zelda: Link's Awakening 1.1.0 (01006BB00C6F0000), a copy of an existing save, Turnip T30 (PurpleVK 26.3.0, driver ID 18): played past the file select into the Mysterious Forest at 59-60 fps, no crash, then saved from the System menu. 8 save commits (6 at boot and load with no writes, 2 with the in-game save's writes;savedata0.binchanged). An inotify watch on the save folder (its/sdcardpath, as Syncthing watches it), set before the game started, kept the same inode (375458) throughout and received 32IN_MOVED_TOevents, one per file per commit, and noIN_MOVE_SELF,IN_DELETE_SELForIN_IGNORED. For comparison, the 0.1.7 release's log on the same phone hassave commit #1: … swapped atomically into …from theRENAME_EXCHANGEpath.make -C dm/host/testsfails onmainalready and does not compileplat_android.c), andlint_c.py tidy.Docs
docs/reference/services.mdentry and the game note, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)dm/third_party/, no change todmsh_chain.lock; the branch starts from the currentmain(theandroidbranch named in CONTRIBUTING.md no longer exists)🤖 Generated with Claude Code