From 286bd01410dda8acda923cb672882ec03013ca63 Mon Sep 17 00:00:00 2001 From: ellieisjelly Date: Tue, 28 Jul 2026 22:14:36 -0300 Subject: [PATCH 1/2] Load mods from cache if they fail to load --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5ef4570..4f7e77a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -190,9 +190,20 @@ async fn prepare_destination( match source::load(ctx, cache_entry, source, &source_set.transform).await { Ok(reference) => cache_files.push((key.clone(), reference)), Err(err) => { - eprintln!("failed to load {}: {:?}! excluding.", key, err); - ctx.status - .write(format!("Failed to load {}... Excluding!", key)); + match cache.entry(key.clone()).get_existing() { + Some(reference) => { + eprintln!("failed to load {}: {:?}! Loading from cache.", key, err); + ctx.status + .write(format!("Failed to load {}... Loading from cache!", key)); + cache_files.push((key.clone(), reference)) + } + None => { + eprintln!("failed to load {}: {:?}! excluding.", key, err); + ctx.status + .write(format!("Failed to load {}... Excluding!", key)); + } + } + } } } From 3f1c8ea0ba31105d61dc4487b1a41191294b1774 Mon Sep 17 00:00:00 2001 From: ellieisjelly Date: Tue, 28 Jul 2026 22:26:31 -0300 Subject: [PATCH 2/2] Make cache fallback a config option --- src/config.rs | 9 ++++++++- src/main.rs | 9 ++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 468b68a..a401746 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,8 +22,10 @@ pub struct Config { pub triggers: HashMap, #[serde(default = "default_min_restart_interval")] pub min_restart_interval_seconds: u64, - #[serde()] + #[serde(default = "default_restart")] pub restart: bool, + #[serde(default = "default_fallback_to_cache")] + pub fallback_to_cache: bool, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] @@ -58,6 +60,7 @@ impl Default for Config { }, min_restart_interval_seconds: default_min_restart_interval(), restart: default_restart(), + fallback_to_cache: default_fallback_to_cache() } } } @@ -70,6 +73,10 @@ fn default_restart() -> bool { true } +fn default_fallback_to_cache() -> bool { + true +} + pub async fn load(path: P) -> T where P: AsRef, diff --git a/src/main.rs b/src/main.rs index 4f7e77a..a44413b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ pub async fn main() { }; let destinations: Vec = - prepare_destinations(&ctx, destinations.destinations).await; + prepare_destinations(&ctx, destinations.destinations, config.fallback_to_cache).await; let changed_sources: Vec<_> = destinations .iter() @@ -153,13 +153,14 @@ pub async fn main() { async fn prepare_destinations( ctx: &Context, destinations: HashMap, + fallback_to_cache: bool ) -> Vec { let mut futures = Vec::new(); for (destination_name, destination) in destinations { let ctx = ctx.clone(); let future = tokio::spawn(async move { - prepare_destination(&ctx, &destination_name, &destination) + prepare_destination(&ctx, &destination_name, &destination, fallback_to_cache) .await .expect(&format!( "failed to prepare destination '{}'", @@ -177,6 +178,8 @@ async fn prepare_destination( ctx: &Context, destination_name: &str, destination: &config::Destination, + fallback_to_cache: bool + ) -> Result { let cache_root = Path::new(CACHE_ROOT).join(destination_name); @@ -190,7 +193,7 @@ async fn prepare_destination( match source::load(ctx, cache_entry, source, &source_set.transform).await { Ok(reference) => cache_files.push((key.clone(), reference)), Err(err) => { - match cache.entry(key.clone()).get_existing() { + match if fallback_to_cache { cache.entry(key.clone()).get_existing() } else { None } { Some(reference) => { eprintln!("failed to load {}: {:?}! Loading from cache.", key, err); ctx.status