From 75a06f0ee95e71e1f7cf0135face0d3106a16c7e Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 20 Apr 2023 17:10:40 +0200 Subject: [PATCH] Refactor FileSystemCache::new to only have one ending --- packages/vm/src/modules/file_system_cache.rs | 34 ++++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/vm/src/modules/file_system_cache.rs b/packages/vm/src/modules/file_system_cache.rs index 209a10020f..77b997ab6c 100644 --- a/packages/vm/src/modules/file_system_cache.rs +++ b/packages/vm/src/modules/file_system_cache.rs @@ -76,32 +76,24 @@ impl FileSystemCache { let metadata = base_path .metadata() .map_err(|_e| NewFileSystemCacheError::CouldntGetMetadata)?; - if metadata.is_dir() { - if !metadata.permissions().readonly() { - Ok(Self { - modules_path: modules_path( - &base_path, - current_wasmer_module_version(), - &Target::default(), - ), - }) - } else { - Err(NewFileSystemCacheError::ReadonlyPath) - } - } else { - Err(NewFileSystemCacheError::ExistsButNoDirectory) + if !metadata.is_dir() { + return Err(NewFileSystemCacheError::ExistsButNoDirectory); + } + if metadata.permissions().readonly() { + return Err(NewFileSystemCacheError::ReadonlyPath); } } else { // Create the directory and any parent directories if they don't yet exist. mkdir_p(&base_path).map_err(|_e| NewFileSystemCacheError::CouldntCreatePath)?; - Ok(Self { - modules_path: modules_path( - &base_path, - current_wasmer_module_version(), - &Target::default(), - ), - }) } + + Ok(Self { + modules_path: modules_path( + &base_path, + current_wasmer_module_version(), + &Target::default(), + ), + }) } /// Loads a serialized module from the file system and returns a module (i.e. artifact + store),