asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject [2/5] asterixdb git commit: [NO ISSUE] Simplify IoUtil delete API
Date Wed, 21 Mar 2018 20:52:38 GMT
[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>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/60bdec3b
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/60bdec3b
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/60bdec3b

Branch: refs/heads/release-0.9.4-pre-rc
Commit: 60bdec3bfb328806aa97bbb1580446e994c1ab9b
Parents: 3c32971
Author: Michael Blow <mblow@apache.org>
Authored: Tue Mar 20 09:37:22 2018 -0400
Committer: Michael Blow <mblow@apache.org>
Committed: Tue Mar 20 09:52:17 2018 -0700

----------------------------------------------------------------------
 .../replication/messaging/DropIndexTask.java    |  2 +-
 .../org/apache/hyracks/api/util/IoUtil.java     | 42 +++++++-------------
 2 files changed, 16 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/60bdec3b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DropIndexTask.java
----------------------------------------------------------------------
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 @@ public class DropIndexTask implements IReplicaTask {
             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());

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/60bdec3b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
----------------------------------------------------------------------
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 @@ public class IoUtil {
     /**
      * 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 @@ public class IoUtil {
     /**
      * 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 class IoUtil {
         }
     }
 
-    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 @@ public class IoUtil {
         }
         return files;
     }
+
 }


Mime
View raw message