Repository navigation
Keep an atomically saved file under the name it was saved as - #52
Merged
Merged
Conversation
Editing a file on the mount made it disappear: `README.md` was gone and `README.md.tmp.194149.5089d5eff10a` was left holding the content. That is the atomic save — write a temp file, rename it over the target — which is how vim, VS Code and most build tools save. The normal case, not an edge case. rename() was not the culprit; it applies the rename locally. The upload of the temp file was still in flight, having started under the temp name, so OneDrive ended up holding the file under that name. The next delta then dragged the temp name back down over the local one: the target vanished and the temp file appeared. No bytes were lost, but it reads exactly like data loss — and a cleanup of "orphaned" temp files would have turned it into the real thing. The row already carries the name the file ended up with, so the upload now compares and corrects the remote to match before writing the row back. Second, smaller, and more dangerous: the `_local_*` branch of rename() deleted the row before re-inserting it. `upsert_item` already evicts whatever holds the new path and updates in place, so the delete bought nothing — and it opened a window in which the row did not exist. An upload of this very file is typically in flight during an atomic save, and one completing inside that window would read "no row" as "deleted while uploading" and remove the file from OneDrive. Tests: a fourth mount round trip performing a real atomic save, with the mock holding the temp file's upload open so the rename lands mid-flight as it does in practice. Asserts the target exists with its content, the temp name is gone, the remote was corrected, and neither reverts once the upload settles. Confirmed to fail before the fix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XfrYQTqjBaP4gDF77Ux1wZ
franzjeger
pushed a commit
that referenced
this pull request
Aug 8, 2026
…not use Three findings from an external conformance suite that states what a cloud file must answer and checks it through a real mount. Five of its eight invariants already passed, including the two hardest — the atomic save and the delete-during-upload races fixed in #52 and #51 both held up under a test that was not written by whoever fixed them. **`chmod +x` returned success and changed nothing.** setattr accepted a mode change and dropped it on the floor, and every attribute answer used a hardcoded 0o644. OneDrive has nowhere to store a mode, so it has to live here or not at all — and the exec bit is the one that matters, because losing it turns a working script into one that will not run with nothing to point at. Modes now live in their own table, the same way local-only symlinks already do, and are held in memory because every stat reads them and a stat must not become a query. The second half of that was worse and only showed up under the suite. The mode is keyed by item ID, and a created file's ID changes when the upload adopts the real OneDrive one. A `chmod +x` made before the upload landed was orphaned under a `_local_*` key nothing would ever ask about again, so it applied right up until the file finished uploading and then quietly stopped. The cache file already moves across adoption; the mode moves with it now. **A download that ended early was served as a short file.** The size of a placeholder comes from the delta pass. If the object changes on OneDrive before anyone reads it, the stream ends at a different length — and we took a completed download to mean a correct one. The reader had asked about a 4096-byte file and got 2048, with no error, and because getattr answers from the cache file the wrong size then became what stat reported from then on. A hydration now either brings what the row promised or it brings nothing: the partial copy is discarded, the row stays a placeholder so the next open tries again, and the reader gets EIO instead of a file that is quietly not what it asked for. **A placeholder claimed disk it was not using.** blocks was computed from size, so a cloud-only file reported a full allocation. That makes `du -sh ~/OneDrive` report the whole drive, which means on-demand cannot be seen to be working even when it is — and the cache-size policy reads those numbers. blocks now comes from the cached copy, and is zero when there is not one. Tests: two mount round trips, one for the mode across an adoption and one for the short download, which also asserts the placeholder's blocks. Both confirmed to fail before the corresponding fix. The five existing round trips and the rest of the suite are unchanged.
franzjeger
added a commit
that referenced
this pull request
Aug 8, 2026
…not use (#55) Three findings from an external conformance suite that states what a cloud file must answer and checks it through a real mount. Five of its eight invariants already passed, including the two hardest — the atomic save and the delete-during-upload races fixed in #52 and #51 both held up under a test that was not written by whoever fixed them. **`chmod +x` returned success and changed nothing.** setattr accepted a mode change and dropped it on the floor, and every attribute answer used a hardcoded 0o644. OneDrive has nowhere to store a mode, so it has to live here or not at all — and the exec bit is the one that matters, because losing it turns a working script into one that will not run with nothing to point at. Modes now live in their own table, the same way local-only symlinks already do, and are held in memory because every stat reads them and a stat must not become a query. The second half of that was worse and only showed up under the suite. The mode is keyed by item ID, and a created file's ID changes when the upload adopts the real OneDrive one. A `chmod +x` made before the upload landed was orphaned under a `_local_*` key nothing would ever ask about again, so it applied right up until the file finished uploading and then quietly stopped. The cache file already moves across adoption; the mode moves with it now. **A download that ended early was served as a short file.** The size of a placeholder comes from the delta pass. If the object changes on OneDrive before anyone reads it, the stream ends at a different length — and we took a completed download to mean a correct one. The reader had asked about a 4096-byte file and got 2048, with no error, and because getattr answers from the cache file the wrong size then became what stat reported from then on. A hydration now either brings what the row promised or it brings nothing: the partial copy is discarded, the row stays a placeholder so the next open tries again, and the reader gets EIO instead of a file that is quietly not what it asked for. **A placeholder claimed disk it was not using.** blocks was computed from size, so a cloud-only file reported a full allocation. That makes `du -sh ~/OneDrive` report the whole drive, which means on-demand cannot be seen to be working even when it is — and the cache-size policy reads those numbers. blocks now comes from the cached copy, and is zero when there is not one. Tests: two mount round trips, one for the mode across an adoption and one for the short download, which also asserts the placeholder's blocks. Both confirmed to fail before the corresponding fix. The five existing round trips and the rest of the suite are unchanged. Co-authored-by: Frank <support@sybr.no>
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.
Editing a file on the mount made it disappear:
README.mdwas gone andREADME.md.tmp.194149.5089d5eff10awas left holding the content.That is the atomic save — write a temp file, rename it over the target — which is how vim, VS Code and most build tools save. The normal case, not an edge case.
What actually happened
rename()was not the culprit. It applies the rename locally, correctly. The problem is upstream of it:Those two lines are the whole bug. The upload started under the temp name and was still in flight when the rename landed, so OneDrive ended up holding the file as
README.md.tmp.…. The next delta then dragged that name back down over the local one — the target vanished and the temp file appeared.No bytes were lost, and the reporter recovered everything from the temp file. But it reads exactly like data loss, and a cleanup of "orphaned" temp files would have turned it into the real thing.
Fix: the row already carries the name the file ended up with, so the upload compares and corrects the remote (
PATCH, i.e.move_item) before writing the row back.Second, smaller, and more dangerous
The
_local_*branch ofrename()deleted the row before re-inserting it:upsert_itemalready evicts whatever holds the new path and updates in place, so the delete bought nothing — and it opened a window in which the row did not exist at all. An upload of this very file is typically in flight during an atomic save, and since #51 a completing upload reads "no row" as "deleted while uploading" and removes the file from OneDrive. Two correct-looking changes that combine into deletion.Testing
A fourth mount round trip performing a real atomic save: create temp, write, close,
renameover the target. The mock holds the temp file's upload open for 2s so the rename lands mid-flight, as it does in practice, rather than depending on machine speed.Asserts the target exists with its content and the temp name is gone immediately after the rename; then that the remote was corrected, the row carries the final name, and neither reverts once the upload settles.
Confirmed to fail before the fix — the assertion that fires is the one naming the consequence:
cargo fmt,cargo clippy --workspace --all-targets -- -D warnings, andONEDRIVE_REQUIRE_FUSE=1 cargo test --workspacepass.Generated by Claude Code