From e5a7f0ba2a6f764c8d83fe72a49834c81b303b5e Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Mon, 2 Dec 2024 18:40:07 +0100 Subject: [PATCH] rectify Signed-off-by: Thang PHAM --- .../DynamicSimulationWorkerService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java index 506cf11..15494ee 100644 --- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java +++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java @@ -208,6 +208,16 @@ public Consumer> consumeCancel() { return super.consumeCancel(); } + @Override + protected void clean(AbstractResultContext resultContext) { + super.clean(resultContext); + if (!resultContext.getRunContext().isDebug()) { + // clean dump directory + Path dumpDir = getDumpDir(resultContext.getRunContext().getDynamicSimulationParameters()); + removeDirectory(dumpDir); + } + } + // --- Dump file related methods --- // private void setupDumpParameters(Path workDir, DynamicSimulationParameters parameters) { @@ -242,4 +252,16 @@ private byte[] zipDumpFile(Path dumpDir) { } return outputState; } + + private void removeDirectory(Path dir) { + if (dir != null) { + try { + FileUtil.removeDir(dir); + } catch (IOException e) { + LOGGER.error(String.format("%s: Error occurred while cleaning directory at %s", getComputationType(), dir.toAbsolutePath()), e); + } + } else { + LOGGER.info("{}: No directory to clean", getComputationType()); + } + } }