Skip to content

Commit

Permalink
allow users to define own mount options
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 12, 2024
1 parent bc478d5 commit 208dc04
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions config/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ exclusive = true # don't allow other users to access the mount point
file-access = "read" # Default: "forbidden" for hot/cold repos, else "read"
mount-point = "~/mnt"
snapshot-path = "latest:/dir" # Default: not set - if not set, generate a virtual tree with all snapshots using path-template
options = [
"kernel_cache", # Default: ["kernel_cache]
]
47 changes: 33 additions & 14 deletions src/commands/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
mod fusefs;
use fusefs::FuseFS;

use std::{ffi::OsStr, path::PathBuf};
use std::{
ffi::{OsStr, OsString},

Check warning on line 10 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

unused import: `OsString`
path::PathBuf,
};

use crate::{repository::CliIndexedRepo, status_err, Application, RusticConfig, RUSTIC_APP};

Expand Down Expand Up @@ -49,6 +52,19 @@ pub struct MountCmd {
#[clap(value_name = "SNAPSHOT[:PATH]")]
#[merge(strategy=conflate::option::overwrite_none)]
snapshot_path: Option<String>,

/// Other options to use for mount
#[clap(skip)]
options: MountOpts,
}

#[derive(Clone, Command, Debug, Serialize, Deserialize, Merge)]

Check failure on line 61 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 61 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the size for values of type `[u8]` cannot be known at compilation time
pub(crate) struct MountOpts(#[merge(strategy = conflate::vec::ignore)] pub(crate) Vec<OsStr>);

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

cannot find function `ignore` in module `conflate::vec`

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the trait bound `MountOpts: Runnable` is not satisfied

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the trait bound `MountOpts: FromArgMatches` is not satisfied

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the trait bound `std::ffi::OsStr: Clone` is not satisfied

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 62 in src/commands/mount.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-unknown-linux-gnu

the trait bound `std::ffi::OsStr: Deserialize<'_>` is not satisfied

impl Default for MountOpts {
fn default() -> Self {
Self(vec![OsStr::new("kernel_cache")])
}
}

impl Override<RusticConfig> for MountCmd {
Expand Down Expand Up @@ -91,6 +107,7 @@ impl MountCmd {
.path_template
.clone()
.unwrap_or_else(|| "[{hostname}]/[{label}]/{time}".to_string());

let time_template = config
.mount
.time_template
Expand All @@ -112,21 +129,13 @@ impl MountCmd {
)?
};

let name_opt = format!("fsname=rusticfs:{}", repo.config().id);
let mut options = vec![
OsStr::new("-o"),
OsStr::new(&name_opt),
OsStr::new("-o"),
OsStr::new("kernel_cache"),
];
let mut options = self.options.0;

options.extend_from_slice(&[OsStr::new(&format!("fsname=rusticfs:{}", repo.config().id))]);

if !config.mount.exclusive {
options.extend_from_slice(&[
OsStr::new("-o"),
OsStr::new("allow_other"),
OsStr::new("-o"),
OsStr::new("default_permissions"),
]);
options
.extend_from_slice(&[OsStr::new("allow_other"), OsStr::new("default_permissions")]);
}

let file_access = config.mount.file_access.as_ref().map_or_else(
Expand All @@ -141,6 +150,16 @@ impl MountCmd {
)?;

let fs = FuseMT::new(FuseFS::new(repo, vfs, file_access), 1);

// Sort and deduplicate options
options.sort_unstable();
options.dedup();

// join options into a single comma-delimited string and prepent "-o "
// this should be parsed just fine by fuser, here
// https://github.com/cberner/fuser/blob/9f6ced73a36f1d99846e28be9c5e4903939ee9d5/src/mnt/mount_options.rs#L157
let options = OsStr::new(&format!("-o {}", options.join(",")));

mount(fs, mount_point, &options)?;

Ok(())
Expand Down

0 comments on commit 208dc04

Please sign in to comment.