diff --git a/clients/filesystem-fuse/Cargo.toml b/clients/filesystem-fuse/Cargo.toml index 047b3e60d5b..7c87434456a 100644 --- a/clients/filesystem-fuse/Cargo.toml +++ b/clients/filesystem-fuse/Cargo.toml @@ -40,7 +40,7 @@ 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"] } -regex = "1.11.1" diff --git a/clients/filesystem-fuse/src/filesystem.rs b/clients/filesystem-fuse/src/filesystem.rs index 31d104824f3..55e6c854b76 100644 --- a/clients/filesystem-fuse/src/filesystem.rs +++ b/clients/filesystem-fuse/src/filesystem.rs @@ -46,7 +46,7 @@ pub(crate) trait RawFileSystem: Send + Sync { /// Get the file stat by file id. if the file id is valid, return the file stat async fn stat(&self, file_id: u64) -> Result; - /// Lookup the file by parent file id and file name, if the file is exist, return the file stat + /// Lookup the file by parent file id and file name, if the file exists, return the file stat async fn lookup(&self, parent_file_id: u64, name: &str) -> Result; /// Read the directory by file id, if the file id is a valid directory, return the file stat list @@ -90,19 +90,19 @@ pub(crate) trait PathFileSystem: Send + Sync { /// Init the file system async fn init(&self) -> Result<()>; - /// Get the file stat by file path, if the file is exist, return the file stat + /// Get the file stat by file path, if the file exists, return the file stat async fn stat(&self, path: &str) -> Result; - /// Get the file stat by file path, if the file is exist, return the file stat + /// Get the file stat by parent file path and file name, if the file exists, return the file stat async fn lookup(&self, path: &str) -> Result; /// Read the directory by file path, if the directory exists, return the file stat list async fn read_dir(&self, path: &str) -> Result>; - /// Open the file by file path and flags, if the file is exist, return the opened file + /// Open the file by file path and flags, if the file exists, return the opened file async fn open_file(&self, path: &str, flags: OpenFileFlags) -> Result; - /// Open the directory by file path and flags, if the file is exist, return the opened file + /// Open the directory by file path and flags, if the file exists, return the opened file async fn open_dir(&self, path: &str, flags: OpenFileFlags) -> Result; /// Create the file by file path and flags, if successful, return the opened file @@ -305,35 +305,4 @@ mod tests { let mut file_stat = FileStat::new_file_filestat("a", "b", 10); file_stat.set_file_id(1, 0); } - - #[test] - fn test_open_file() { - let mut open_file = OpenedFile::new(FileStat::new_file_filestat("a", "b", 10)); - assert_eq!(open_file.file_stat.name, "b"); - assert_eq!(open_file.file_stat.size, 10); - - open_file.set_file_id(1, 2); - - assert_eq!(open_file.file_stat.file_id, 2); - assert_eq!(open_file.file_stat.parent_file_id, 1); - } - - #[test] - fn test_file_entry_manager() { - let mut manager = FileEntryManager::new(); - manager.insert(1, 2, "a/b"); - let file = manager.get_file_entry_by_id(2).unwrap(); - assert_eq!(file.file_id, 2); - assert_eq!(file.parent_file_id, 1); - assert_eq!(file.path, "a/b"); - - let file = manager.get_file_entry_by_path("a/b").unwrap(); - assert_eq!(file.file_id, 2); - assert_eq!(file.parent_file_id, 1); - assert_eq!(file.path, "a/b"); - - manager.remove("a/b"); - assert!(manager.get_file_entry_by_id(2).is_none()); - assert!(manager.get_file_entry_by_path("a/b").is_none()); - } } diff --git a/clients/filesystem-fuse/src/fuse_api_handle.rs b/clients/filesystem-fuse/src/fuse_api_handle.rs index f1398b29438..76af581446b 100644 --- a/clients/filesystem-fuse/src/fuse_api_handle.rs +++ b/clients/filesystem-fuse/src/fuse_api_handle.rs @@ -34,7 +34,7 @@ use std::ffi::{OsStr, OsString}; use std::num::NonZeroU32; use std::time::{Duration, SystemTime}; -pub struct FuseApiHandle { +pub(crate) struct FuseApiHandle { fs: T, default_ttl: Duration, fs_context: FileSystemContext, diff --git a/clients/filesystem-fuse/tests/fuse_test.rs b/clients/filesystem-fuse/tests/fuse_test.rs index d81c667c49c..f83b1ea3c22 100644 --- a/clients/filesystem-fuse/tests/fuse_test.rs +++ b/clients/filesystem-fuse/tests/fuse_test.rs @@ -51,11 +51,9 @@ impl FuseTest { let start_time = Instant::now(); while start_time.elapsed() < timeout { - if let Ok(exists) = fs::exists(&test_file) { - info!("Wait for fuse server ready: {}", exists); - if exists { - return true; - } + if !file_exists(&test_file) { + info!("Wait for fuse server ready",); + return true; } sleep(Duration::from_secs(1)); } @@ -99,7 +97,7 @@ fn test_fuse_filesystem(mount_point: &str) { let test_file = base_path.join("test_create"); let file = File::create(&test_file).expect("Failed to create file"); assert!(file.metadata().is_ok(), "Failed to get file metadata"); - assert!(fs::exists(&test_file).expect("File is not created")); + assert!(file_exists(&test_file)); //test write file fs::write(&test_file, "read test").expect("Failed to write file"); @@ -110,7 +108,7 @@ fn test_fuse_filesystem(mount_point: &str) { //test delete file fs::remove_file(test_file.clone()).expect("Failed to delete file"); - assert!(!fs::exists(test_file).expect("File is not deleted")); + assert!(!file_exists(test_file)); //test create directory let test_dir = base_path.join("test_dir"); @@ -131,11 +129,15 @@ fn test_fuse_filesystem(mount_point: &str) { //test delete file in directory fs::remove_file(&test_file).expect("Failed to delete file"); - assert!(!fs::exists(&test_file).expect("File is not deleted")); + assert!(!file_exists(&test_file)); //test delete directory fs::remove_dir_all(&test_dir).expect("Failed to delete directory"); - assert!(!fs::exists(&test_dir).expect("Directory is not deleted")); + assert!(!file_exists(&test_dir)); info!("Success test") } + +fn file_exists>(path: P) -> bool { + fs::metadata(path).is_ok() +}