Repository navigation
fix(storage): write settings in place when renames are refused - #26711
rafael-rosa-knowcode wants to merge 4 commits into
Conversation
Win32 app isolation refuses every rename in a sandboxed package's data folder, so saving settings through a temporary file and a rename failed on every write: changes were kept in memory only and lost at exit. When the rename is still refused after the retries, write the file in place under the existing write lock and skip the rename for the rest of the run. A damaged file is copied aside instead of moved. Wherever renames work, nothing changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-up. The fallback now triggers only when the rename itself is refused after the retries, not on any access-denied error from the write. While renames are refused, each write still tries one rename, so a brief hold by another program does not leave the app writing in place for the rest of the run. Moving a damaged file aside no longer switches the mode; it is copied when the move is refused. The in-place write puts the new content down in one write and then cuts the old tail, which readers already ignore. The switch is logged once at Warning with the error code, and write retries are logged at Debug. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Second review round. Deleting the temporary file no longer throws over the outcome of the write, so a refused rename still reaches the in-place write. The retry comment sits on the rename path it describes, and two tests now fail if a single refusal switches to in-place writes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
…he temporary-file delete Review follow-up. Any other exception from the in-place write still reaches the write's outer handler, which logs it and keeps the change for a later write, so the behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 249061 found UI Test snapshots differences: Details
|
|
Tick the box to add this pull request to the merge queue (same as
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 249078 found UI Test snapshots differences: Details
|
GitHub Issue: related to unoplatform/studio.live#6221 (not closed by this PR: Studio closes it when it takes the Uno version with this fix)
PR Type:
🐞 Bugfix
Why the sandbox needs this
Win32 app isolation (overview) lets a packaged desktop app run sandboxed, in an AppContainer.
%LOCALAPPDATA%\Packages\<family>\AC).ApplicationDatasettings through a rename.The case: Uno Platform Studio's Windows package is moving from full trust to this sandbox (unoplatform/studio.live#5298).
What changed? 🚀
The bug: in an app packaged with Win32 app isolation (a sandboxed MSIX),
ApplicationData.Current.LocalSettingsis never saved on Skia desktop.SettingsFilewrites a.tmpfile and renames it overLocal.dat.UnauthorizedAccessException).Failed to write settings to …\Local.dat; the change is kept in memory and saved on a later write, so changes are lost at exit..corruptwith a rename. In the sandbox that is refused too, so one damaged file would block every later save.The fix, in
src/Uno.WinRT/Storage/Internal/SettingsFile.skia.cs:.corruptwhen moving it is refused, then rebuilt as before. This doesn't change the write mode.Flow of one save. Default colour: unchanged. Red: what happened before and no longer does. Green: added by this PR.
flowchart TD S1["Set a value"] --> S2["Take the write lock, read Local.dat"] S2 -- "file damaged" --> S3{"Move Local.dat to .corrupt"} S3 -- "refused (before)" --> R1["Every later save fails"]:::removed S3 -- "refused (now)" --> G1["Copy Local.dat to .corrupt"]:::added S3 -- "works" --> S4["Rebuild from the last good copy"] G1 --> S4 S2 -- "file fine" --> S5["Apply the change, write a .tmp file"] S4 --> S5 S5 --> S6{"Rename .tmp over Local.dat"} S6 -- "works" --> S7["Saved"] S7 --> G2["If saves were in place: back to renaming, Info logged"]:::added S6 -- "refused" --> G3{"Renames already refused this run?"}:::added G3 -- "no" --> S8["Retry, up to 5 times"] S8 -- "still refused (before)" --> R2["Error logged; change kept in memory only, lost at exit"]:::removed S8 -- "still refused (now)" --> G4["Write Local.dat in place, under the lock"]:::added G3 -- "yes" --> G4 G4 --> G5["Saved; Warning logged once; later saves try the rename once"]:::added classDef removed fill:#ffebe9,stroke:#cf222e,color:#82071e,stroke-width:2px classDef added fill:#dafbe1,stroke:#1a7f37,color:#044f1e,stroke-width:2pxTrade-off (only where renames are refused): the in-place write is not atomic.
Reviewer's guide
SettingsFile.TryWrite, thenReplaceThroughTemporaryFile(returns the refused rename, ornull),TryWriteInPlace/WriteInPlace,SetDamagedFileAside,NoteRenamesRefused/NoteRenamesWork.moveFileconstructor argument (defaultFile.Move(…, overwrite: true)) so the tests can refuse a rename. Both renames go through it.Serialize(aBinaryWriterover aMemoryStream, same format), and the temporary-file delete intoDeleteTemporaryFileso its failure can't hide the write's outcome.Given_SettingsFile):When_Renames_Are_Refused_Then_The_Value_Is_Saved_In_PlaceWhen_Renames_Are_Refused_Then_Later_Writes_Try_The_Rename_Only_OnceWhen_Renames_Work_Again_Then_Writes_Retry_Them_Fully_AgainWhen_Renames_Are_Refused_And_The_Content_Shrinks_Then_No_Old_Bytes_Are_ReadWhen_Renames_Are_Refused_And_The_File_Is_Damaged_Then_It_Is_Copied_Aside_And_RebuiltWhen_Only_Moving_A_Damaged_File_Aside_Is_Refused_Then_It_Is_Copied_Aside_And_SavedWhen_A_Rename_Is_Refused_Once_Then_It_Is_Retried_Rather_Than_Written_In_PlaceWhen_A_Rename_Fails_For_Another_Reason_Then_The_File_Is_Not_Written_In_PlaceValidation
On
fcaf3d77da8:Uno.UI.UnitTests(net11.0) builds with 0 errors and 0 warnings, analyzers on (UnoFastDevBuild=false).Given_SettingsFile24/24 pass. The first sandbox tests failed before the fix.Uno.UI.UnitTestssuite (on8da7433aa95): 15 failures, all of which also fail on unchangedmasteron the same machine (styles, themes, a time picker). None in storage.UnauthorizedAccessExceptionin the Uno licensing SDK, which is what this relies on.Review items not taken
.bakbackup before the in-place write: it would grow the change, and the torn-write risk above is the one it covers.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code