Skip to content

fix(mktemp): remove temporary file or directory when name cannot be printed#12889

Open
WaiHlyanMinThein17 wants to merge 2 commits into
uutils:mainfrom
WaiHlyanMinThein17:mktemp-cleanup-on-print-error
Open

fix(mktemp): remove temporary file or directory when name cannot be printed#12889
WaiHlyanMinThein17 wants to merge 2 commits into
uutils:mainfrom
WaiHlyanMinThein17:mktemp-cleanup-on-print-error

Conversation

@WaiHlyanMinThein17

Copy link
Copy Markdown

When mktemp creates a temp file/directory but then fails to print its
name to stdout (e.g. stdout is /dev/full), it left the created entry
behind as an unreachable orphan. GNU mktemp removes it.

Fix: on a print failure, remove the created file or directory before
propagating the error. Best-effort, skipped in dry-run mode. keep()
disables tempfile's auto-cleanup, so removal is manual.

Fixes the GNU test tests/mktemp/write-error.sh. Added a Linux-only
integration test (file and -d cases via /dev/full); verified it fails
without the change and passes with it.

Note: distinct from #10494, which targets shared stdout-error detection.
This is the mktemp-local cleanup the GNU test requires, and is independent.

…rinted

When mktemp fails to write the created file or directory name to stdout
(for example when stdout is /dev/full), it left the created entry behind
as an orphan the caller can never reference. GNU mktemp removes it.

Capture the created path and, on a print failure, remove the file or
directory before propagating the error. The tempfile builder's automatic
cleanup was disabled via keep(), so removal is done manually.

Add a Linux-only integration test that directs stdout to /dev/full and
verifies the created entry is cleaned up. Fixes the GNU test
tests/mktemp/write-error.sh.
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/io-errors (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/rm/isatty (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/mktemp/write-error is no longer failing!

@WaiHlyanMinThein17

Copy link
Copy Markdown
Author

Pushed a follow-up that applies nightly rustfmt import ordering. The earlier style/format failure was a stable-vs-nightly rustfmt import-sort mismatch, not a logic issue; cargo +nightly fmt --all -- --check is clean locally now. The GNU write-error test is confirmed passing by the comparison bot above.

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