mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
ptx: Flush BufWriter
, add context to errors
This commit is contained in:
parent
cba48c0284
commit
bfdde70309
2 changed files with 17 additions and 2 deletions
|
@ -633,7 +633,8 @@ fn write_traditional_output(
|
||||||
let mut writer: BufWriter<Box<dyn Write>> = BufWriter::new(if output_filename == "-" {
|
let mut writer: BufWriter<Box<dyn Write>> = BufWriter::new(if output_filename == "-" {
|
||||||
Box::new(stdout())
|
Box::new(stdout())
|
||||||
} else {
|
} else {
|
||||||
let file = File::create(output_filename).map_err_context(String::new)?;
|
let file = File::create(output_filename)
|
||||||
|
.map_err_context(|| output_filename.maybe_quote().to_string())?;
|
||||||
Box::new(file)
|
Box::new(file)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -673,8 +674,11 @@ fn write_traditional_output(
|
||||||
return Err(PtxError::DumbFormat.into());
|
return Err(PtxError::DumbFormat.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
writeln!(writer, "{output_line}").map_err_context(String::new)?;
|
writeln!(writer, "{output_line}").map_err_context(|| "write failed".into())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.flush().map_err_context(|| "write failed".into())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,3 +163,14 @@ fn test_format() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("\\xx {}{}{a}{}{}\n");
|
.stdout_only("\\xx {}{}{a}{}{}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
#[test]
|
||||||
|
fn test_failed_write_is_reported() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-G")
|
||||||
|
.pipe_in("hello")
|
||||||
|
.set_stdout(std::fs::File::create("/dev/full").unwrap())
|
||||||
|
.fails()
|
||||||
|
.stderr_is("ptx: write failed: No space left on device\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue