mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-13 21:05:25 +00:00
pxar: bin: use dedicated api type for restore pattern
Instead of taking a plain string as input parameter, use the corresponding api type performing additional input validation. Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
parent
45b5556765
commit
33031f9835
@ -25,5 +25,6 @@ proxmox-router = { workspace = true, features = ["cli", "server"] }
|
|||||||
proxmox-schema = { workspace = true, features = [ "api-macro" ] }
|
proxmox-schema = { workspace = true, features = [ "api-macro" ] }
|
||||||
proxmox-sys.workspace = true
|
proxmox-sys.workspace = true
|
||||||
|
|
||||||
|
pbs-api-types.workspace = true
|
||||||
pbs-client.workspace = true
|
pbs-client.workspace = true
|
||||||
pbs-pxar-fuse.workspace = true
|
pbs-pxar-fuse.workspace = true
|
||||||
|
@ -9,9 +9,11 @@ use std::sync::Arc;
|
|||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
use futures::select;
|
use futures::select;
|
||||||
|
use serde_json::Value;
|
||||||
use tokio::signal::unix::{signal, SignalKind};
|
use tokio::signal::unix::{signal, SignalKind};
|
||||||
|
|
||||||
use pathpatterns::{MatchEntry, MatchType, PatternFlag};
|
use pathpatterns::{MatchEntry, MatchType, PatternFlag};
|
||||||
|
use pbs_api_types::PathPatterns;
|
||||||
use pbs_client::pxar::tools::format_single_line_entry;
|
use pbs_client::pxar::tools::format_single_line_entry;
|
||||||
use pbs_client::pxar::{
|
use pbs_client::pxar::{
|
||||||
Flags, OverwriteFlags, PxarExtractOptions, PxarWriters, ENCODER_MAX_ENTRIES,
|
Flags, OverwriteFlags, PxarExtractOptions, PxarWriters, ENCODER_MAX_ENTRIES,
|
||||||
@ -53,12 +55,7 @@ fn extract_archive_from_reader<R: std::io::Read>(
|
|||||||
description: "Archive name.",
|
description: "Archive name.",
|
||||||
},
|
},
|
||||||
pattern: {
|
pattern: {
|
||||||
description: "List of paths or pattern matching files to restore",
|
type: PathPatterns,
|
||||||
type: Array,
|
|
||||||
items: {
|
|
||||||
type: String,
|
|
||||||
description: "Path or pattern matching files to restore.",
|
|
||||||
},
|
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
target: {
|
target: {
|
||||||
@ -144,7 +141,6 @@ fn extract_archive_from_reader<R: std::io::Read>(
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn extract_archive(
|
fn extract_archive(
|
||||||
archive: String,
|
archive: String,
|
||||||
pattern: Option<Vec<String>>,
|
|
||||||
target: Option<String>,
|
target: Option<String>,
|
||||||
no_xattrs: bool,
|
no_xattrs: bool,
|
||||||
no_fcaps: bool,
|
no_fcaps: bool,
|
||||||
@ -161,6 +157,7 @@ fn extract_archive(
|
|||||||
strict: bool,
|
strict: bool,
|
||||||
payload_input: Option<String>,
|
payload_input: Option<String>,
|
||||||
prelude_target: Option<String>,
|
prelude_target: Option<String>,
|
||||||
|
param: Value,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut feature_flags = Flags::DEFAULT;
|
let mut feature_flags = Flags::DEFAULT;
|
||||||
if no_xattrs {
|
if no_xattrs {
|
||||||
@ -190,7 +187,6 @@ fn extract_archive(
|
|||||||
overwrite_flags.insert(OverwriteFlags::all());
|
overwrite_flags.insert(OverwriteFlags::all());
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern = pattern.unwrap_or_default();
|
|
||||||
let target = target.as_ref().map_or_else(|| ".", String::as_str);
|
let target = target.as_ref().map_or_else(|| ".", String::as_str);
|
||||||
|
|
||||||
let mut match_list = Vec::new();
|
let mut match_list = Vec::new();
|
||||||
@ -204,11 +200,15 @@ fn extract_archive(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry in pattern {
|
if let Some(pattern) = param["pattern"].as_array() {
|
||||||
match_list.push(
|
for p in pattern {
|
||||||
MatchEntry::parse_pattern(entry, PatternFlag::PATH_NAME, MatchType::Include)
|
if let Some(entry) = p.as_str() {
|
||||||
.map_err(|err| format_err!("error in pattern: {}", err))?,
|
match_list.push(
|
||||||
);
|
MatchEntry::parse_pattern(entry, PatternFlag::PATH_NAME, MatchType::Include)
|
||||||
|
.map_err(|err| format_err!("error in pattern: {err}"))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let extract_match_default = match_list.is_empty();
|
let extract_match_default = match_list.is_empty();
|
||||||
|
Loading…
Reference in New Issue
Block a user