A tool to sync music with your favorite devices
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: refactor to make ignore files really work

Gee Sawra 2a6ce727 2b312d83

+23 -6
+23 -6
src/fs.rs
··· 1 + use std::path::Path; 2 + 1 3 use async_std::channel::{Receiver, Sender}; 2 4 3 5 /// Traverses the file system from the given path. ··· 15 17 } 16 18 17 19 async fn traverse_inner(path: String, tx: Sender<Result<String, std::io::Error>>) { 18 - for maybe_path in walkdir::WalkDir::new(path) { 19 - let path = match maybe_path { 20 - Ok(p) => p, 21 - Err(e) => { 22 - tx.send(Err(e.into())).await.unwrap(); 20 + let mut wd = walkdir::WalkDir::new(path).into_iter(); 21 + loop { 22 + let path = match wd.next() { 23 + None => break, 24 + Some(Err(err)) => { 25 + tx.send(Err(err.into())).await.unwrap(); 23 26 tx.close(); 24 27 return; 25 28 } 29 + Some(Ok(entry)) => entry, 26 30 }; 27 31 28 32 let meta = match path.metadata() { ··· 37 41 let path_str = path.path().to_str().unwrap().to_string(); 38 42 39 43 match meta.is_dir() { 40 - true => {} 44 + true => { 45 + log::debug!("DIRECTORY: {}", path_str); 46 + if is_ignored(path.path()) { 47 + log::debug!("ignoring {} as it contains a .ignore file", path_str); 48 + wd.skip_current_dir(); 49 + continue; 50 + } 51 + } 41 52 false => match is_music(&path_str) { 42 53 Ok(im) => match im { 43 54 true => tx.send(Ok(path_str)).await.unwrap(), ··· 65 76 None => false, 66 77 }) 67 78 } 79 + 80 + /// Returns true if the directory should not be scanned further. 81 + fn is_ignored(path: &Path) -> bool { 82 + let ignore_file = path.join(".ignore"); 83 + ignore_file.exists() 84 + }