diff --git a/clients/filesystem-fuse/Cargo.toml b/clients/filesystem-fuse/Cargo.toml index 7c87434456a..2d02639fc4a 100644 --- a/clients/filesystem-fuse/Cargo.toml +++ b/clients/filesystem-fuse/Cargo.toml @@ -40,7 +40,5 @@ fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] } futures-util = "0.3.30" libc = "0.2.168" log = "0.4.22" -regex = "1.11.1" tokio = { version = "1.38.0", features = ["full"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } - diff --git a/clients/filesystem-fuse/src/memory_filesystem.rs b/clients/filesystem-fuse/src/memory_filesystem.rs index bba19604e33..66142da8131 100644 --- a/clients/filesystem-fuse/src/memory_filesystem.rs +++ b/clients/filesystem-fuse/src/memory_filesystem.rs @@ -61,19 +61,19 @@ impl MemoryFileSystem { #[async_trait] impl PathFileSystem for MemoryFileSystem { async fn init(&self) -> Result<()> { - let root = MemoryFile { + let root_file = MemoryFile { kind: Directory, data: Arc::new(Mutex::new(Vec::new())), }; let root_path = PathBuf::from("/"); - self.file_map.write().unwrap().insert(root_path, root); + self.file_map.write().unwrap().insert(root_path, root_file); - let meta = MemoryFile { + let meta_file = MemoryFile { kind: RegularFile, data: Arc::new(Mutex::new(Vec::new())), }; let meta_file_path = Path::new(Self::FS_META_FILE_NAME).to_path_buf(); - self.file_map.write().unwrap().insert(meta_file_path, meta); + self.file_map.write().unwrap().insert(meta_file_path, meta_file); Ok(()) } @@ -100,21 +100,21 @@ impl PathFileSystem for MemoryFileSystem { async fn open_file(&self, path: &Path, _flags: OpenFileFlags) -> Result { let file_stat = self.stat(path).await?; - let mut file = OpenedFile::new(file_stat.clone()); - match file.file_stat.kind { - Directory => Ok(file), + let mut opened_file = OpenedFile::new(file_stat); + match opened_file.file_stat.kind { + Directory => Ok(opened_file), RegularFile => { let data = self .file_map .read() .unwrap() - .get(&file.file_stat.path) + .get(&opened_file.file_stat.path) .unwrap() .data .clone(); - file.reader = Some(Box::new(MemoryFileReader { data: data.clone() })); - file.writer = Some(Box::new(MemoryFileWriter { data: data })); - Ok(file) + opened_file.reader = Some(Box::new(MemoryFileReader { data: data.clone() })); + opened_file.writer = Some(Box::new(MemoryFileWriter { data: data })); + Ok(opened_file) } _ => Err(Errno::from(libc::EBADF)), } @@ -125,36 +125,28 @@ impl PathFileSystem for MemoryFileSystem { } async fn create_file(&self, path: &Path, _flags: OpenFileFlags) -> Result { - { - let file_map = self.file_map.read().unwrap(); - if file_map.contains_key(path) { - return Err(Errno::from(libc::EEXIST)); - } - }; + self.check_file_exist(path)?; + let mut file_map = self.file_map.write().unwrap(); - let mut file = OpenedFile::new(FileStat::new_file_filestat_with_path(path, 0)); + + let mut opened_file = OpenedFile::new(FileStat::new_file_filestat_with_path(path, 0)); let data = Arc::new(Mutex::new(Vec::new())); self.file_map.write().unwrap().insert( - file.file_stat.path.clone(), + opened_file.file_stat.path.clone(), MemoryFile { kind: RegularFile, data: data.clone(), }, ); - file.reader = Some(Box::new(MemoryFileReader { data: data.clone() })); - file.writer = Some(Box::new(MemoryFileWriter { data: data })); + opened_file.reader = Some(Box::new(MemoryFileReader { data: data.clone() })); + opened_file.writer = Some(Box::new(MemoryFileWriter { data: data })); - Ok(file) + Ok(opened_file) } async fn create_dir(&self, path: &Path) -> Result { - { - let file_map = self.file_map.read().unwrap(); - if file_map.contains_key(path) { - return Err(Errno::from(libc::EEXIST)); - } - } + self.check_file_exist(path)?; let file = FileStat::new_dir_filestat_with_path(path); self.file_map.write().unwrap().insert( @@ -188,7 +180,9 @@ impl PathFileSystem for MemoryFileSystem { return Err(Errno::from(libc::ENOTEMPTY)); } - file_map.remove(path); + if (file_map.remove(path)) { + return Err(Errno::from(libc::ENOENT)); + } Ok(()) } }