From a2d4991e42eaaea8b8a25639406d24e9ec257440 Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 17 Jun 2019 21:12:44 +0800 Subject: [PATCH] Fix file deletion bug --- src/main/java/run/halo/app/utils/FileUtils.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/run/halo/app/utils/FileUtils.java b/src/main/java/run/halo/app/utils/FileUtils.java index b03d29452..ce8512c39 100644 --- a/src/main/java/run/halo/app/utils/FileUtils.java +++ b/src/main/java/run/halo/app/utils/FileUtils.java @@ -66,25 +66,16 @@ public class FileUtils { public static void deleteFolder(@NonNull Path deletingPath) throws IOException { Assert.notNull(deletingPath, "Deleting path must not be null"); + if (Files.notExists(deletingPath)) { + return; + } + log.info("Deleting [{}]", deletingPath); // Delete folder recursively org.eclipse.jgit.util.FileUtils.delete(deletingPath.toFile(), org.eclipse.jgit.util.FileUtils.RECURSIVE | org.eclipse.jgit.util.FileUtils.RETRY); -// try (Stream pathStream = Files.walk(deletingPath)) { -// pathStream.sorted(Comparator.reverseOrder()) -// .peek(path -> log.debug("Try to delete [{}]", path.toString())) -// .forEach(path -> { -// try { -// Files.delete(path); -// log.debug("Deleted [{}] successfully", path.toString()); -// } catch (IOException e) { -// throw new ServiceException("Failed to delete " + path.toString(), e).setErrorData(deletingPath.toString()); -// } -// }); -// } - log.info("Deleted [{}] successfully", deletingPath); }