1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Properly support --no-create for truncate

This commit is contained in:
Arcterus 2014-01-31 21:31:10 -08:00
parent 4a7778caf1
commit 2001c5c5ee

View file

@ -115,18 +115,10 @@ fn truncate(no_create: bool, io_blocks: bool, reference: Option<~str>, size: Opt
for filename in filenames.iter() {
let filename: &str = *filename;
let path = Path::new(filename);
if !path.exists() && !no_create {
io_error::cond.trap(|_| {
writeln!(&mut stderr() as &mut Writer,
"Failed to create the file '{}'", filename);
os::set_exit_status(1);
}).inside(|| {
File::create(&path);
});
}
io_error::cond.trap(|err| {
writeln!(&mut stderr() as &mut Writer, "{}", err.to_str());
}).inside(|| {
if path.exists() || !no_create {
match File::open_mode(&path, Open, ReadWrite) {
Some(mut file) => {
file.seek(0, SeekEnd);
@ -149,6 +141,7 @@ fn truncate(no_create: bool, io_blocks: bool, reference: Option<~str>, size: Opt
os::set_exit_status(1);
}
}
}
});
}
}