From 95cea65b04a460add4cb2695357049be80614dca Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 18 Jan 2019 12:24:58 +0100 Subject: [PATCH] backup/datastore.rs: list all index files using walkdir crate --- Cargo.toml | 1 + src/backup/datastore.rs | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6cbedfa1..226993e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,5 @@ chrono = "0.4.6" # Date and time library for Rust openssl = "0.10.16" siphasher = "0.3" endian_trait = "0.6.0" +walkdir = "2" diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 35b2acc3..7ba912ba 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -134,17 +134,25 @@ impl DataStore { let mut list = vec![]; - // fixme: walk into subdirs ... - for entry in std::fs::read_dir(base)? { - let entry = entry?; - if entry.file_type()?.is_file() { - let path = entry.path(); - if let Some(ext) = path.extension() { - if ext == "iidx" { - list.push(path); - } else if ext == "aidx" { - list.push(path); - } + use walkdir::WalkDir; + + let walker = WalkDir::new(&base).same_file_system(true).into_iter(); + + // make sure we skip .chunks (and other hidden files to keep it simple) + fn is_hidden(entry: &walkdir::DirEntry) -> bool { + entry.file_name() + .to_str() + .map(|s| s.starts_with(".")) + .unwrap_or(false) + } + + for entry in walker.filter_entry(|e| !is_hidden(e)) { + let path = entry?.into_path(); + if let Some(ext) = path.extension() { + if ext == "iidx" { + list.push(path); + } else if ext == "aidx" { + list.push(path); } } }