Skip to content

Commit 878fce3

Browse files
committed
Add support for pruning excluded directories (#8)
1 parent 87a9fe5 commit 878fce3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ impl Default for Config {
2525
decimal: false,
2626
compression: Compression::default(),
2727
excludes: vec![
28-
"*:\\Windows\\*",
28+
"*:\\Windows*",
29+
"*:\\System Volume Information*",
30+
"*:\\$*",
2931
"*.7z",
3032
"*.aac",
3133
"*.avi",
3234
"*.ba",
35+
"*.{bik,bk2,bnk,pc_binkvid}",
3336
"*.br",
3437
"*.bz2",
3538
"*.cab",
@@ -46,6 +49,7 @@ impl Default for Config {
4649
"*.lzma",
4750
"*.lzx",
4851
"*.m[24]v",
52+
"*.m4a",
4953
"*.mkv",
5054
"*.mp[234]",
5155
"*.mpeg",
@@ -67,7 +71,6 @@ impl Default for Config {
6771
"*.xz",
6872
"*.zst",
6973
"*.zstd",
70-
"*.{bik,bk2,bnk,pc_binkvid}",
7174
]
7275
.into_iter()
7376
.map(String::from)

src/folder.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,19 @@ impl Background for FolderScan {
179179

180180
let mut last_status = Instant::now();
181181

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

0 commit comments

Comments
 (0)