Skip to content

sort: report a full temporary file by name and exit 2 - #16888

Open
adityawrk wants to merge 2 commits into
uutils:mainfrom
adityawrk:sort-tmp-file-enospc
Open

adityawrk wants to merge 2 commits into
uutils:mainfrom
adityawrk:sort-tmp-file-enospc

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #16851.

A full temporary directory used to print only the errno and exit 1:

sort: No space left on device

The temporary file is now named and the exit status is 2, including when the failing operation is the write that filled the buffer, the flush of that buffer, or the close:

sort: close failed: t/<tempfile>: No space left on device

BufWriter and File both drop those errors. sort now flushes and closes the temporary file itself and maps the error to SortError::TmpFileCloseFailed. Writes to standard output are unchanged, so a full stdout still exits 1.

Testing

  • cargo test -p uu_sort --lib — 21 passed, including the new close-failure tests and tmp_file_enospc_names_the_file_and_exits_2.
  • On macOS arm64, an 8MB APFS volume filled by an external sort:
$ seq 300000 | ./target/debug/sort -S 1k -T /Volumes/tinysort >/dev/null
sort: close failed: /Volumes/tinysort/uutils_sort0yZ6ir/1441: No space left on device
$ echo $?
2
  • tests/by-util/test_sort.rs test_spill_write_error_does_not_panic now expects exit 2, close failed:, the temporary directory, and no panic. That test mounts a tmpfs, so it was not run on this machine.

Also, on this commit:

  • cargo test --test tests --no-default-features --features sort -- test_sort:: — 240 passed, 0 failed.
  • cargo clippy -p uu_sort --all-targets -- -D warnings — clean.
  • The report's own shape, -S 100k against a volume with 80 KiB free:
$ seq 100000 | ./target/debug/sort -S 100k -T "$MNT" >/tmp/out
sort: close failed: /tmp/sort-enospc-mnt-HXae/uutils_sortgjgRBz/1: No space left on device
$ echo $?
2

stdout was empty. seq 20 | ./target/debug/sort -S 1k -T /tmp exited 0 and printed the sorted lines.

@adityawrk

Copy link
Copy Markdown
Author

The first CI runs were cancelled because they shared this commit with #16887. Reopening so the workflows run again.

@adityawrk adityawrk closed this Nov 26, 2026
@adityawrk

Copy link
Copy Markdown
Author

Reopened on d1c1404 so the workflows are not the ones cancelled with #16887.

@adityawrk adityawrk reopened this Nov 26, 2026
@xtqqczze

This comment was marked as resolved.

@adityawrk
adityawrk force-pushed the sort-tmp-file-enospc branch from d147c74 to 8e57d39 Compare November 26, 2026 17:51
@adityawrk

Copy link
Copy Markdown
Author

Squashed onto one commit.

@xtqqczze

Copy link
Copy Markdown
Collaborator

failure on windows:

thread 'tests::tmp_file_enospc_names_the_file_and_exits_2' panicked at src\uu\sort\src\sort.rs:3496:9:
unexpected message: close failed: t/chunk: The printer is out of paper.

@adityawrk

Copy link
Copy Markdown
Author

Errno 28 is ENOSPC on Unix and ERROR_OUT_OF_PAPER on Windows, which is why that test printed "The printer is out of paper." The same assertion failed on WASI. 76e6166 checks the close failed: <path>: <error> format with a StorageFull error instead of a raw errno.

Comment thread src/uu/sort/src/sort.rs
uucore::locale::setup_localization("sort").unwrap();
// 28 is ENOSPC on Linux and macOS.
let error = std::io::Error::from_raw_os_error(28);
// A raw errno is not portable: 28 is ENOSPC on Unix and

@xtqqczze xtqqczze Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A write or close error on a temporary file printed only the errno and
exited 1. GNU sort names that file and exits 2:

    sort: close failed: t/<tempfile>: No space left on device

Flush and close the temporary file explicitly, and report the failure
with its path. On Linux, close can return EINTR after the descriptor
is already closed, so do not retry it.

Fixes uutils#16851
Errno 28 is ENOSPC on Unix and ERROR_OUT_OF_PAPER on Windows, so the
unit test expected "No space left on device" and observed "The printer
is out of paper." Check the close-failed format with a disk-full error
instead of a raw errno.
@sylvestre
sylvestre force-pushed the sort-tmp-file-enospc branch from 76e6166 to 09d7bd5 Compare November 29, 2026 20:55

This branch has not been deployed

No deployments
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.

sort: no file name and exit 1 on ENOSPC in temp dir, GNU exits 2

2 participants