refactor(backup): race fix, env sanitization, restore flow#1246
Merged
Conversation
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
Follow-up polish for the backup/restore feature merged in #1211. Addresses every blocking and smaller issue called out in the review. One concern per commit so the history is bisect-friendly.
Blocking fixes
ProcessPostgresDumpRunner— termination handler could run between theprocess.isRunningcheck and the continuation assignment inresult, leaving the awaiter hung forever. Both branches now serialize throughstateLock, and the termination outcome is cached so a lateawait resultreturns the buffered value instead of stalling.Localizable.xcstringskeys left over from the dump↔backup rename (Choose Backup File,Save Backup,Choose where to save the backup of "%@",Select a backup file created with...,pg_dump exited with code %d,pg_restore exited with code %d,Backups are only supported...,Restore is only supported...,Connect to the database before starting a backup/restore,A backup/restore is already running, ASCIIBackup Dump.../Restore Dump...). The strings catalog is back in sync with the code.Backup Dump…,Restore Dump…) to match the primary button label.[0.40.0](already shipped without this feature) to[Unreleased], and rewrote them to match the menu names.Polish
pg_dumpandpg_restorenow receive onlyPATH,HOME,USER,LOGNAME,SHELL,TMPDIR,LANG,LC_ALLplusPGPASSWORD/PGSSLMODE. No more ambient libpq env leaking through.stderrCapfield; readscommand.stderrByteCapdirectly inside the readability handler.MainContentCommandActions.restoreDatabase()opensNSOpenPanelon the main window first; only after the user picks a file does it setcoordinator.activeSheet = .restoreDatabase(fileURL:).ActiveSheet.restoreDatabasecarries the URL, andRestoreDatabaseFlowno longer needs a.needsSourceplaceholder phase.BackupResultSheet's failure case now uses a height-cappedScrollViewwith monospaced text instead oflineLimit(8), so multi-screenpg_restorestderr is readable without breaking the sheet layout.PostgresDumpService.estimatedDatabaseSizeusesexecuteParameterized(query: "SELECT pg_database_size($1)", parameters: [database])instead of string-escaping.DatabaseSwitcherSheet.Mode.switch(keyword-escaped) renamed to.switching.PostgresDumpServiceexposesstateUpdates()returning anAsyncStream<PostgresDumpState>(eager subscription viamakeStream()so transitions aren't dropped). State-machine tests await the next matching state from the stream instead of polling.nonisolatedstatic helpers —buildCommand,minimalEnvironment,pgSSLMode,inheritedEnvironmentKeysare pure and now correctly markednonisolated, so command-builder tests compile.FakeDumpRunnerre-entrant — buffers the outcome iffinish()is called beforeresultis awaited, mirroring the production fix.DataGridRowViewSetValueTests—@MainActor-annotated and imports sorted so the test target compiles (pre-existing regression from fix(datagrid): edit date cells inline and add date presets to Set Value #1233, blocking the whole test suite).Test plan
swiftlint lint --strictclean on every changed file.xcodebuild buildsucceeds (the twoRunning SwiftLint for CodeEditSourceEditor/CodeEditTextViewfailures are the known headless plugin-sandbox issue, unrelated).PostgresDumpServiceCommandTests(8 cases including newenvironmentIsMinimal()) all pass.PostgresDumpServiceStateMachineTests(5 cases) all pass.DataGridRowViewSetValueTests(7 cases) all pass.