diff --git a/remotefs-fuse-cli/src/main.rs b/remotefs-fuse-cli/src/main.rs index b15d484..66da710 100644 --- a/remotefs-fuse-cli/src/main.rs +++ b/remotefs-fuse-cli/src/main.rs @@ -35,8 +35,6 @@ fn main() -> anyhow::Result<()> { options.push(MountOption::DefaultMode(default_mode)); } - let driver = Driver::new(args.remote(), options); - log::info!("Mounting remote fs at {}", mount_path.display()); // create the mount point if it does not exist @@ -46,8 +44,7 @@ fn main() -> anyhow::Result<()> { } // Mount the remote file system - let mut mount = Mount::mount(driver, &mount_path)?; - + let mut mount = Mount::mount(Driver::new(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 627e708..db5fff5 100644 --- a/remotefs-fuse/src/driver.rs +++ b/remotefs-fuse/src/driver.rs @@ -36,13 +36,13 @@ impl Driver { /// /// * `remote` - The instance which implements the [`RemoteFs`] trait. /// * `options` - The mount options. - pub fn new(remote: Box, options: Vec) -> Self { + pub fn new(remote: Box) -> Self { Self { #[cfg(unix)] database: unix::InodeDb::load(), #[cfg(unix)] file_handlers: unix::FileHandlersDb::default(), - options, + options: Vec::new(), remote, } } diff --git a/remotefs-fuse/src/driver/unix/test.rs b/remotefs-fuse/src/driver/unix/test.rs index 0fdb852..47b30a2 100644 --- a/remotefs-fuse/src/driver/unix/test.rs +++ b/remotefs-fuse/src/driver/unix/test.rs @@ -27,15 +27,14 @@ fn setup_driver() -> Driver { let fs = Box::new(fs) as Box; - Driver::new( - fs, - vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - ], - ) + let mut driver = Driver::new(fs); + driver.options = vec![ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + ]; + driver } fn setup_driver_with_mode(mode: u32) -> Driver { @@ -56,16 +55,16 @@ fn setup_driver_with_mode(mode: u32) -> Driver { let fs = Box::new(fs) as Box; - Driver::new( - fs, - vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - MountOption::DefaultMode(mode), - ], - ) + let mut driver = Driver::new(fs); + driver.options = vec![ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + MountOption::DefaultMode(mode), + ]; + + driver } fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver { @@ -83,17 +82,17 @@ fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver { let fs = Box::new(fs) as Box; - Driver::new( - fs, - vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - MountOption::Uid(uid), - MountOption::Gid(gid), - ], - ) + let mut driver = Driver::new(fs); + driver.options = vec![ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + MountOption::Uid(uid), + MountOption::Gid(gid), + ]; + + driver } /// Make file on the remote fs at `path` with `content` diff --git a/remotefs-fuse/src/mount.rs b/remotefs-fuse/src/mount.rs index d8d3dfa..3848e8c 100644 --- a/remotefs-fuse/src/mount.rs +++ b/remotefs-fuse/src/mount.rs @@ -20,7 +20,13 @@ impl Mount { /// You can specify the mount options using the `options` parameter. #[allow(clippy::self_named_constructors)] #[cfg(unix)] - pub fn mount(driver: Driver, mountpoint: &Path) -> Result { + pub fn mount( + mut driver: Driver, + mountpoint: &Path, + options: &[MountOption], + ) -> Result { + driver.options = options.to_vec(); + let options = driver .options .iter() @@ -32,8 +38,18 @@ impl Mount { }) } + /// Mount the filesystem implemented by [`Driver`] to the provided mountpoint. + /// + /// You can specify the mount options using the `options` parameter. #[cfg(windows)] - pub fn mount(driver: Driver, mountpoint: &Path) -> Result { + #[allow(clippy::self_named_constructors)] + pub fn mount( + mut driver: Driver, + mountpoint: &Path, + options: &[MountOption], + ) -> Result { + driver.options = options.to_vec(); + todo!() } diff --git a/remotefs-fuse/tests/driver/mod.rs b/remotefs-fuse/tests/driver/mod.rs index abaac59..b07767e 100644 --- a/remotefs-fuse/tests/driver/mod.rs +++ b/remotefs-fuse/tests/driver/mod.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use remotefs::fs::{Metadata, UnixPex}; use remotefs::{RemoteError, RemoteErrorType, RemoteFs}; -use remotefs_fuse::{Driver, MountOption}; +use remotefs_fuse::Driver; use remotefs_memory::{node, Inode, MemoryFs, Node, Tree}; pub fn mounted_file_path() -> &'static Path { @@ -27,15 +27,7 @@ pub fn setup_driver() -> Driver { make_file_at(&mut fs, mounted_file_path(), b"Hello, world!"); - Driver::new( - fs, - vec![ - MountOption::AllowRoot, - MountOption::RW, - MountOption::Exec, - MountOption::Sync, - ], - ) + Driver::new(fs) } /// Make file on the remote fs at `path` with `content` diff --git a/remotefs-fuse/tests/fuse/mod.rs b/remotefs-fuse/tests/fuse/mod.rs index a4a6d23..18df339 100644 --- a/remotefs-fuse/tests/fuse/mod.rs +++ b/remotefs-fuse/tests/fuse/mod.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex}; use std::thread::JoinHandle; use std::time::Duration; -use remotefs_fuse::{Mount, Umount}; +use remotefs_fuse::{Mount, MountOption, Umount}; use tempfile::TempDir; use crate::driver::mounted_file_path; @@ -24,8 +24,17 @@ fn mount(p: &Path) -> (UmountLock, JoinHandle<()>) { let umount_t = umount.clone(); let join = std::thread::spawn(move || { - let mut mount = - Mount::mount(crate::driver::setup_driver(), &mountpoint).expect("failed to mount"); + let mut mount = Mount::mount( + crate::driver::setup_driver(), + &mountpoint, + &[ + MountOption::AllowRoot, + MountOption::RW, + MountOption::Exec, + MountOption::Sync, + ], + ) + .expect("failed to mount"); let umount = mount.unmounter(); *umount_t.lock().unwrap() = Some(umount);