[NO ISSUE] Simplify IoUtil delete API
Change-Id: I0dabcb642fa3007b3b6e9d30be9911a22ed8f252
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2502
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DropIndexTask.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DropIndexTask.java
index b7f0985..4bd97c1 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DropIndexTask.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DropIndexTask.java
@@ -52,7 +52,7 @@
final File indexFile = ioManager.resolve(file).getFile();
if (indexFile.exists()) {
File indexDir = indexFile.getParentFile();
- IoUtil.deleteDirectory(indexDir);
+ IoUtil.delete(indexDir);
LOGGER.info(() -> "Deleted index: " + indexFile.getAbsolutePath());
} else {
LOGGER.warning(() -> "Requested to delete a non-existing index: " + indexFile.getAbsolutePath());
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
index 396c026..03227ee 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
@@ -46,30 +46,29 @@
/**
* Delete a file
*
- * @param fileRef
- * the file to be deleted
- * @throws HyracksDataException
- * if the file couldn't be deleted
+ * @param fileRef the file to be deleted
+ * @throws HyracksDataException if the file couldn't be deleted
*/
public static void delete(FileReference fileRef) throws HyracksDataException {
delete(fileRef.getFile());
}
/**
- * Delete a file
+ * Delete a file or directory
*
- * @param file
- * the file to be deleted
- * @throws HyracksDataException
- * if the file couldn't be deleted
+ * @param file the file to be deleted
+ * @throws HyracksDataException if the file (or directory if exists) couldn't be deleted
*/
public static void delete(File file) throws HyracksDataException {
try {
if (file.isDirectory()) {
- deleteDirectory(file);
- } else {
- Files.delete(file.toPath());
+ if (!file.exists()) {
+ return;
+ } else if (!FileUtils.isSymlink(file)) {
+ cleanDirectory(file);
+ }
}
+ Files.delete(file.toPath());
} catch (NoSuchFileException | FileNotFoundException e) {
LOGGER.warn(() -> FILE_NOT_FOUND_MSG + ": " + e.getMessage(), e);
} catch (IOException e) {
@@ -80,10 +79,8 @@
/**
* Create a file on disk
*
- * @param fileRef
- * the file to create
- * @throws HyracksDataException
- * if the file already exists or if it couldn't be created
+ * @param fileRef the file to create
+ * @throws HyracksDataException if the file already exists or if it couldn't be created
*/
public static void create(FileReference fileRef) throws HyracksDataException {
if (fileRef.getFile().exists()) {
@@ -99,17 +96,7 @@
}
}
- public static void deleteDirectory(File directory) throws IOException {
- if (!directory.exists()) {
- return;
- }
- if (!FileUtils.isSymlink(directory)) {
- cleanDirectory(directory);
- }
- Files.delete(directory.toPath());
- }
-
- public static void cleanDirectory(final File directory) throws IOException {
+ private static void cleanDirectory(final File directory) throws IOException {
final File[] files = verifiedListFiles(directory);
for (final File file : files) {
delete(file);
@@ -133,4 +120,5 @@
}
return files;
}
+
}