From 7cf3dcacbf65a5fe3047a8f4aa48f040ae9ffc0e Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 8 Apr 2024 12:39:42 -0700 Subject: [PATCH] Fix clippy::suspicious_open_options warnings Use .create_new() rather than .create() for cases where we always want to ensure that the file does not already exist, and add .truncate(false) for a case where we do want to open an existing file and don't want to overwrite it. BUG=b:344974550 TEST=tools/clippy Change-Id: Ie82a6db306532c600c140efab3d310b6c7cf25a7 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5604660 Reviewed-by: Alexandre Courbot Commit-Queue: Daniel Verkamp --- disk/src/qcow/mod.rs | 4 ++-- io_uring/tests/uring.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/disk/src/qcow/mod.rs b/disk/src/qcow/mod.rs index 19a044c772..85b96c5048 100644 --- a/disk/src/qcow/mod.rs +++ b/disk/src/qcow/mod.rs @@ -2470,7 +2470,7 @@ mod tests { let _backing_file = OpenOptions::new() .read(true) .write(true) - .create(true) + .create_new(true) .open(&backing_file_path) .unwrap(); @@ -2478,7 +2478,7 @@ mod tests { let level1_qcow_file = OpenOptions::new() .read(true) .write(true) - .create(true) + .create_new(true) .open(&level1_qcow_file_path) .unwrap(); let _level1_qcow_file = QcowFile::new_from_backing( diff --git a/io_uring/tests/uring.rs b/io_uring/tests/uring.rs index bb3cd53e47..381bbbd845 100644 --- a/io_uring/tests/uring.rs +++ b/io_uring/tests/uring.rs @@ -308,8 +308,7 @@ fn fallocate_fsync() { let mut f = OpenOptions::new() .read(true) .write(true) - .create(true) - .truncate(true) + .create_new(true) .open(&file_path) .unwrap(); f.write_all(&buf).unwrap(); @@ -321,6 +320,7 @@ fn fallocate_fsync() { .read(true) .write(true) .create(true) + .truncate(false) .open(&file_path) .unwrap();