Delete old job directory automatically
[jabaws.git] / engine / compbio / engine / Cleaner.java
index 4813388..ce9c774 100644 (file)
@@ -22,11 +22,17 @@ import java.util.List;
 \r
 import org.apache.log4j.Logger;\r
 \r
+import compbio.engine.conf.PropertyHelperManager;\r
 import compbio.engine.client.ConfiguredExecutable;\r
 import compbio.engine.client.PathValidator;\r
 import compbio.engine.local.ExecutableWrapper;\r
+import compbio.util.PropertyHelper;\r
 \r
-@Deprecated\r
+//@Deprecated\r
+\r
+// TODO\r
+// understand what this class does and why it was set as deprecated ...\r
+// how to check timestamps of files before deleting\r
 public class Cleaner {\r
 \r
        private static final Logger log = Logger.getLogger(Cleaner.class);\r
@@ -56,10 +62,8 @@ public class Cleaner {
                // Remove process std output and error capture files, do not care\r
                // whether succeed or not\r
                // as these are only created for local processes, so may not exist\r
-               removeFile(exec.getWorkDirectory() + File.separator\r
-                               + ExecutableWrapper.PROC_OUT_FILE);\r
-               removeFile(exec.getWorkDirectory() + File.separator\r
-                               + ExecutableWrapper.PROC_ERR_FILE);\r
+               removeFile(exec.getWorkDirectory() + File.separator + ExecutableWrapper.PROC_OUT_FILE);\r
+               removeFile(exec.getWorkDirectory() + File.separator + ExecutableWrapper.PROC_ERR_FILE);\r
                // Remove the task directory if all files were successfully removed\r
                return removeFile(exec.getWorkDirectory());\r
        }\r
@@ -88,12 +92,11 @@ public class Cleaner {
 \r
        public static boolean deleteAllFiles(String directory) {\r
                if (compbio.util.Util.isEmpty(directory)) {\r
-                       throw new NullPointerException("Direcotry must be provided! ");\r
+                       throw new NullPointerException("Directory must be provided! ");\r
                }\r
                File rootdir = new File(directory);\r
                if (!rootdir.exists()) {\r
-                       log.error("Directory " + directory\r
-                                       + " does not exist. Have been deleted already?");\r
+                       log.error("Directory " + directory + " does not exist. Have been deleted already?");\r
                        return false;\r
                }\r
                if (!rootdir.isDirectory()) {\r
@@ -105,15 +108,24 @@ public class Cleaner {
                int deletedCount = 0;\r
                for (File f : files) {\r
                        if (f.isDirectory()) {\r
-                               log.error("Cannot delete subdirecotries! Skipping...");\r
+                               log.error("Cannot delete subdirectories! Skipping...");\r
                        } else {\r
-                               boolean deleted = f.delete();\r
-                               if (deleted) {\r
+                               if (f.delete()) {\r
                                        deletedCount++;\r
                                }\r
                        }\r
                }\r
+               rootdir.delete();\r
                return deletedCount == files.length;\r
        }\r
 \r
+       public static boolean deleteDirectory(String directory) {\r
+               if (deleteAllFiles (directory)) {\r
+                       File rootdir = new File(directory);\r
+                       return rootdir.delete();\r
+               }\r
+               return false;\r
+       }\r
+\r
+       \r
 }\r