]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java
Fixed unsafe handling of temporary directory deletion.
[simantics/fmil.git] / org.simantics.fmil.core / src / org / simantics / fmil / core / FMIL.java
index 7301caf4c8209883e9d77aaaa3fc3e5bc6a5aa17..f4c7ca4f2fbbf7d044be10c09a2b4f896b31fe0b 100644 (file)
@@ -6,6 +6,7 @@ import java.io.RandomAccessFile;
 import java.net.URL;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -193,21 +194,23 @@ public class FMIL {
                 fmuN = 0;
             }
 
-            File tempDir = new File(fmuDir);
-            if(tempDir.isDirectory()) {
+            java.nio.file.Path tempDir = Paths.get(fmuDir);
+            if(Files.exists(tempDir) && Files.isDirectory(tempDir)) {
                 try {
-                    FileUtils.deleteAll(tempDir);
+                       FileUtils.emptyDirectory(tempDir);
                 } catch (IOException e) {
-                    throw new FMILException("Could not create temp folder for fmu");
+                    throw new FMILException("Could not delete existing files from temp folder for fmu " + path, e);
                 }
-                tempDir.mkdir();
             } else {
-                tempDir.mkdir();
+                try {
+                       Files.createDirectory(tempDir);
+                } catch (IOException e) {
+                    throw new FMILException("Could not create temp folder for fmu " + path, e);
+                }
             }
 
-
             try {
-                String tmpPath = tempDir.getAbsolutePath();
+                String tmpPath = tempDir.toString();
                 if(!tmpPath.endsWith("\\") && !tmpPath.endsWith("/"))
                     tmpPath = tmpPath + "/";
                 id = loadFMUFile_(path, tmpPath);