From a7513d5f0db18570cc7db405810ce66cab6475e4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 2 Oct 2023 13:45:30 +0200 Subject: broken transcode --- base/src/cache.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'base/src') diff --git a/base/src/cache.rs b/base/src/cache.rs index 7705a14..ee13b73 100644 --- a/base/src/cache.rs +++ b/base/src/cache.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Context}; use base64::Engine; use bincode::{Decode, Encode}; use jellycommon::AssetLocation; -use log::info; +use log::{info, warn}; use std::{ any::Any, collections::{BTreeMap, HashMap}, @@ -54,7 +54,14 @@ where let f = tokio::fs::File::create(location.path()) .await .context("creating new cache file")?; - generate(f).await?; + match generate(f).await { + Ok(()) => (), + Err(e) => { + warn!("cache generation failed, unlinking entry"); + tokio::fs::remove_file(location.path()).await?; + return Err(e); + } + } } drop(_guard); Ok(location) @@ -70,7 +77,14 @@ where let exists = location.path().exists(); if !exists { let f = std::fs::File::create(location.path()).context("creating new cache file")?; - generate(f)?; + match generate(f) { + Ok(()) => (), + Err(e) => { + warn!("cache generation failed, unlinking entry"); + std::fs::remove_file(location.path())?; + return Err(e); + } + } } drop(_guard); Ok(location) -- cgit v1.2.3-70-g09d2