Skip to content

Keep the existing file when a desktop save overwrite fails - #207

Merged
vycdev merged 5 commits into
developfrom
fix/kpal-safe-overwrite
Nov 19, 2026
Merged

vycdev merged 5 commits into
developfrom
fix/kpal-safe-overwrite

Conversation

@vycdev

@vycdev vycdev commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

From the v4.3.0 release review: if you confirmed replacing an existing .kpal palette in the desktop app and the write then failed or came up short, the old file was left empty or partial, even though the app showed an error. Desktop Save As truncated the chosen file before streaming the new contents into it.

Now desktop saves write to a hidden temporary file in the same folder and rename it over the chosen file only after the whole file is written. If the write fails, the temporary file is deleted and the old file keeps its contents. This covers every saveBlobToFile caller: palettes, profiles, PNG/STL/3MF exports, calibration prints and proofs. Cancelling and browser downloads work as before.

The Save dialog only puts the exact chosen file into Tauri's fs scope, so a few small native commands (src-tauri/src/safe_save.rs) do the work. Capabilities are unchanged. The commands:

  • create the temporary file only next to a file that is already in scope, and add just that temporary file to the scope
  • if the destination is a symlink, resolve it first and check the resolved file against the scope, so the target is replaced and the link stays a link
  • refuse the app's local data folder, which the fs plugin denies to the webview by default
  • refuse to replace a read-only file, which the old code also refused
  • keep the temporary file at 0600 while it is being written when it replaces an existing file, then copy the existing file's Unix mode (best effort, so mounts that reject chmod still save)
  • run off the main thread, so flushing a large export does not freeze the UI

Proof: the new overwrite-failure unit test fails on the old code, which leaves the original truncated to {"versi, and passes now. Native tests cover replace, discard, a failed rename, read-only files and file modes. A Tauri mock-runtime IPC test runs the full begin → plugin:fs|open/write → finish sequence against the app's real capabilities and fs scope. It covers files outside the scope, abandoned saves, finished temporary files that can no longer be written, absolute and relative symlinks, and the app-data refusal. I checked it by mutation: removing allow_file(temp), the symlink resolution, the resolve-before-check order or the app-data guard each makes it fail. npm run lint, tsc -b, npm test (1158), cargo test (36, macOS) and npm run test:e2e:all all pass. The Windows and Linux Rust builds are not compiled locally, and CI does not build Rust.

Follow-ups (declined in review): keep Windows ACLs with ReplaceFileW when replacing an existing file. Retry renames that antivirus software briefly blocks on Windows. Clean up temporary files left behind by a crash.

Reviewed with sol-loop: 3 rounds with gpt-6.2-sol. Sol verdict: approved

Council review

Rounds: 3

Delegate Round 1 Round 2 Round 3
Claude Opus 5.5 8/10 9/10 9/10
GPT-6.2 Sol 6/10 8/10 9/10

Created with Claude Opus 5.5 in Claude Code (T3 Code); reviewed by GPT-6.2 Sol and Claude Opus 5.5.

🤖 Generated with Claude Code

vycdev and others added 5 commits November 19, 2026 22:03
Desktop Save As used to truncate the chosen file and stream into it, so a
failed or short write left an existing palette (or profile, image, model)
empty or partial. Saves now stream into a temporary sibling that a small
native command creates inside the fs scope, and rename it over the chosen
file only after the whole blob is written. Failures remove the temporary
file and leave the original untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Flush and rename in async commands so large exports do not block the UI,
replace the file a symlink points to instead of the link, refuse the app's
local data folder that the fs plugin denies, and keep saving when a mount
rejects chmod.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vycdev
vycdev merged commit e9123d6 into develop Nov 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant