From 0675cc2f9066bb169dafe0039a51cb64cad85480 Mon Sep 17 00:00:00 2001 From: veeso Date: Fri, 25 Oct 2024 13:08:54 +0200 Subject: [PATCH] fix: don't expose Driver --- remotefs-fuse-cli/src/main.rs | 4 +- remotefs-fuse/src/driver.rs | 6 +-- remotefs-fuse/src/driver/error.rs | 6 --- remotefs-fuse/src/driver/unix/test.rs | 62 ++++++++++++++------------- remotefs-fuse/src/lib.rs | 1 - remotefs-fuse/src/mount.rs | 7 +-- remotefs-fuse/tests/driver/mod.rs | 5 +-- 7 files changed, 42 insertions(+), 49 deletions(-) delete mode 100644 remotefs-fuse/src/driver/error.rs diff --git a/remotefs-fuse-cli/src/main.rs b/remotefs-fuse-cli/src/main.rs index 66da710..1fc8d1f 100644 --- a/remotefs-fuse-cli/src/main.rs +++ b/remotefs-fuse-cli/src/main.rs @@ -1,6 +1,6 @@ mod cli; -use remotefs_fuse::{Driver, Mount, MountOption}; +use remotefs_fuse::{Mount, MountOption}; fn main() -> anyhow::Result<()> { let args = argh::from_env::(); @@ -44,7 +44,7 @@ fn main() -> anyhow::Result<()> { } // Mount the remote file system - let mut mount = Mount::mount(Driver::new(args.remote()), &mount_path, &options)?; + let mut mount = Mount::mount(args.remote(), &mount_path, &options)?; let mut umount = mount.unmounter(); // setup signal handler diff --git a/remotefs-fuse/src/driver.rs b/remotefs-fuse/src/driver.rs index db5fff5..35ee8ad 100644 --- a/remotefs-fuse/src/driver.rs +++ b/remotefs-fuse/src/driver.rs @@ -1,11 +1,9 @@ -mod error; #[cfg(unix)] #[cfg_attr(docsrs, doc(cfg(unix)))] mod unix; use remotefs::RemoteFs; -pub use self::error::{DriverError, DriverResult}; use crate::MountOption; /// Remote Filesystem Driver @@ -36,13 +34,13 @@ impl Driver { /// /// * `remote` - The instance which implements the [`RemoteFs`] trait. /// * `options` - The mount options. - pub fn new(remote: Box) -> Self { + pub fn new(remote: Box, options: Vec) -> Self { Self { #[cfg(unix)] database: unix::InodeDb::load(), #[cfg(unix)] file_handlers: unix::FileHandlersDb::default(), - options: Vec::new(), + options, remote, } } diff --git a/remotefs-fuse/src/driver/error.rs b/remotefs-fuse/src/driver/error.rs deleted file mode 100644 index da01a75..0000000 --- a/remotefs-fuse/src/driver/error.rs +++ /dev/null @@ -1,6 +0,0 @@ -use thiserror::Error; - -pub type DriverResult = Result; - -#[derive(Debug, Error)] -pub enum DriverError {} diff --git a/remotefs-fuse/src/driver/unix/test.rs b/remotefs-fuse/src/driver/unix/test.rs index 47b30a2..2a74742 100644 --- a/remotefs-fuse/src/driver/unix/test.rs +++ b/remotefs-fuse/src/driver/unix/test.rs @@ -7,7 +7,8 @@ use remotefs::fs::{Metadata, UnixPex}; use remotefs::{File, RemoteError, RemoteErrorType, RemoteFs}; use remotefs_memory::{node, Inode, MemoryFs, Node, Tree}; -use crate::{Driver, MountOption}; +use super::Driver; +use crate::MountOption; fn setup_driver() -> Driver { let gid = nix::unistd::getgid().as_raw(); @@ -27,14 +28,15 @@ fn setup_driver() -> Driver { let fs = Box::new(fs) as Box; - let mut driver = Driver::new(fs); - driver.options = vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - ]; - driver + Driver::new( + fs, + vec![ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + ], + ) } fn setup_driver_with_mode(mode: u32) -> Driver { @@ -55,16 +57,16 @@ fn setup_driver_with_mode(mode: u32) -> Driver { let fs = Box::new(fs) as Box; - let mut driver = Driver::new(fs); - driver.options = vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - MountOption::DefaultMode(mode), - ]; - - driver + Driver::new( + fs, + vec![ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + MountOption::DefaultMode(mode), + ], + ) } fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver { @@ -82,17 +84,17 @@ fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver { let fs = Box::new(fs) as Box; - let mut driver = Driver::new(fs); - driver.options = vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - MountOption::Uid(uid), - MountOption::Gid(gid), - ]; - - driver + Driver::new( + fs, + vec![ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + MountOption::Uid(uid), + MountOption::Gid(gid), + ], + ) } /// Make file on the remote fs at `path` with `content` diff --git a/remotefs-fuse/src/lib.rs b/remotefs-fuse/src/lib.rs index e462f8a..0644b9c 100644 --- a/remotefs-fuse/src/lib.rs +++ b/remotefs-fuse/src/lib.rs @@ -33,5 +33,4 @@ extern crate log; mod driver; mod mount; -pub use self::driver::{Driver, DriverError, DriverResult}; pub use self::mount::{Mount, MountOption, Umount}; diff --git a/remotefs-fuse/src/mount.rs b/remotefs-fuse/src/mount.rs index 3848e8c..4708956 100644 --- a/remotefs-fuse/src/mount.rs +++ b/remotefs-fuse/src/mount.rs @@ -4,9 +4,10 @@ use std::path::Path; #[cfg(unix)] use fuser::{Session, SessionUnmounter}; +use remotefs::RemoteFs; pub use self::option::MountOption; -use crate::Driver; +use crate::driver::Driver; /// A struct to mount the filesystem. pub struct Mount { @@ -21,11 +22,11 @@ impl Mount { #[allow(clippy::self_named_constructors)] #[cfg(unix)] pub fn mount( - mut driver: Driver, + remote: Box, mountpoint: &Path, options: &[MountOption], ) -> Result { - driver.options = options.to_vec(); + let driver = Driver::new(remote, options.to_vec()); let options = driver .options diff --git a/remotefs-fuse/tests/driver/mod.rs b/remotefs-fuse/tests/driver/mod.rs index b07767e..fdb3380 100644 --- a/remotefs-fuse/tests/driver/mod.rs +++ b/remotefs-fuse/tests/driver/mod.rs @@ -2,14 +2,13 @@ use std::path::{Path, PathBuf}; use remotefs::fs::{Metadata, UnixPex}; use remotefs::{RemoteError, RemoteErrorType, RemoteFs}; -use remotefs_fuse::Driver; use remotefs_memory::{node, Inode, MemoryFs, Node, Tree}; pub fn mounted_file_path() -> &'static Path { Path::new("/tmp/mounted.txt") } -pub fn setup_driver() -> Driver { +pub fn setup_driver() -> Box { let gid = nix::unistd::getgid().as_raw(); let uid = nix::unistd::getuid().as_raw(); @@ -27,7 +26,7 @@ pub fn setup_driver() -> Driver { make_file_at(&mut fs, mounted_file_path(), b"Hello, world!"); - Driver::new(fs) + fs } /// Make file on the remote fs at `path` with `content`