From 6270bd3dccb2207022a8334f5e24f2d93f002b5a Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Tue, 15 May 2018 16:01:03 +0200
Subject: [PATCH] OO-3473	: delete the temporary files only at the end
 of the wizard and not after the first created element

---
 .../wizard/CheckListStepRunnerCallback.java   | 22 +++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/olat/course/nodes/cl/ui/wizard/CheckListStepRunnerCallback.java b/src/main/java/org/olat/course/nodes/cl/ui/wizard/CheckListStepRunnerCallback.java
index fcf870967d3..c9f58fa3499 100644
--- a/src/main/java/org/olat/course/nodes/cl/ui/wizard/CheckListStepRunnerCallback.java
+++ b/src/main/java/org/olat/course/nodes/cl/ui/wizard/CheckListStepRunnerCallback.java
@@ -20,6 +20,7 @@
 package org.olat.course.nodes.cl.ui.wizard;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -32,6 +33,9 @@ import org.olat.core.gui.control.generic.wizard.StepRunnerCallback;
 import org.olat.core.gui.control.generic.wizard.StepsMainRunController;
 import org.olat.core.gui.control.generic.wizard.StepsRunContext;
 import org.olat.core.id.OLATResourceable;
+import org.olat.core.logging.OLog;
+import org.olat.core.logging.Tracing;
+import org.olat.core.util.FileUtils;
 import org.olat.core.util.StringHelper;
 import org.olat.core.util.resource.OresHelper;
 import org.olat.core.util.vfs.LocalFolderImpl;
@@ -62,6 +66,8 @@ import org.olat.modules.ModuleConfiguration;
  */
 public class CheckListStepRunnerCallback implements StepRunnerCallback {
 	
+	private static final OLog log = Tracing.createLoggerFor(CheckListStepRunnerCallback.class);
+	
 	private final OLATResourceable courseOres;
 	
 	public CheckListStepRunnerCallback(OLATResourceable courseOres) {
@@ -105,7 +111,6 @@ public class CheckListStepRunnerCallback implements StepRunnerCallback {
 					if(item instanceof VFSLeaf) {
 						VFSContainer container = checkboxManager.getFileContainer(courseEnv, checkNode);
 						VFSManager.copyContent(tmpContainer, container);
-						tmpContainer.deleteSilently();
 					}
 				}
 			}
@@ -116,11 +121,24 @@ public class CheckListStepRunnerCallback implements StepRunnerCallback {
 			if(dueDate) {
 				config.set(CheckListCourseNode.CONFIG_KEY_DUE_DATE, node.getDueDate());
 			}
-			config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, new Boolean(dueDate));
+			config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, Boolean.valueOf(dueDate));
 			
 			course.getEditorTreeModel().addCourseNode(checkNode, structureNode);
 		}
 		
+		for(Checkbox templateBox:templateCheckbox) {
+			if(StringHelper.containsNonWhitespace(templateBox.getFilename())) {
+				File path = new File(FolderConfig.getCanonicalTmpDir(), templateBox.getCheckboxId());
+				if(path.exists()) {
+					try {
+						FileUtils.deleteDirsAndFiles(path.toPath());
+					} catch (IOException e) {
+						log.error("Cannot cleanup tmp directory: " + path);
+					}
+				}
+			}
+		}
+
 		setScoreCalculation(data, (STCourseNode)structureNode, nodesIdent);
 		
 		return StepsMainRunController.DONE_MODIFIED;
-- 
GitLab