Skip to content

Commit

Permalink
Fix future lint by truncate(false) in touch (#11863)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sholderbach committed Feb 24, 2024
1 parent 96744e3 commit e09b481
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/nu-command/src/filesystem/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
msg: format!("Failed to create file: {err}"),
span: call
Expand Down

0 comments on commit e09b481

Please sign in to comment.