Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/uu/sort/src/ext_sort/threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,45 @@ fn write<I: WriteableTmpFile>(
separator: u8,
) -> UResult<I::Closed> {
let mut tmp_file = I::create(file, compress_prog)?;
write_lines(chunk.lines(), tmp_file.as_write(), separator);
write_lines(chunk.lines(), tmp_file.as_write(), separator)?;
tmp_file.finished_writing()
}

fn write_lines<T: Write>(lines: &[Line], writer: &mut T, separator: u8) {
fn write_lines<T: Write>(lines: &[Line], writer: &mut T, separator: u8) -> std::io::Result<()> {
for s in lines {
writer.write_all(s.line).unwrap();
writer.write_all(&[separator]).unwrap();
writer.write_all(s.line)?;
writer.write_all(&[separator])?;
}
Ok(())
}

#[cfg(test)]
mod tests {
use std::io::{self, Write};

use super::*;

struct FailingWriter(io::ErrorKind);

impl Write for FailingWriter {
fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
Err(io::Error::from(self.0))
}

fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

#[test]
fn write_lines_propagates_write_errors() {
let lines = [Line {
line: b"line",
index: 0,
}];

let result = write_lines(&lines, &mut FailingWriter, b'\n');

@xtqqczze xtqqczze Sep 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let result = write_lines(&lines, &mut FailingWriter, b'\n');
let result = write_lines(
&lines,
&mut FailingWriter(io::ErrorKind::StorageFull),
b'\n',
);
error[E0277]: the trait bound `fn(std::io::ErrorKind) -> FailingWriter {FailingWriter}: std::io::Write` is not satisfied

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Once this change has been made could you please rebase.


assert_eq!(result.unwrap_err().kind(), io::ErrorKind::StorageFull);
}
}