Repository navigation
Files(rootdir, atomic=True): atomic writes and the defaults that go with them (#213) - #226
Merged
Merged
Conversation
…ith them (#213) The atomic=True facade of #210 item 2: each value goes through atomic_write (hidden temp file beside the target, then os.replace), so a reader never sees a partial value and a write killed half way leaves the old one whole. It also defaults read_retry=DFLT_RETRY and strict_key_errors=True (explicit values win); write_func and write_open_kwargs conflict with it (ValueError). Temp files are never keys, now also with include_hidden=True. Folders stay with mk_dirs_if_missing (composition tested). Default atomic=False: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ocstring says what is covered (#213 review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thorwhalen
force-pushed
the
files-atomic-213
branch
from
December 1, 2026 15:22
07cf08e to
771853d
Compare
Member
Author
|
Adversarial review (independent Opus subagent): merge once the two tests are fixed for Windows. They failed only on the Windows job, which is continue-on-error: |
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.
Closes #213. Implements item 2 of #210 (the
atomic=Truefacade); items 1, 3 and 4 there stay open.Most of what #213 asks for was already in
dol, but it took knowing three seams:Files(write_func=atomic_write)(#201),read_retry=,strict_key_errors=.atomic_write's temp files were already hidden, and so skipped. Two applications hand-rolled the store anyway. This PR adds one keyword that assembles those seams:What
atomic=Truedoes (onFileBytesPersister, so every file store inherits it):write_func=atomic_write: a hidden temp file beside the target, thenos.replace. A reader sees the old value or the new one, and a killed write leaves the old one whole.read_retry=DFLT_RETRY: Windows refuses the rename while a reader holds the file open.strict_key_errors=True: a failure other than a missing file propagates as itself instead of becoming aKeyError.atomic_write's temp names are never keys, now also withinclude_hidden=True, through the walk filter (_walked_key_filter, so the Files iteration: ~100 µs/file and three walks per list(store); scandir + skip containment for walked keys (~68x) #219 fast path is kept).Conflict rule (#210 asked for one). Explicit
read_retry=/strict_key_errors=win over the facade's defaults.write_func=orwrite_open_kwargs=together withatomic=Trueraise aValueErrorthat points towrite_func=functools.partial(atomic_write, fsync=True, ...)for other write options.Defaults unchanged.
atomic=Falseis the default, and nothing changes without it.Not done here (decided, reversible):
atomic=True. It is a separate concern, already covered bymk_dirs_if_missing, whose failure cleanup also applies here; the composition is tested and documented.Filesalready refuses keys outside the root (.., absolute paths).Tests (
dol/tests/test_files_atomic.py), per the issue's "done when":atomic=Falsethe same test fails 3 out of 3.KeyError; a key outside the root is still refused),TextFilesandJsonFilesgoing through a rename,mk_dirs_if_missingcomposition, and temp skipping withinclude_hidden=True.Full suite: 1090 passed, 11 skipped.
🤖 Generated with Claude Code