fix(cleanup): Fixing an issue where empty run directory is not cleaned up.
@@ -109,13 +109,15 @@ public class ShutdownManager {
logger.info("Skipping cleanup, it is disabled.");
}
} catch (final Exception e) {
- logger.debug(String.format("Error trying cleanup: %s", e.getMessage()));
+ logger.debug("Error trying cleanup: ", e);
}
}
private void cleanup(File directory, List<File> skip) throws IOException {
IOException exception = null;
- for (final File file : directory.listFiles()) {
+ File[] files = directory.listFiles();
+ if (files != null) {
+ for (final File file : files) {
try {
if (skip.contains(file)) {
logger.debug("Skipping cleanup for: " + file.getAbsolutePath());
@@ -127,8 +129,11 @@ public class ShutdownManager {
exception = ioe;
}
}
+ }
- if (directory.listFiles().length == 0) {
+ files = directory.listFiles();
+ boolean noFiles = files == null || files.length == 0;
+ if (noFiles && directory.exists()) {
logger.info("Cleaning up directory: " + directory.getAbsolutePath());
FileUtils.forceDelete(directory);
}
