From b1907fe8e849ed5050b926e744bfb5032e1a887d Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Thu, 29 Aug 2024 16:00:38 +0300 Subject: [PATCH] vfs: add open_or_create functions --- src/vfs/directory.rs | 11 +++++++++++ src/vfs/file.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/vfs/directory.rs b/src/vfs/directory.rs index 9842b2b..6398ab8 100644 --- a/src/vfs/directory.rs +++ b/src/vfs/directory.rs @@ -88,6 +88,17 @@ pub fn open_dir(path: &str, create: bool, timeout: Option) -> Result Result { + match open_dir(path, false, None) { + Ok(dir) => Ok(dir), + Err(_) => match open_dir(path, true, None) { + Ok(dir) => Ok(dir), + Err(e) => Err(e), + }, + } +} + /// Removes a dir at path, errors if path not found or path is not a directory. pub fn remove_dir(path: &str, timeout: Option) -> Result<(), VfsError> { let timeout = timeout.unwrap_or(5); diff --git a/src/vfs/file.rs b/src/vfs/file.rs index 861d8ea..450fa4d 100644 --- a/src/vfs/file.rs +++ b/src/vfs/file.rs @@ -377,6 +377,17 @@ pub fn open_file(path: &str, create: bool, timeout: Option) -> Result Result { + match open_file(path, false, None) { + Ok(file) => Ok(file), + Err(_) => match open_file(path, true, None) { + Ok(file) => Ok(file), + Err(e) => Err(e), + }, + } +} + /// Creates a file at path, if file found at path, truncates it to 0. pub fn create_file(path: &str, timeout: Option) -> Result { let timeout = timeout.unwrap_or(5);