Repository navigation
fix(core): guard saves against external overwrite (#6) - #22
Open
Yan123-tech wants to merge 1 commit into
Open
Yan123-tech wants to merge 1 commit into
Yan123-tech wants to merge 1 commit into
Conversation
…#6) When a document's file is modified on disk between load and save, `save()` overwrote the change without warning. `Document.save()` now captures the on-disk mtime at `load`, compares it on save, and throws `DocumentError.changedOnDisk` when the file is newer (unless `force: true`). - Document: `fileModificationDate` at load; baseline refreshed after each save; new `reloadFromDisk()`/`revert()`; `save(force:)` keeps the no-arg call sites working. - AppState: `performSave` routes `.changedOnDisk` to `pendingExternalChange` (not a generic error); new `revertDocument`/`saveAnyway`; Save All now saves via `performSave` so conflicts surface there too. - MainWindowView: Revert / Save Anyway / Cancel confirmation dialog. - StatusBarView: "⚠️ Changed on disk" hint while a conflict is pending. - DocumentExternalChangeTests (5 tests): conflict blocks save & keeps the buffer dirty, no false positive, baseline resets on save, revert reloads, untitled is never guarded. Verified locally: swift build clean (pre-existing #NoUsage warning only), swift test 78/78 in 18 suites, swift-format lint --strict 0 violations. CI runs Format + Syntax only (see MEMORY.md #1) — build/test are a local gate.
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.
Fixes #6 — a save can no longer silently overwrite a file that changed on disk while open.
What
Document.save()captures the on-disk modification date atloadand compares it on save.If the file on disk is newer (changed since the document was opened),
save()throwsDocumentError.changedOnDiskinstead of overwriting; it only proceeds whenforce: true(the "Save Anyway" escape hatch).
DocumentgainsreloadFromDisk()andrevert()for theReload path, and refreshes the baseline after every successful save so a later genuine
external change is still caught.
Wiring
AppState.performSaveroutes.changedOnDisktopendingExternalChange(not a genericerror); new
revertDocument(Reload from Disk) andsaveAnyway(Save Anyway). Save All isnow driven through
performSaveso the conflict is surfaced there too.MainWindowViewpresents a Revert / Save Anyway / Cancel confirmation dialog bound topendingExternalChange.StatusBarViewshows "Verification (local gate — CI runs Format + Syntax only, see MEMORY.md #1)
swift build— clean (only the pre-existing#NoUsagewarning in an unrelated file).swift test— 78/78 in 18 suites.swift-format lint --strict— 0 violations.Tests:
DocumentExternalChangeTests(5 cases): conflict blocks save & keeps the bufferdirty, no false positive on a stable file, the baseline resets on save,
revertreloads theon-disk version, and untitled documents are never guarded.
Untested by
swift test: the dialog and status-bar hint are thin SwiftUI/AppKit glue in theview layer (see MEMORY.md #18 for why view-update logic is only reachable by running the app).