Merge pull request #9129 from mattsu2020/truncate_fix

feat(truncate): allow negative size values for truncation
This commit is contained in:
Daniel Hofstetter 2025-11-03 16:42:25 +01:00 committed by GitHub
commit d2f6996973
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -145,6 +145,7 @@ pub fn uu_app() -> Command {
.long(options::SIZE)
.required_unless_present(options::REFERENCE)
.help(translate!("truncate-help-size"))
.allow_hyphen_values(true)
.value_name("SIZE"),
)
.arg(

View file

@ -386,6 +386,17 @@ fn test_underflow_relative_size() {
assert!(at.read_bytes(FILE1).is_empty());
}
#[test]
fn test_negative_size_with_space() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-s", "-1", FILE1])
.succeeds()
.no_stdout()
.no_stderr();
assert!(at.file_exists(FILE1));
assert!(at.read_bytes(FILE1).is_empty());
}
#[cfg(not(windows))]
#[test]
fn test_fifo_error_size_only() {