diff --git a/src/input/folder.rs b/src/input/folder.rs index 3f02bad9..3d9fe8b6 100644 --- a/src/input/folder.rs +++ b/src/input/folder.rs @@ -1,13 +1,7 @@ -use notify::{ - DebouncedEvent::{Create, Remove, Rename}, - {watcher, RecursiveMode, Watcher}, -}; - -use rand::{seq::SliceRandom, thread_rng}; -use simplelog::*; use std::{ ffi::OsStr, path::Path, + process::exit, sync::{ mpsc::channel, {Arc, Mutex}, @@ -16,6 +10,12 @@ use std::{ time::Duration, }; +use notify::{ + DebouncedEvent::{Create, Remove, Rename}, + {watcher, RecursiveMode, Watcher}, +}; +use rand::{seq::SliceRandom, thread_rng}; +use simplelog::*; use walkdir::WalkDir; use crate::utils::{get_sec, GlobalConfig, Media}; @@ -34,6 +34,14 @@ impl Source { let mut media_list = vec![]; let mut index: usize = 0; + if !Path::new(&config.storage.path).is_dir() { + error!( + "Path not exists: {}", + config.storage.path + ); + exit(1); + } + for entry in WalkDir::new(config.storage.path.clone()) .into_iter() .filter_map(|e| e.ok()) @@ -150,10 +158,7 @@ fn file_extension(filename: &Path) -> Option<&str> { filename.extension().and_then(OsStr::to_str) } -pub async fn watchman( - sources: Arc>>, - is_terminated: Arc>, -) { +pub async fn watchman(sources: Arc>>, is_terminated: Arc>) { let config = GlobalConfig::global(); let (tx, rx) = channel(); @@ -169,7 +174,7 @@ pub async fn watchman( loop { if *is_terminated.lock().unwrap() { - break + break; } if let Ok(res) = rx.try_recv() {