2020-03-23 14:03:18 +00:00
|
|
|
use std::collections::HashSet;
|
2019-08-08 10:49:20 +00:00
|
|
|
use std::ffi::OsStr;
|
2020-03-23 14:03:18 +00:00
|
|
|
use std::fs::OpenOptions;
|
2019-05-27 12:16:13 +00:00
|
|
|
use std::os::unix::fs::OpenOptionsExt;
|
2020-03-23 14:03:18 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2020-07-31 12:08:02 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2020-07-31 12:08:02 +00:00
|
|
|
use anyhow::{bail, format_err, Error};
|
2020-03-23 14:03:18 +00:00
|
|
|
use futures::future::FutureExt;
|
|
|
|
use futures::select;
|
|
|
|
use tokio::signal::unix::{signal, SignalKind};
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
use pathpatterns::{MatchEntry, MatchType, PatternFlag};
|
2021-07-19 08:50:18 +00:00
|
|
|
use pbs_client::pxar::{fuse, format_single_line_entry, ENCODER_MAX_ENTRIES, Flags, PxarExtractOptions};
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2021-10-08 09:19:37 +00:00
|
|
|
use proxmox_schema::api;
|
|
|
|
use proxmox_router::cli::*;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-07-16 16:19:45 +00:00
|
|
|
fn extract_archive_from_reader<R: std::io::Read>(
|
|
|
|
reader: &mut R,
|
|
|
|
target: &str,
|
2020-06-10 09:03:42 +00:00
|
|
|
feature_flags: Flags,
|
2019-07-16 16:19:45 +00:00
|
|
|
verbose: bool,
|
2021-01-25 13:42:55 +00:00
|
|
|
options: PxarExtractOptions,
|
2019-07-16 16:19:45 +00:00
|
|
|
) -> Result<(), Error> {
|
2021-07-19 08:50:18 +00:00
|
|
|
pbs_client::pxar::extract_archive(
|
2020-03-23 14:03:18 +00:00
|
|
|
pxar::decoder::Decoder::from_std(reader)?,
|
|
|
|
Path::new(target),
|
|
|
|
feature_flags,
|
|
|
|
|path| {
|
|
|
|
if verbose {
|
|
|
|
println!("{:?}", path);
|
|
|
|
}
|
|
|
|
},
|
2021-01-25 13:42:55 +00:00
|
|
|
options,
|
2020-03-23 14:03:18 +00:00
|
|
|
)
|
2019-07-05 10:39:25 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
archive: {
|
|
|
|
description: "Archive name.",
|
|
|
|
},
|
|
|
|
pattern: {
|
|
|
|
description: "List of paths or pattern matching files to restore",
|
|
|
|
type: Array,
|
|
|
|
items: {
|
|
|
|
type: String,
|
|
|
|
description: "Path or pattern matching files to restore.",
|
|
|
|
},
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
description: "Target directory",
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
verbose: {
|
|
|
|
description: "Verbose output.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-xattrs": {
|
|
|
|
description: "Ignore extended file attributes.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-fcaps": {
|
|
|
|
description: "Ignore file capabilities.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-acls": {
|
|
|
|
description: "Ignore access control list entries.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"allow-existing-dirs": {
|
|
|
|
description: "Allows directories to already exist on restore.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"files-from": {
|
|
|
|
description: "File containing match pattern for files to restore.",
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"no-device-nodes": {
|
|
|
|
description: "Ignore device nodes.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-fifos": {
|
|
|
|
description: "Ignore fifos.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-sockets": {
|
|
|
|
description: "Ignore sockets.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-07-31 12:08:02 +00:00
|
|
|
strict: {
|
|
|
|
description: "Stop on errors. Otherwise most errors will simply warn.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-03-23 14:03:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Extract an archive.
|
2021-01-25 13:42:59 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2019-03-15 07:03:44 +00:00
|
|
|
fn extract_archive(
|
2020-03-23 14:03:18 +00:00
|
|
|
archive: String,
|
|
|
|
pattern: Option<Vec<String>>,
|
|
|
|
target: Option<String>,
|
|
|
|
verbose: bool,
|
|
|
|
no_xattrs: bool,
|
|
|
|
no_fcaps: bool,
|
|
|
|
no_acls: bool,
|
|
|
|
allow_existing_dirs: bool,
|
|
|
|
files_from: Option<String>,
|
|
|
|
no_device_nodes: bool,
|
|
|
|
no_fifos: bool,
|
|
|
|
no_sockets: bool,
|
2020-07-31 12:08:02 +00:00
|
|
|
strict: bool,
|
2020-03-23 14:03:18 +00:00
|
|
|
) -> Result<(), Error> {
|
2020-06-10 09:03:42 +00:00
|
|
|
let mut feature_flags = Flags::DEFAULT;
|
2019-05-23 11:10:20 +00:00
|
|
|
if no_xattrs {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_XATTRS);
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
|
|
|
if no_fcaps {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_FCAPS);
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
2019-05-28 09:16:21 +00:00
|
|
|
if no_acls {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_ACL);
|
2019-05-28 09:16:21 +00:00
|
|
|
}
|
2019-08-01 15:51:59 +00:00
|
|
|
if no_device_nodes {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_DEVICE_NODES);
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_fifos {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_FIFOS);
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_sockets {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_SOCKETS);
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
2019-03-15 07:03:44 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
let pattern = pattern.unwrap_or_else(Vec::new);
|
|
|
|
let target = target.as_ref().map_or_else(|| ".", String::as_str);
|
|
|
|
|
|
|
|
let mut match_list = Vec::new();
|
|
|
|
if let Some(filename) = &files_from {
|
2021-07-19 13:53:43 +00:00
|
|
|
for line in pbs_tools::fs::file_get_non_comment_lines(filename)? {
|
2020-03-23 14:03:18 +00:00
|
|
|
let line = line
|
|
|
|
.map_err(|err| format_err!("error reading {}: {}", filename, err))?;
|
|
|
|
match_list.push(
|
|
|
|
MatchEntry::parse_pattern(line, PatternFlag::PATH_NAME, MatchType::Include)
|
|
|
|
.map_err(|err| format_err!("bad pattern in file '{}': {}", filename, err))?,
|
|
|
|
);
|
2019-07-18 09:35:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-16 16:19:45 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
for entry in pattern {
|
|
|
|
match_list.push(
|
|
|
|
MatchEntry::parse_pattern(entry, PatternFlag::PATH_NAME, MatchType::Include)
|
|
|
|
.map_err(|err| format_err!("error in pattern: {}", err))?,
|
|
|
|
);
|
2019-07-18 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 07:29:20 +00:00
|
|
|
let extract_match_default = match_list.is_empty();
|
|
|
|
|
2020-07-31 12:08:02 +00:00
|
|
|
let was_ok = Arc::new(AtomicBool::new(true));
|
|
|
|
let on_error = if strict {
|
|
|
|
// by default errors are propagated up
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let was_ok = Arc::clone(&was_ok);
|
|
|
|
// otherwise we want to log them but not act on them
|
|
|
|
Some(Box::new(move |err| {
|
|
|
|
was_ok.store(false, Ordering::Release);
|
|
|
|
eprintln!("error: {}", err);
|
|
|
|
Ok(())
|
|
|
|
}) as Box<dyn FnMut(Error) -> Result<(), Error> + Send>)
|
|
|
|
};
|
|
|
|
|
2021-01-25 13:42:55 +00:00
|
|
|
let options = PxarExtractOptions {
|
|
|
|
match_list: &match_list,
|
|
|
|
allow_existing_dirs,
|
|
|
|
extract_match_default,
|
|
|
|
on_error,
|
|
|
|
};
|
|
|
|
|
2019-07-05 10:39:25 +00:00
|
|
|
if archive == "-" {
|
|
|
|
let stdin = std::io::stdin();
|
|
|
|
let mut reader = stdin.lock();
|
2020-03-23 14:03:18 +00:00
|
|
|
extract_archive_from_reader(
|
|
|
|
&mut reader,
|
|
|
|
&target,
|
|
|
|
feature_flags,
|
|
|
|
verbose,
|
2021-01-25 13:42:55 +00:00
|
|
|
options,
|
2020-03-23 14:03:18 +00:00
|
|
|
)?;
|
2019-07-05 10:39:25 +00:00
|
|
|
} else {
|
2020-03-23 14:03:18 +00:00
|
|
|
if verbose {
|
|
|
|
println!("PXAR extract: {}", archive);
|
|
|
|
}
|
2019-07-05 10:39:25 +00:00
|
|
|
let file = std::fs::File::open(archive)?;
|
|
|
|
let mut reader = std::io::BufReader::new(file);
|
2020-03-23 14:03:18 +00:00
|
|
|
extract_archive_from_reader(
|
|
|
|
&mut reader,
|
|
|
|
&target,
|
|
|
|
feature_flags,
|
|
|
|
verbose,
|
2021-01-25 13:42:55 +00:00
|
|
|
options,
|
2020-03-23 14:03:18 +00:00
|
|
|
)?;
|
2019-07-05 10:39:25 +00:00
|
|
|
}
|
2019-03-15 07:03:44 +00:00
|
|
|
|
2020-07-31 12:08:02 +00:00
|
|
|
if !was_ok.load(Ordering::Acquire) {
|
|
|
|
bail!("there were errors");
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
Ok(())
|
2019-03-15 07:03:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
archive: {
|
|
|
|
description: "Archive name.",
|
|
|
|
},
|
|
|
|
source: {
|
|
|
|
description: "Source directory.",
|
|
|
|
},
|
|
|
|
verbose: {
|
|
|
|
description: "Verbose output.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-xattrs": {
|
|
|
|
description: "Ignore extended file attributes.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-fcaps": {
|
|
|
|
description: "Ignore file capabilities.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-acls": {
|
|
|
|
description: "Ignore access control list entries.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"all-file-systems": {
|
|
|
|
description: "Include mounted sudirs.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-device-nodes": {
|
|
|
|
description: "Ignore device nodes.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-fifos": {
|
|
|
|
description: "Ignore fifos.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"no-sockets": {
|
|
|
|
description: "Ignore sockets.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
exclude: {
|
|
|
|
description: "List of paths or pattern matching files to exclude.",
|
|
|
|
optional: true,
|
|
|
|
type: Array,
|
|
|
|
items: {
|
|
|
|
description: "Path or pattern matching files to restore",
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"entries-max": {
|
|
|
|
description: "Max number of entries loaded at once into memory",
|
|
|
|
optional: true,
|
|
|
|
default: ENCODER_MAX_ENTRIES as isize,
|
|
|
|
minimum: 0,
|
2021-10-04 12:58:55 +00:00
|
|
|
maximum: isize::MAX,
|
2020-03-23 14:03:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Create a new .pxar archive.
|
2021-01-25 13:42:55 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2021-02-09 12:03:48 +00:00
|
|
|
async fn create_archive(
|
2020-03-23 14:03:18 +00:00
|
|
|
archive: String,
|
|
|
|
source: String,
|
|
|
|
verbose: bool,
|
|
|
|
no_xattrs: bool,
|
|
|
|
no_fcaps: bool,
|
|
|
|
no_acls: bool,
|
|
|
|
all_file_systems: bool,
|
|
|
|
no_device_nodes: bool,
|
|
|
|
no_fifos: bool,
|
|
|
|
no_sockets: bool,
|
|
|
|
exclude: Option<Vec<String>>,
|
|
|
|
entries_max: isize,
|
|
|
|
) -> Result<(), Error> {
|
2021-01-25 13:42:54 +00:00
|
|
|
let patterns = {
|
2020-03-23 14:03:18 +00:00
|
|
|
let input = exclude.unwrap_or_else(Vec::new);
|
2021-01-25 13:42:54 +00:00
|
|
|
let mut patterns = Vec::with_capacity(input.len());
|
2020-03-23 14:03:18 +00:00
|
|
|
for entry in input {
|
2021-01-25 13:42:54 +00:00
|
|
|
patterns.push(
|
2020-03-23 14:03:18 +00:00
|
|
|
MatchEntry::parse_pattern(entry, PatternFlag::PATH_NAME, MatchType::Exclude)
|
|
|
|
.map_err(|err| format_err!("error in exclude pattern: {}", err))?,
|
|
|
|
);
|
|
|
|
}
|
2021-01-25 13:42:54 +00:00
|
|
|
patterns
|
2020-03-23 14:03:18 +00:00
|
|
|
};
|
2019-01-07 12:25:41 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
let device_set = if all_file_systems {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(HashSet::new())
|
|
|
|
};
|
2019-07-24 05:48:59 +00:00
|
|
|
|
2021-07-19 08:50:18 +00:00
|
|
|
let options = pbs_client::pxar::PxarCreateOptions {
|
2021-01-25 13:42:54 +00:00
|
|
|
entries_max: entries_max as usize,
|
|
|
|
device_set,
|
|
|
|
patterns,
|
|
|
|
verbose,
|
|
|
|
skip_lost_and_found: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-15 07:03:44 +00:00
|
|
|
let source = PathBuf::from(source);
|
2019-01-07 12:25:41 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
let dir = nix::dir::Dir::open(
|
|
|
|
&source,
|
|
|
|
nix::fcntl::OFlag::O_NOFOLLOW,
|
|
|
|
nix::sys::stat::Mode::empty(),
|
|
|
|
)?;
|
2019-01-07 12:25:41 +00:00
|
|
|
|
2019-05-27 12:16:13 +00:00
|
|
|
let file = OpenOptions::new()
|
2019-01-07 12:25:41 +00:00
|
|
|
.create_new(true)
|
|
|
|
.write(true)
|
2019-05-27 12:16:13 +00:00
|
|
|
.mode(0o640)
|
2019-01-07 12:25:41 +00:00
|
|
|
.open(archive)?;
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
let writer = std::io::BufWriter::with_capacity(1024 * 1024, file);
|
2020-06-10 09:03:42 +00:00
|
|
|
let mut feature_flags = Flags::DEFAULT;
|
2019-05-23 11:10:20 +00:00
|
|
|
if no_xattrs {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_XATTRS);
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
|
|
|
if no_fcaps {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_FCAPS);
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
2019-05-28 09:16:21 +00:00
|
|
|
if no_acls {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_ACL);
|
2019-05-28 09:16:21 +00:00
|
|
|
}
|
2019-08-01 15:51:59 +00:00
|
|
|
if no_device_nodes {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_DEVICE_NODES);
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_fifos {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_FIFOS);
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_sockets {
|
2021-03-12 09:00:34 +00:00
|
|
|
feature_flags.remove(Flags::WITH_SOCKETS);
|
2019-10-22 13:07:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
let writer = pxar::encoder::sync::StandardWriter::new(writer);
|
2021-07-19 08:50:18 +00:00
|
|
|
pbs_client::pxar::create_archive(
|
2020-03-23 14:03:18 +00:00
|
|
|
dir,
|
|
|
|
writer,
|
2019-10-22 13:07:51 +00:00
|
|
|
feature_flags,
|
2021-02-09 12:03:48 +00:00
|
|
|
move |path| {
|
2020-03-23 14:03:18 +00:00
|
|
|
if verbose {
|
|
|
|
println!("{:?}", path);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
None,
|
2021-01-25 13:42:54 +00:00
|
|
|
options,
|
2021-02-09 12:03:48 +00:00
|
|
|
).await?;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
Ok(())
|
2018-12-30 17:01:20 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
archive: { description: "Archive name." },
|
|
|
|
mountpoint: { description: "Mountpoint for the file system." },
|
|
|
|
verbose: {
|
|
|
|
description: "Verbose output, running in the foreground (for debugging).",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2019-08-08 10:49:20 +00:00
|
|
|
/// Mount the archive to the provided mountpoint via FUSE.
|
2020-03-23 14:03:18 +00:00
|
|
|
async fn mount_archive(
|
|
|
|
archive: String,
|
|
|
|
mountpoint: String,
|
|
|
|
verbose: bool,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let archive = Path::new(&archive);
|
|
|
|
let mountpoint = Path::new(&mountpoint);
|
2019-08-08 10:49:20 +00:00
|
|
|
let options = OsStr::new("ro,default_permissions");
|
2020-03-23 14:03:18 +00:00
|
|
|
|
|
|
|
let session = fuse::Session::mount_path(&archive, &options, verbose, mountpoint)
|
|
|
|
.await
|
2019-08-08 10:49:20 +00:00
|
|
|
.map_err(|err| format_err!("pxar mount failed: {}", err))?;
|
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
let mut interrupt = signal(SignalKind::interrupt())?;
|
2019-08-08 10:49:20 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
select! {
|
|
|
|
res = session.fuse() => res?,
|
|
|
|
_ = interrupt.recv().fuse() => {
|
|
|
|
if verbose {
|
|
|
|
eprintln!("interrupted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-21 08:36:41 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2019-11-21 08:36:41 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
archive: {
|
|
|
|
description: "Archive name.",
|
|
|
|
},
|
|
|
|
verbose: {
|
|
|
|
description: "Verbose output.",
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// List the contents of an archive.
|
|
|
|
fn dump_archive(archive: String, verbose: bool) -> Result<(), Error> {
|
|
|
|
for entry in pxar::decoder::Decoder::open(archive)? {
|
|
|
|
let entry = entry?;
|
2019-11-21 08:36:41 +00:00
|
|
|
|
2020-03-23 14:03:18 +00:00
|
|
|
if verbose {
|
|
|
|
println!("{}", format_single_line_entry(&entry));
|
|
|
|
} else {
|
|
|
|
println!("{:?}", entry.path());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-11-21 08:36:41 +00:00
|
|
|
|
2018-12-30 17:01:20 +00:00
|
|
|
fn main() {
|
|
|
|
let cmd_def = CliCommandMap::new()
|
2020-03-23 14:03:18 +00:00
|
|
|
.insert(
|
|
|
|
"create",
|
|
|
|
CliCommand::new(&API_METHOD_CREATE_ARCHIVE)
|
|
|
|
.arg_param(&["archive", "source"])
|
2021-10-13 10:55:51 +00:00
|
|
|
.completion_cb("archive", complete_file_name)
|
|
|
|
.completion_cb("source", complete_file_name),
|
2020-03-23 14:03:18 +00:00
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"extract",
|
|
|
|
CliCommand::new(&API_METHOD_EXTRACT_ARCHIVE)
|
|
|
|
.arg_param(&["archive", "target"])
|
2021-10-13 10:55:51 +00:00
|
|
|
.completion_cb("archive", complete_file_name)
|
|
|
|
.completion_cb("target", complete_file_name)
|
|
|
|
.completion_cb("files-from", complete_file_name),
|
2018-12-30 17:01:20 +00:00
|
|
|
)
|
2020-03-23 14:03:18 +00:00
|
|
|
.insert(
|
|
|
|
"mount",
|
|
|
|
CliCommand::new(&API_METHOD_MOUNT_ARCHIVE)
|
|
|
|
.arg_param(&["archive", "mountpoint"])
|
2021-10-13 10:55:51 +00:00
|
|
|
.completion_cb("archive", complete_file_name)
|
|
|
|
.completion_cb("mountpoint", complete_file_name),
|
2019-08-08 10:49:20 +00:00
|
|
|
)
|
2020-03-23 14:03:18 +00:00
|
|
|
.insert(
|
|
|
|
"list",
|
|
|
|
CliCommand::new(&API_METHOD_DUMP_ARCHIVE)
|
|
|
|
.arg_param(&["archive"])
|
2021-10-13 10:55:51 +00:00
|
|
|
.completion_cb("archive", complete_file_name),
|
2018-12-30 17:01:20 +00:00
|
|
|
);
|
|
|
|
|
2020-05-06 05:51:05 +00:00
|
|
|
let rpcenv = CliEnvironment::new();
|
2020-03-23 14:03:18 +00:00
|
|
|
run_cli_command(cmd_def, rpcenv, Some(|future| {
|
2021-07-06 10:08:44 +00:00
|
|
|
pbs_runtime::main(future)
|
2020-03-23 14:03:18 +00:00
|
|
|
}));
|
2018-12-30 17:01:20 +00:00
|
|
|
}
|