Fix future lint by truncate(false) in touch (#11863)

The following clippy lint on nightly would complain:
- https://rust-lang.github.io/rust-clippy/master/#/suspicious_open

We don't want to alter the content in `touch` or truncate by not
writing. While not fully applicable, may be good practice for
platforms/filesystems we are not aware of.
This commit is contained in:
Stefan Holderbach 2024-02-25 00:02:48 +01:00 committed by GitHub
parent 96744e3155
commit e09b4817e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -136,7 +136,12 @@ impl Command for Touch {
} }
} }
if let Err(err) = OpenOptions::new().write(true).create(true).open(&item) { if let Err(err) = OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(&item)
{
return Err(ShellError::CreateNotPossible { return Err(ShellError::CreateNotPossible {
msg: format!("Failed to create file: {err}"), msg: format!("Failed to create file: {err}"),
span: call span: call