From f0110496bdfa1bcbf19c5d2ec511a4c29a9147ff Mon Sep 17 00:00:00 2001 From: CEbbinghaus Date: Sun, 18 Feb 2024 18:01:49 +1100 Subject: [PATCH] Added scan interval to config --- backend/src/cfg.rs | 2 ++ backend/src/ds.rs | 2 +- backend/src/watch.rs | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/cfg.rs b/backend/src/cfg.rs index 15a1037..6c81568 100644 --- a/backend/src/cfg.rs +++ b/backend/src/cfg.rs @@ -33,6 +33,7 @@ pub enum LogLevel { #[derive(Serialize, Deserialize)] pub struct Config { pub port: u16, + pub scan_interval: u64, pub store_file: PathBuf, pub log_file: PathBuf, #[serde(with = "LogLevel")] @@ -43,6 +44,7 @@ impl Config { pub fn new() -> Self { Config { port: 12412, + scan_interval: 5000, log_file: "microsdeck.log".into(), store_file: "store".into(), log_level: Level::INFO, diff --git a/backend/src/ds.rs b/backend/src/ds.rs index 439381f..476cbd0 100644 --- a/backend/src/ds.rs +++ b/backend/src/ds.rs @@ -443,7 +443,7 @@ impl Store { } pub fn remove_element(&self, id: &str) -> Result<(), Error> { - // these two operations have to happen within a single scope otherwise the try_write_to_file causes a deadlock + // these two operations have to happen within a single lock otherwise the try_write_to_file causes a deadlock { let mut lock = self.data.write().unwrap(); lock.remove_item(id)?; diff --git a/backend/src/watch.rs b/backend/src/watch.rs index bc75fb0..daa99bd 100644 --- a/backend/src/watch.rs +++ b/backend/src/watch.rs @@ -1,3 +1,4 @@ +use crate::cfg::CONFIG; use crate::{ds::Store, dto::*, err::Error, sdcard::*, steam::*}; use std::borrow::Borrow; use std::path::{Path, PathBuf}; @@ -93,7 +94,7 @@ fn read_msd_directory(datastore: &Store, mount: &Option) -> Result<(), E } pub async fn start_watch(datastore: Arc, sender: Sender) -> Result<(), Error> { - let mut interval = interval(Duration::from_secs(1)); + let mut interval = interval(Duration::from_millis(CONFIG.scan_interval)); let mut card_inserted = false;