FS durability API: fsync(path) and sync() - #46
Merged
Conversation
Platform-level half of the durable-writes work, split out of the editor series at the maintainer level: this is shared FS API, not editor code. - util/filesystem.lua: FS.fsync(path) and FS.sync() over a pcall-guarded LuaJIT FFI cdef (open/fsync/close/ sync), degrading to a no-op where the syscalls are unavailable. FS.write stays async by contract — bulk deploy/clone and the user-facing writefile must not stall on the card — with durability as an explicit opt-in for callers that promise it. Vendored nativefs is untouched. - controller/controller.lua: whole-filesystem sync() on love.quit, plus focus(false)/visible(false) handlers, previously skipped, that sync when the app goes to the background. Split from c5866b2 (the editor's per-accept fsync and save-failure refusal follow in the editor series, which consumes this API). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011WEJighCCuSFparAVqjsWH
aldum
reviewed
Jul 21, 2026
| local function focus(f) | ||
| if not f then FS.sync() end | ||
| end | ||
| love.focus = focus |
Owner
There was a problem hiding this comment.
What's this for? Do we have multi-app scenarios?
Collaborator
There was a problem hiding this comment.
Not really, probably just over-defensiveness that is typical for Claude. Should we remove it?
aldum
approved these changes
Jul 21, 2026
aldum
left a comment
Owner
There was a problem hiding this comment.
Honestly, I did not think OS-level disk flushes were the abstraction level we needed to operate at, but alas, better than losing data.
I do have a question though, how does (or not) this work on other platforms, like JS/WASM?
(not a blocker, just interested)
Collaborator
|
@aldum I'll put it into my backlog to test with web and Linux versions. |
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.
Platform-level half of the durable-writes work, split out of #45 at
dsent's request — this is shared FS API, not editor code.
Adds FS.fsync(path) and FS.sync() over a pcall-guarded LuaJIT FFI cdef,
degrading to a no-op where the syscalls are unavailable, plus
whole-filesystem sync on love.quit and on focus/visible loss. FS.write
stays async by contract (bulk deploy/clone and writefile must not stall
on the card); durability is an explicit opt-in for callers that promise
it — the editor's accept path in #45 is the first consumer.
Motivated by real data loss on the device's exfat-dirsync SD card:
the directory entry survived a force-stop while the contents vanished.
#45 depends on this (its tail carries the same API commit so the branch
stays self-contained; merging this first will dedup cleanly).