Add ability to extract subset of files from yama
ci/woodpecker/push/build Pipeline is pending Details
ci/woodpecker/push/release Pipeline is pending Details

This commit is contained in:
Olivier 'reivilibre' 2022-10-04 20:21:23 +01:00
parent aa2722607e
commit 0811c11c48
2 changed files with 44 additions and 3 deletions

View File

@ -56,8 +56,9 @@ enum PileCommand {
pointer_name: String,
/// Limited expression(s) of files to retrieve.
/// LIMITATION OF CURRENT VERSION: ONLY ONE EXACT PATH ALLOWED, PLEASE.
#[clap(short, long)]
subset: Vec<PathBuf>,
subset: Option<String>,
destination: PathBuf,
@ -118,7 +119,7 @@ fn wrapped_main() -> anyhow::Result<i32> {
match &opts.command {
PileCommand::Retrieve {
pointer_name,
subset: _,
subset,
destination,
num_workers: workers,
} => {
@ -136,10 +137,25 @@ fn wrapped_main() -> anyhow::Result<i32> {
fully_integrate_pointer_node(&pile, &mut root_tree_node.node, &mut pointer)?;
let mut node_to_extract = &mut root_tree_node.node;
if let Some(subset) = subset {
for path_to_descend in subset.split('/').filter(|s| ! s.is_empty()) {
match node_to_extract.child(path_to_descend) {
Ok(new_node) => {
node_to_extract = new_node;
}
Err(msg) => {
bail!("Can't descend into {path_to_descend:?}: {msg}");
}
}
}
}
// todo allow disabling apply metadata
extracting::extract(
destination,
&mut root_tree_node.node,
node_to_extract,
&pile,
true,
workers.unwrap_or(2),

View File

@ -270,6 +270,31 @@ impl TreeNode {
}
}
}
/// Recurses into a child by name, or returns Err with a reason.
pub fn child(&mut self, name: &str) -> Result<&mut TreeNode, &'static str> {
match self {
TreeNode::NormalFile { .. } => {
Err("not a directory: normal file")
}
TreeNode::Directory { children, .. } => {
match children.get_mut(name) {
None => {
Err("child not in directory")
}
Some(node) => {
Ok(node)
}
}
}
TreeNode::SymbolicLink { .. } => {
Err("not a directory: symlink")
}
TreeNode::Deleted => {
Err("not a directory: deleted")
}
}
}
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]