mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Merge pull request #569 from rustic-rs/ls-recursive
ls: Add option --recursive
This commit is contained in:
commit
37d03d94d6
@ -1,6 +1,7 @@
|
||||
Changes in version x.x.x:
|
||||
|
||||
Breaking changes:
|
||||
- ls: Added option `--recursive`, note: default is now non-recursive if a path is given
|
||||
|
||||
Bugs fixed:
|
||||
- Fixed compilation on OpenBSD.
|
||||
@ -9,3 +10,4 @@ Bugs fixed:
|
||||
|
||||
New features:
|
||||
- REST backend: Set User-Agent header
|
||||
- ls: Added option `--recursive`
|
||||
|
||||
@ -21,7 +21,7 @@ use super::{Metadata, Node, NodeType};
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Getters)]
|
||||
pub struct Tree {
|
||||
#[serde(deserialize_with = "deserialize_null_default")]
|
||||
nodes: Vec<Node>,
|
||||
pub nodes: Vec<Node>,
|
||||
}
|
||||
|
||||
fn deserialize_null_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
|
||||
|
||||
@ -14,6 +14,10 @@ pub(super) struct Opts {
|
||||
#[clap(flatten, help_heading = "SNAPSHOT FILTER OPTIONS (when using latest)")]
|
||||
filter: SnapshotFilter,
|
||||
|
||||
/// recursively list the dir (default when no PATH is given)
|
||||
#[clap(long)]
|
||||
recursive: bool,
|
||||
|
||||
/// Snapshot/path to list
|
||||
#[clap(value_name = "SNAPSHOT[:PATH]")]
|
||||
snap: String,
|
||||
@ -26,15 +30,28 @@ pub(super) fn execute(
|
||||
) -> Result<()> {
|
||||
config_file.merge_into("snapshot-filter", &mut opts.filter)?;
|
||||
let be = &repo.dbe;
|
||||
let mut recursive = opts.recursive;
|
||||
|
||||
let (id, path) = opts.snap.split_once(':').unwrap_or((&opts.snap, ""));
|
||||
let (id, path) = opts.snap.split_once(':').unwrap_or_else(|| {
|
||||
recursive = true;
|
||||
(&opts.snap, "")
|
||||
});
|
||||
let snap = SnapshotFile::from_str(be, id, |sn| sn.matches(&opts.filter), progress_counter(""))?;
|
||||
let index = IndexBackend::new(be, progress_counter(""))?;
|
||||
let node = Tree::node_from_path(&index, snap.tree, Path::new(path))?;
|
||||
|
||||
for item in NodeStreamer::new(index, &node)? {
|
||||
let (path, _) = item?;
|
||||
println!("{path:?} ");
|
||||
if recursive {
|
||||
for item in NodeStreamer::new(index, &node)? {
|
||||
let (path, _) = item?;
|
||||
println!("{path:?} ");
|
||||
}
|
||||
} else if node.is_dir() {
|
||||
let tree = Tree::from_backend(&index, node.subtree.unwrap())?.nodes;
|
||||
for node in tree {
|
||||
println!("{:?} ", node.name());
|
||||
}
|
||||
} else {
|
||||
println!("{:?} ", node.name());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user