package com.github.sakserv.minicluster.util;

import java.io.File;

import org.slf4j.LoggerFactory;


public class FileUtils {

    // Logger
    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(FileUtils.class);

    public static void deleteFolder(String directory) {
        File directoryToClean = new File(directory);
        String directoryAbsPath = directoryToClean.getAbsolutePath();

        LOG.info("FILEUTILS: Deleting contents of directory: {}", directoryAbsPath);

        File[] files = directoryToClean.listFiles();
        if(files!=null) { //some JVMs return null for empty dirs
            for(File f: files) {
                if(f.isDirectory()) {
                    f.setWritable(true);
                    deleteFolder(f.getAbsolutePath());
                } else {
                    LOG.debug("FILEUTILS: Deleting file: {}", f.getAbsolutePath());
                    f.setWritable(true);
                    f.delete();
                }
            }
        }
        LOG.debug("FILEUTILS: Deleting file: {}", directoryToClean.getAbsolutePath());
        directoryToClean.setWritable(true);
        directoryToClean.delete();
    }

    @Override
    public String toString() {
        return "FileUtils";
    }
}

@@ -39,16 +39,49 @@
 .util;%0A%0A
+import org.slf4j.LoggerFactory;%0A%0A
 import j
@@ -97,39 +97,63 @@
 le;%0A
-%0A
 import 
-org.slf4j.LoggerFactory
+java.net.URI;%0Aimport java.net.URISyntaxException
 ;%0A%0A%0A
@@ -159,16 +159,22 @@
 %0Apublic 
+final 
 class Fi
@@ -382,99 +382,360 @@
  = n
-ew File(directory);%0A        String directoryAbsPath = directoryToClean.getAbsolutePath();%0A%0A
+ull;%0A        try %7B%0A            directoryToClean = new File(new URI(directory).getPath());%0A        %7D catch (URISyntaxException e) %7B%0A            LOG.error(%22Directory is invalid for URI conversion: %22 + directory, e);%0A        %7D%0A%0A        if (directoryToClean == null) %7B%0A          LOG.error(%22Directory to cleanup is null, skipping...%22);%0A        %7D else %7B%0A    
     
@@ -809,19 +809,41 @@
 tory
-Abs
+ToClean.getAbsolute
 Path
+()
 );%0A%0A
+    
     
@@ -903,18 +903,25 @@
     
+   
+ 
 if
+ 
 (files
+ 
 !=
+ 
 null
@@ -979,18 +979,24 @@
     
+    
 for
+ 
 (File f
+ 
 : fi
@@ -1018,18 +1018,23 @@
         
+  
+  
 if
+ 
 (f.isDir
@@ -1057,32 +1057,36 @@
                 
+   
+ 
 f.setWritable(tr
@@ -1082,32 +1082,36 @@
 Writable(true);%0A
+    
                 
@@ -1157,32 +1157,36 @@
                 
+ 
+   
 %7D else %7B%0A       
@@ -1170,32 +1170,36 @@
        %7D else %7B%0A
+    
                 
@@ -1278,32 +1278,36 @@
                 
+    
 f.setWritable(tr
@@ -1331,16 +1331,20 @@
         
+  
+  
 f.delete
@@ -1343,24 +1343,28 @@
 f.delete();%0A
+    
             
@@ -1385,20 +1385,32 @@
     
-%7D%0A    
     %7D%0A
+            %7D%0A    
     
@@ -1492,32 +1492,36 @@
 ath());%0A        
+    
 directoryToClean
@@ -1540,32 +1540,36 @@
 (true);%0A        
+  
+  
 directoryToClean
@@ -1575,24 +1575,34 @@
 n.delete();%0A
+        %7D%0A
     %7D%0A%0A    @

handle malformed URIs when deleting directories