mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
truncate: process all files when one fails
Should make test truncate/multiple-files.sh pass
This commit is contained in:
committed by
Daniel Hofstetter
parent
47dcbbaa15
commit
d21d02e6ab
@@ -14,6 +14,7 @@ use std::path::Path;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
|
||||
use uucore::format_usage;
|
||||
use uucore::show_if_err;
|
||||
use uucore::translate;
|
||||
|
||||
use uucore::parser::parse_size::{ParseSizeError, Parser, allow_list_with_all_suffixes};
|
||||
@@ -284,8 +285,10 @@ fn truncate(
|
||||
));
|
||||
}
|
||||
|
||||
// Process every file: a failure on one (e.g. a directory) must not
|
||||
// prevent the remaining files from being truncated.
|
||||
for filename in filenames {
|
||||
file_truncate(no_create, reference_size, &mode, filename)?;
|
||||
show_if_err!(file_truncate(no_create, reference_size, &mode, filename));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -404,6 +404,19 @@ fn test_no_such_dir() {
|
||||
.stderr_contains("cannot open 'a/b' for writing: No such file or directory");
|
||||
}
|
||||
|
||||
/// Test that truncate processes every file even if one fails.
|
||||
#[test]
|
||||
fn test_continue_after_error() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("dir");
|
||||
ucmd.args(&["-s", "0", "a", "dir", "b"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("dir");
|
||||
assert!(at.file_exists("a"));
|
||||
assert!(at.file_exists("b"));
|
||||
}
|
||||
|
||||
/// Test that truncate with a relative size less than 0 is not an error.
|
||||
#[test]
|
||||
fn test_underflow_relative_size() {
|
||||
|
||||
Reference in New Issue
Block a user