From 2eb8f51139a1e29c294550dc61b234b29ce9a3ba Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Thu, 14 Apr 2022 21:24:02 +0200 Subject: [PATCH] check if storage path exists --- src/input/folder.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) 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() {