Michael Blow has submitted this change and it was merged. Change subject: [NO ISSUE] Simplify IoUtil delete API ......................................................................
[NO ISSUE] Simplify IoUtil delete API Change-Id: I0dabcb642fa3007b3b6e9d30be9911a22ed8f252 Reviewed-on: https://asterix-gerrit.ics.uci.edu/2502 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Contrib: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> --- M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/DropIndexTask.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java 2 files changed, 16 insertions(+), 28 deletions(-) Approvals: Anon. E. Moose #1000171: Jenkins: Verified; No violations found; ; Verified Murtadha Hubail: Looks good to me, approved 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; } + } -- To view, visit https://asterix-gerrit.ics.uci.edu/2502 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0dabcb642fa3007b3b6e9d30be9911a22ed8f252 Gerrit-PatchSet: 3 Gerrit-Project: asterixdb Gerrit-Branch: release-0.9.4-pre-rc Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]>
