Repository navigation
fix(gui): auto-clean temp files via RAII guard in plot/validate commands - #114
Merged
Merged
Conversation
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
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.
What
Introduce a
TempFileRAII guard in the Tauri backend so temporary.wind/.gcode/.pngfiles are deleted on all exit paths, fixing leaks inplot_definition,plot_preview, andvalidate_wind_definition.Why
plot_definitiondeleted its temp files only on the happy path — every early-return error path leaked.plot_previewleaked its temp PNG unconditionally (no cleanup at all).validate_wind_definitionleaked on the exec error path. Over a long GUI session these accumulate in the system temp dir.How
TempFileholds a path and removes the file inDrop, 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. (tempfileis also not currently a dependency; this adds none.)output_pathis preserved (no guard); only internally generated temp PNGs are wrapped.plan_windis intentionally left as-is: its temp.gcodeis the returned value consumed by downstream simulate/stream, so it must persist.Verification
cargo fmt --check: clean.cargo clippycould not be run locally (the Tauri build needs GTK/gio-2.0system libs not present in my environment); CI'sgui-ciclippy job is the gate, as for any GUI PR.Closes #106