pxar: add command 'mount' to cli of pxar
Allows to mount an archive to a specified mountpoint via the cli. Once the archive is mounted, the process is send to the background. By passing the --verbose flag, the process is kept in foreground and debug output is provided. Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
parent
02ba8a5d11
commit
f71e8cc96f
@ -12,6 +12,7 @@ use serde_json::{Value};
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::os::unix::fs::OpenOptionsExt;
|
use std::os::unix::fs::OpenOptionsExt;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
@ -216,6 +217,27 @@ fn create_archive(
|
|||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mount the archive to the provided mountpoint via FUSE.
|
||||||
|
fn mount_archive(
|
||||||
|
param: Value,
|
||||||
|
_info: &ApiMethod,
|
||||||
|
_rpcenv: &mut dyn RpcEnvironment,
|
||||||
|
) -> Result<Value, Error> {
|
||||||
|
let archive = tools::required_string_param(¶m, "archive")?;
|
||||||
|
let mountpoint = tools::required_string_param(¶m, "mountpoint")?;
|
||||||
|
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
||||||
|
|
||||||
|
let archive = Path::new(archive);
|
||||||
|
let mountpoint = Path::new(mountpoint);
|
||||||
|
let options = OsStr::new("ro,default_permissions");
|
||||||
|
let mut session = pxar::fuse::Session::new(&archive, &options, verbose)
|
||||||
|
.map_err(|err| format_err!("pxar mount failed: {}", err))?;
|
||||||
|
session.mount(&mountpoint)?;
|
||||||
|
session.run_loop()?;
|
||||||
|
|
||||||
|
Ok(Value::Null)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let cmd_def = CliCommandMap::new()
|
let cmd_def = CliCommandMap::new()
|
||||||
@ -267,6 +289,19 @@ fn main() {
|
|||||||
.completion_cb("files-from", tools::complete_file_name)
|
.completion_cb("files-from", tools::complete_file_name)
|
||||||
.into()
|
.into()
|
||||||
)
|
)
|
||||||
|
.insert("mount", CliCommand::new(
|
||||||
|
ApiMethod::new(
|
||||||
|
mount_archive,
|
||||||
|
ObjectSchema::new("Mount the archive as filesystem via FUSE.")
|
||||||
|
.required("archive", StringSchema::new("Archive name."))
|
||||||
|
.required("mountpoint", StringSchema::new("Mountpoint for the filesystem root."))
|
||||||
|
.optional("verbose", BooleanSchema::new("Verbose output, keeps process running in foreground.").default(false))
|
||||||
|
))
|
||||||
|
.arg_param(vec!["archive", "mountpoint"])
|
||||||
|
.completion_cb("archive", tools::complete_file_name)
|
||||||
|
.completion_cb("mountpoint", tools::complete_file_name)
|
||||||
|
.into()
|
||||||
|
)
|
||||||
.insert("list", CliCommand::new(
|
.insert("list", CliCommand::new(
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
dump_archive,
|
dump_archive,
|
||||||
|
Loading…
Reference in New Issue
Block a user