Repository navigation
fix(settings): replace configuration files atomically - #1072
Open
abhinavrastogi2627 wants to merge 1 commit into
Open
abhinavrastogi2627 wants to merge 1 commit into
abhinavrastogi2627 wants to merge 1 commit into
Conversation
Write settings to a private temporary file beside the destination, then sync, close and rename it. Existing readers keep the previous complete JSON, and serialization failures leave the saved configuration intact. Preserve settings symlinks and clean up temporary files on errors. Refs tursodatabase#911
This branch has not been deployed
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.
Problem
Settings persistence currently truncates
settings.jsonbefore writing it. Another CLI process can read an empty or partial document, and a serialization error can erase the previous valid configuration.Change
Write to a mode-0600 temporary file in the destination directory, sync and close it, then replace the settings file by rename. Preserve a configured symlink by replacing its target, and remove temporary files on failure. Record the resolved configuration path after initial loading/creation so the first save also uses this path.
Validation
go test -race ./internal/settings -count=10, including original permissions coverage, symlink preservation and failed-replacement cleanup.go test ./...has one failure,TestGetReservedBytes(12versus expected0); the same test fails identically on unchanged upstreamcc95e98. The complete suite passes when that known baseline failure is skipped.go vet ./...,go build ./..., Staticcheck 2025.1.1, the workflow's pinned sqlclosecheck, andgit diff --checkpass.go mod tidyproduces no dependency changes.Limits
Atomic replacement prevents torn reads; this does not merge concurrent writers' independent updates. Rename atomicity depends on the operating system/filesystem, and this change does not claim power-loss durability of the parent directory or Windows validation. Initial configuration creation and explicit
--reset-configretain their existing behavior.Fixes #911