Skip to content

Commit

Permalink
Add support for pruning excluded directories (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaky committed Aug 25, 2019
1 parent 87a9fe5 commit 878fce3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ impl Default for Config {
decimal: false,
compression: Compression::default(),
excludes: vec![
"*:\\Windows\\*",
"*:\\Windows*",
"*:\\System Volume Information*",
"*:\\$*",
"*.7z",
"*.aac",
"*.avi",
"*.ba",
"*.{bik,bk2,bnk,pc_binkvid}",
"*.br",
"*.bz2",
"*.cab",
Expand All @@ -46,6 +49,7 @@ impl Default for Config {
"*.lzma",
"*.lzx",
"*.m[24]v",
"*.m4a",
"*.mkv",
"*.mp[234]",
"*.mpeg",
Expand All @@ -67,7 +71,6 @@ impl Default for Config {
"*.xz",
"*.zst",
"*.zstd",
"*.{bik,bk2,bnk,pc_binkvid}",
]
.into_iter()
.map(String::from)
Expand Down
10 changes: 9 additions & 1 deletion src/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,19 @@ impl Background for FolderScan {

let mut last_status = Instant::now();

// 1. Handle excludes separately for directories to allow pruning, while
// still recording accurate sizes for files.
// 2. Ignore errors - consider recording them somewhere in future.
// 3. Only process files.
// 4. Grab metadata - should be infallible on Windows, it comes with the
// DirEntry.
// 5. GetCompressedFileSizeW() or skip.
let walker = WalkDir::new(&self.path)
.into_iter()
.filter_entry(|e| e.file_type().is_file() || !excludes.is_match(e.path()))
.filter_map(|e| e.map_err(|e| eprintln!("Error: {:?}", e)).ok())
.filter(|e| e.file_type().is_file())
.filter_map(|e| e.metadata().map(|md| (e, md)).ok())
.filter(|(_, md)| md.is_file())
.filter_map(|(e, md)| file_real_size(e.path()).map(|s| (e, md, s)).ok())
.enumerate();

Expand Down

0 comments on commit 878fce3

Please sign in to comment.