From de282d24a6b8fcd294873873529216d498182833 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Sun, 31 Dec 2023 14:54:56 +0100 Subject: [PATCH] Fix deletion of HTTP cache on shutdown --- .../main/java/ctbrec/ui/CamrecApplication.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index d085481a..87c9a5f2 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -405,6 +405,7 @@ public class CamrecApplication extends Application { } onlineMonitor.shutdown(); recorder.shutdown(immediately); + scheduler.shutdownNow(); for (Site site : sites) { if (site.isEnabled()) { site.shutdown(); @@ -412,6 +413,7 @@ public class CamrecApplication extends Application { } try { Config.getInstance().save(); + clearHttpCache(); LOG.info("Shutdown complete. Goodbye!"); Platform.runLater(() -> { primaryStage.close(); @@ -431,17 +433,22 @@ public class CamrecApplication extends Application { } try { ExternalBrowser.getInstance().close(); - HttpClientCacheProvider.getCache(config).evictAll(); - HttpClientCacheProvider.getCache(config).close(); - IoUtils.deleteDirectory(new File(config.getConfigDir(), "cache")); } catch (IOException e12) { // noop } - scheduler.shutdownNow(); }).start(); } + private void clearHttpCache() throws IOException { + File httpCacheDir = new File(config.getConfigDir(), "cache"); + LOG.debug("Deleting http cache {}", httpCacheDir); + HttpClientCacheProvider.getCache(config).evictAll(); + HttpClientCacheProvider.getCache(config).close(); + IoUtils.deleteDirectory(httpCacheDir); + LOG.debug("Cache has been deleted"); + } + private void registerAlertSystem() { for (EventHandlerConfiguration eventHandlerConfig : Config.getInstance().getSettings().eventHandlers) { var handler = new EventHandler(eventHandlerConfig);