From 697b136e1392469cc47acaed5963f8c15c2297b9 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Fri, 9 Oct 2020 13:08:06 -0500 Subject: [PATCH] Delete netkan tmp files if cache fills up --- Netkan/Services/CachingHttpService.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Netkan/Services/CachingHttpService.cs b/Netkan/Services/CachingHttpService.cs index 33267cfdee..83fa476450 100644 --- a/Netkan/Services/CachingHttpService.cs +++ b/Netkan/Services/CachingHttpService.cs @@ -99,12 +99,22 @@ private string DownloadPackage(Uri url, string identifier, DateTime? updated, Ur break; } - return _cache.Store( - primaryUrl, - downloadedFile, - string.Format("netkan-{0}.{1}", identifier, extension), - move: true - ); + try + { + return _cache.Store( + primaryUrl, + downloadedFile, + $"netkan-{identifier}.{extension}", + move: true + ); + } + catch (IOException exc) + { + // If cache is full, don't also fill /tmp + log.Debug($"Failed to store to cache: {exc.Message}"); + File.Delete(downloadedFile); + throw; + } } }