Skip to content

Commit

Permalink
fix: don't expose Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 25, 2024
1 parent c7fb70f commit 0675cc2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 49 deletions.
4 changes: 2 additions & 2 deletions remotefs-fuse-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::<cli::CliArgs>();
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions remotefs-fuse/src/driver.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,13 +34,13 @@ impl Driver {
///
/// * `remote` - The instance which implements the [`RemoteFs`] trait.
/// * `options` - The mount options.
pub fn new(remote: Box<dyn RemoteFs>) -> Self {
pub fn new(remote: Box<dyn RemoteFs>, options: Vec<MountOption>) -> Self {
Self {
#[cfg(unix)]
database: unix::InodeDb::load(),
#[cfg(unix)]
file_handlers: unix::FileHandlersDb::default(),
options: Vec::new(),
options,
remote,
}
}
Expand Down
6 changes: 0 additions & 6 deletions remotefs-fuse/src/driver/error.rs

This file was deleted.

62 changes: 32 additions & 30 deletions remotefs-fuse/src/driver/unix/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -27,14 +28,15 @@ fn setup_driver() -> Driver {

let fs = Box::new(fs) as Box<dyn RemoteFs>;

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 {
Expand All @@ -55,16 +57,16 @@ fn setup_driver_with_mode(mode: u32) -> Driver {

let fs = Box::new(fs) as Box<dyn RemoteFs>;

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 {
Expand All @@ -82,17 +84,17 @@ fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver {

let fs = Box::new(fs) as Box<dyn RemoteFs>;

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`
Expand Down
1 change: 0 additions & 1 deletion remotefs-fuse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
7 changes: 4 additions & 3 deletions remotefs-fuse/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,11 +22,11 @@ impl Mount {
#[allow(clippy::self_named_constructors)]
#[cfg(unix)]
pub fn mount(
mut driver: Driver,
remote: Box<dyn RemoteFs>,
mountpoint: &Path,
options: &[MountOption],
) -> Result<Self, std::io::Error> {
driver.options = options.to_vec();
let driver = Driver::new(remote, options.to_vec());

let options = driver
.options
Expand Down
5 changes: 2 additions & 3 deletions remotefs-fuse/tests/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn RemoteFs> {
let gid = nix::unistd::getgid().as_raw();
let uid = nix::unistd::getuid().as_raw();

Expand All @@ -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`
Expand Down

0 comments on commit 0675cc2

Please sign in to comment.