From d9fe7bfaf42453e3f083aaae0bbf3b96c1ea695b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 22 Jul 2022 22:38:10 +1000 Subject: [PATCH] Fix bug in `helpers::create_if_not_exist` Returned `File` must be both readable and writable. Signed-off-by: Jiahao XU --- src/helpers.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index d240772e..5118722a 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -53,13 +53,18 @@ pub fn cargo_home() -> Result<&'static Path, io::Error> { .map(ops::Deref::deref) } +/// Returned file is readable and writable. pub fn create_if_not_exist(path: impl AsRef) -> io::Result { let path = path.as_ref(); - fs::File::options() + let mut options = fs::File::options(); + options.read(true).write(true); + + options + .clone() .create_new(true) .open(path) - .or_else(|_| fs::File::open(path)) + .or_else(|_| options.open(path)) } pub async fn await_task(task: tokio::task::JoinHandle>) -> miette::Result {