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: handle is_music edge cases

Gee Sawra 36143f25 cf53f439

+12 -12
+12 -12
src/fs.rs
··· 1 - use anyhow::Context; 2 1 use async_std::channel::{Receiver, Sender}; 3 2 4 3 /// Traverses the file system from the given path. ··· 39 38 40 39 match meta.is_dir() { 41 40 true => {} 42 - false => { 43 - if is_music(&path_str) { 44 - tx.send(Ok(path_str)).await.unwrap(); 45 - } 46 - } 41 + false => match is_music(&path_str) { 42 + Ok(im) => match im { 43 + true => tx.send(Ok(path_str)).await.unwrap(), 44 + false => (), 45 + }, 46 + Err(err) => tx.send(Err(err)).await.unwrap(), 47 + }, 47 48 } 48 49 } 49 50 ··· 51 52 } 52 53 53 54 /// Returns true if name has one of the supported music file extension. 54 - fn is_music(name: &String) -> bool { 55 + fn is_music(name: &String) -> std::io::Result<bool> { 55 56 let formats = ["flac", "mp3", "ogg", "mp4", "m4a", "opus"]; 56 57 57 - let mime = infer::get_from_path(name) 58 - .context(format!("could not infer extension from {}", name.clone())) 59 - .unwrap(); 60 - match mime { 58 + let mime = infer::get_from_path(name)?; 59 + 60 + Ok(match mime { 61 61 Some(mime) => { 62 62 let ext = mime.extension(); 63 63 formats.iter().find(|f| **f == ext).is_some() 64 64 } 65 65 None => false, 66 - } 66 + }) 67 67 }