Skip to content

Commit

Permalink
remove unused mod
Browse files Browse the repository at this point in the history
� Conflicts:
�	clients/filesystem-fuse/src/main.rs

� Conflicts:
�	clients/filesystem-fuse/src/filesystem.rs
�	clients/filesystem-fuse/src/main.rs
  • Loading branch information
diqiu50 committed Dec 19, 2024
1 parent d32cd6a commit 53e4c4e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
2 changes: 1 addition & 1 deletion clients/filesystem-fuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

41 changes: 5 additions & 36 deletions clients/filesystem-fuse/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileStat>;

/// 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<FileStat>;

/// Read the directory by file id, if the file id is a valid directory, return the file stat list
Expand Down Expand Up @@ -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<FileStat>;

/// 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<FileStat>;

/// Read the directory by file path, if the directory exists, return the file stat list
async fn read_dir(&self, path: &str) -> Result<Vec<FileStat>>;

/// 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<OpenedFile>;

/// 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<OpenedFile>;

/// Create the file by file path and flags, if successful, return the opened file
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion clients/filesystem-fuse/src/fuse_api_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::ffi::{OsStr, OsString};
use std::num::NonZeroU32;
use std::time::{Duration, SystemTime};

pub struct FuseApiHandle<T: RawFileSystem> {
pub(crate) struct FuseApiHandle<T: RawFileSystem> {
fs: T,
default_ttl: Duration,
fs_context: FileSystemContext,
Expand Down
20 changes: 11 additions & 9 deletions clients/filesystem-fuse/tests/fuse_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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<P: AsRef<Path>>(path: P) -> bool {
fs::metadata(path).is_ok()
}

0 comments on commit 53e4c4e

Please sign in to comment.