1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 05:57:46 +00:00

sort: handle cases where the output file is also an input file

In such cases we have to create a temporary copy of the input file to prevent
overwriting the input with the output. This only affects merge sort, because it
is the only mode where we start writing to the output before having read all inputs.
This commit is contained in:
Michael Debertol 2021-07-31 20:12:38 +02:00
parent 103a9d52ff
commit 849086e9c5
4 changed files with 119 additions and 36 deletions

View file

@ -1020,3 +1020,13 @@ fn test_separator_null() {
.succeeds()
.stdout_only("a\0z\0z\nz\0b\0a\nz\0a\0b\n");
}
#[test]
fn test_output_is_input() {
let input = "a\nb\nc\n";
let (at, mut cmd) = at_and_ucmd!();
at.touch("file");
at.append("file", input);
cmd.args(&["-m", "-o", "file", "file"]).succeeds();
assert_eq!(at.read("file"), input);
}