fix(tabs): notice any change to or deletion of an open SQL file, and report a failed move to Trash - #3088
Merged
Conversation
datlechin
changed the base branch from
fix/linked-header-utf8-boundary
to
main
September 23, 2026 15:44
…report a failed move to Trash
datlechin
force-pushed
the
fix/file-tab-external-change-detection
branch
from
September 23, 2026 15:48
bb1c779 to
87ccc88
Compare
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
This branch was successfully 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.
Summary
Two defects in tabs backed by an
.sqlfile on disk, both found while investigating #2505:cp -p, Time Machine,rsync -a), a write in the same second as the load, or a file opened with File > Open outside a linked folder got no changed-on-disk notice.Cmd+Sthen wrote over it.Cmd+S.This branch is stacked on #3083 (it touches
FileTextLoader.loadtoo). Review that one first; this diff is the commit on top.Root cause
currentMtime > loadMtime + 0.5 s, so any restore with an older or equal mtime passed. Five load paths also read the date after reading the text, so a write between the two was recorded as already seen.trashLinkedFavoritewastry? FileManager.default.trashItem(...). A tab whose file vanished read the failedstatas "not modified", and Save recreated the file.Fix
FileStamprecords mtime (to the nanosecond), size and inode, taken before the read in every load path (FileTextLoader, File > Open, restore, reopen).SourceFileDiskChange.detectcompares stamps with no tolerance and answers.modifiedor.missing.FileTabBaseline.diskChange(in:)is the single entry point for the save gates, batch save, save on close and the periodic check.loadMtime,externalModificationDetectedand the 0.5 s slack are gone.SourceFileDiskChangeMonitorchecks every file tab when the window becomes key and when a linked folder changes. It reads the stamps off the main actor, so a stalled network volume cannot freeze the window, and drops a result if the tab was saved or reloaded meanwhile.Cmd+Sand Save on close open Save As instead of writing to the old path, and the close finishes once Save As has written the new file.docs/features/sql-files.mdxdescribes when the check runs and the missing-file banner.Tests
SourceFileDiskChangeTests: stamp comparison.FileTabExternalChangeTests: an older copy restored in place, a same-size rewrite with a new inode, an unchanged file, a deleted file, and the stamp travelling in the payload.SourceFileDiskChangeHandlingTests:FileTabBaselineTests,QueryTabManagerDeduplicationTests,TabQueryContentEqualityTests,CommandActionsBulkCloseTests,TabCloseProtectionTests,EditorTabPayloadTests,SessionStateFactoryTests,LinkedSQLFavoriteWriterTestsand theFileTextLoadersuites.No UI automation. Each flow needs a file changed or deleted by another process while the app runs, and the UI-test runner is sandboxed away from the files the app has open. The coordinator tests drive the same entry points (
handleWindowDidBecomeKey,saveSelectedTabWork,saveFile(of:to:),trashLinkedFavorite).Risks
statfor another reason (permissions, an unmounted volume) is reported as deleted or moved.Deliberately not fixed here
Every save writes UTF-8, whatever encoding the file was read in. A Latin-1 or UTF-16 file is rewritten as UTF-8, and a file whose encoding is known only from its
com.apple.TextEncodingextended attribute loses it. A fix that saved in the loaded encoding was written and reviewed, and it made one case worse.Data.write(options: .atomic)drops that attribute, so a Shift-JIS, CP1251 or MacRoman file read back as ISO Latin-1 after one save (measured). It also turned a UTF-16 file identified only by its attribute into little-endian with a byte order mark. It was removed from this PR. A correct fix writes throughNSString.write(to:atomically:encoding:)or sets the attribute itself, and needs a test for each encoding source.