From 2112f77e17ec4802ee8a58e5fbb5012640e1a39e Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 27 Jun 2024 11:55:23 +0000 Subject: [PATCH] Foreground cache scan when free space is low --- src/cache_manager.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cache_manager.rs b/src/cache_manager.rs index 9631504..7e19cf7 100644 --- a/src/cache_manager.rs +++ b/src/cache_manager.rs @@ -72,9 +72,19 @@ impl CacheManager { let manager = new.clone(); let verify_cache = init_settings.verify_cache(); let static_range = init_settings.static_range(); - if verify_cache && !force_background_scan { - // Force check cache - info!("Start force cache check"); + let low_disk = if let Some(free) = get_available_space(cache_dir.as_ref()) { + warn!("Disk space is low than 100MiB: available={}MiB", free / 1024 / 1024); + free < SIZE_100MB + } else { + false + }; + if low_disk || (verify_cache && !force_background_scan) { + // Low space or force cache check + if low_disk { + info!("Start foreground cache scan due to low disk space"); + } else { + info!("Start force cache check"); + } new.scan_cache(static_range, 16, verify_cache).await?; CacheManager::start_background_task(manager); } else {