Skip to content

fix(gui): auto-clean temp files via RAII guard in plot/validate commands - #114

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/gui-temp-file-cleanup
Jun 24, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/gui-temp-file-cleanup

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

What

Introduce a TempFile RAII guard in the Tauri backend so temporary .wind/.gcode/.png files are deleted on all exit paths, fixing leaks in plot_definition, plot_preview, and validate_wind_definition.

Why

plot_definition deleted its temp files only on the happy path — every early-return error path leaked. plot_preview leaked its temp PNG unconditionally (no cleanup at all). validate_wind_definition leaked on the exec error path. Over a long GUI session these accumulate in the system temp dir.

How

  • TempFile holds a path and removes the file in Drop, covering success and every ? early return. It holds only the path, no open handle, so the CLI subprocess can create/overwrite the file freely — avoiding the Windows sharing violations that an open-handle approach (tempfile::NamedTempFile) would cause when the subprocess writes the same path. (tempfile is also not currently a dependency; this adds none.)
  • A caller-supplied output_path is preserved (no guard); only internally generated temp PNGs are wrapped.
  • plan_wind is intentionally left as-is: its temp .gcode is the returned value consumed by downstream simulate/stream, so it must persist.

Verification

  • cargo fmt --check: clean.
  • Unit tests for the guard (removed on drop; drop is safe when the file is missing).
  • Note: cargo clippy could not be run locally (the Tauri build needs GTK/gio-2.0 system libs not present in my environment); CI's gui-ci clippy job is the gate, as for any GUI PR.

Closes #106

plot_definition deleted its temp files only on the happy path, leaking on
every early-return error path; plot_preview leaked its temp PNG
unconditionally; validate_wind_definition leaked on the exec error path.

Introduce a `TempFile` RAII guard whose Drop removes the file — covering
success and all `?` early returns. It holds only the path (no open handle),
so the CLI subprocess can create/overwrite the file freely, avoiding the
Windows sharing violations a `NamedTempFile`-style open handle would cause.

A caller-supplied output_path is preserved (no guard); only internally
generated temp PNGs are cleaned. plan_wind is intentionally left as-is: its
temp .gcode is the returned value consumed by downstream simulate/stream.

Adds unit tests for the guard (removed on drop; drop is safe when the file
is missing).

Closes #106
@CameronBrooks11 CameronBrooks11 added rust Pull requests that update Rust code tauri Pull requests that update Tauri code labels Jun 24, 2026
@CameronBrooks11
CameronBrooks11 merged commit 01063be into main Jun 24, 2026
21 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/gui-temp-file-cleanup branch June 24, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code tauri Pull requests that update Tauri code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up Tauri temp files created by plot_definition

1 participant