Skip to content

Removes the temporary files that stopped exports leave beside plots - #3616

Merged
HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:export-stale-save-temps
Nov 24, 2026
Merged

HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:export-stale-save-temps

Conversation

@travisjhughes

Copy link
Copy Markdown
Contributor

Change summary

The DWF, PDF and SVG exports and the PDF of PUBLISH write to a temporary file beside the output, .<name>.ocs-save-<process id>-<n>.<extension>, and then replace the output with it. When the process ends during the write (an abort, a forced quit, a power loss), the temporary file stays. #3597 made a successful save remove such files of its drawing; the exports do not, so the file of a stopped export stays in the folder. A PUBLISH set of many sheets can make a large file.

With this change, each successful export removes the temporary files of earlier exports to the same file that nothing has written to for an hour. It is the same cleanup as for a save (remove_stale_save_temps).

What specifically changed

Two commits: the change, then its tests.

  • src/io/dwf_export.rs (export_dwf_pages), src/io/svg_export.rs (write_svg_atomically), src/io/pdf_export.rs (write_pdf_atomically), src/io/pdf_publish.rs (PublishPdf::finish): after the replace succeeds, each calls remove_stale_save_temps(path). These are all the callers of replace_save_file other than the save, which calls it already.
  • An SVG export of more than one page writes <stem>-1.svg, <stem>-2.svg, ...; each page file cleans its own temporary files.
  • src/io/mod.rs: the doc comment of remove_stale_save_temps names the exports too. The tests commit adds stopped_save_temp(path) (test builds only), which writes the temporary file of a save or export of path that stopped two hours ago.

Testing

On main 063aea515.

  • New tests, one for each writer: a_dwf_export_removes_the_temporary_file_of_a_stopped_export, an_svg_export_removes_the_temporary_file_of_a_stopped_export, a_pdf_export_removes_the_temporary_file_of_a_stopped_export, a_published_set_removes_the_temporary_file_of_a_stopped_publish. Each puts the temporary file of a stopped export beside the output, exports, and checks that the output exists and the temporary file is gone. Each fails without the change: the temporary file stays. The test of Removes the temporary files that stopped saves leave beside drawings #3597 covers which files the cleanup keeps (younger files, other drawings, other names).
  • Before and after (cargo test --workspace --locked --no-fail-fast, cargo check --workspace --all-targets, clippy, the wasm32 check, rustfmt on the changed files, the golden file): 8,159 passed and 0 failed before; 8,163 passed and 0 failed after. The 4 new tests are the only difference. Warnings, the wasm32 check, clippy and the golden file are the same. Three of the five files have rustfmt drift on main; this change adds none.
  • Fault injection with cargo mutants on the changed lines: 5 mutants, 5 caught, 0 missed.

Not covered

  • Windows. I ran the tests on macOS only. The CI run on Windows shows the result.
  • A stopped export to a file that is not exported again keeps its temporary file. The same is true for a save.
  • The three copies of write-then-replace in the DWF, SVG and PDF writers stay three copies. One shared function would be a separate change.

Impact to Contributors

None.

Co-Authored-By: Claude

The DWF, PDF and SVG exports and the PDF of PUBLISH write to a temporary
file beside the output and then replace the output with it. When the
process ends during the write, the temporary file stays. After each
successful replace, the four writers now call remove_stale_save_temps,
as a save does since HakanSeven12#3597: the temporary files of earlier exports to
the same file that nothing wrote to for an hour are removed.

Co-Authored-By: Claude
One test for each writer: DWF, SVG, PDF and the PDF of PUBLISH. Each
puts the temporary file of an export that stopped two hours ago beside
the output, exports, and checks that the output exists and the
temporary file is gone. The helper stopped_save_temp (test builds only)
writes that file.

Co-Authored-By: Claude
@HakanSeven12
HakanSeven12 merged commit e7686cf into HakanSeven12:main Nov 24, 2026
6 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.

2 participants