From 94fad4412ae151c0a71150e8b83edc0ecd10adf3 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sun, 19 Aug 2018 20:48:06 +0200 Subject: [PATCH 1/3] Suppress warning for trying to delete non-empty directory This is actually a fairly common occurrence; deleting the parent directories can work only if the file deleted was the last one in the directory. Bug: 537872 Change-Id: I86d1d45e1e2631332025ff24af8dfd46c9725711 Signed-off-by: Thomas Wolf (cherry picked from commit d9e767b431eae7978613cc8e0ade7467ec04376c) Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/internal/storage/file/RefDirectory.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 48fdf8119..d16ca7095 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -63,6 +63,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.DirectoryNotEmptyException; import java.nio.file.Files; import java.security.DigestInputStream; import java.security.MessageDigest; @@ -1093,6 +1094,10 @@ public class RefDirectory extends RefDatabase { for (int i = 0; i < depth; ++i) { try { Files.delete(dir.toPath()); + } catch (DirectoryNotEmptyException e) { + // Don't log; normal case when there are other refs with the + // same prefix + break; } catch (IOException e) { LOG.warn("Unable to remove path {}", dir, e); break; From c78d6445ec927b660e2abe6e9e0bd6324215b0a5 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 23 Aug 2018 11:44:28 +0200 Subject: [PATCH 2/3] Externalize warning message in RefDirectory.delete() Change-Id: Icec16c01853a3f5ea016d454b3d48624498efcce Signed-off-by: Matthias Sohn (cherry picked from commit 5e68fe245fb97f38620ea683dbeab724bf86da4c) Signed-off-by: David Pursehouse --- .../resources/org/eclipse/jgit/internal/JGitText.properties | 1 + org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java | 1 + .../org/eclipse/jgit/internal/storage/file/RefDirectory.java | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 873cf526b..34457c936 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -647,6 +647,7 @@ truncatedHunkOldLinesMissing=Truncated hunk, at least {0} old lines is missing tSizeMustBeGreaterOrEqual1=tSize must be >= 1 unableToCheckConnectivity=Unable to check connectivity. unableToCreateNewObject=Unable to create new object: {0} +unableToRemovePath=Unable to remove path ''{0}'' unableToStore=Unable to store {0}. unableToWrite=Unable to write {0} unauthorized=Unauthorized diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 9ea0aa570..41f3c2a48 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -706,6 +706,7 @@ public class JGitText extends TranslationBundle { /***/ public String tSizeMustBeGreaterOrEqual1; /***/ public String unableToCheckConnectivity; /***/ public String unableToCreateNewObject; + /***/ public String unableToRemovePath; /***/ public String unableToStore; /***/ public String unableToWrite; /***/ public String unauthorized; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index d16ca7095..91f5d7dc8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -1099,7 +1099,8 @@ public class RefDirectory extends RefDatabase { // same prefix break; } catch (IOException e) { - LOG.warn("Unable to remove path {}", dir, e); + LOG.warn(MessageFormat.format(JGitText.get().unableToRemovePath, + dir), e); break; } dir = dir.getParentFile(); From 667ac8b3189336efbdb0484e212c36beb4ed5338 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 27 Aug 2018 01:13:38 +0200 Subject: [PATCH 3/3] Fix NoSuchFileException during directory cleanup in RefDirectory Bug: 538285 Change-Id: Iab5c381a412cb2c2176af55189668c267ed29fbc Signed-off-by: Matthias Sohn (cherry picked from commit 8ab89ef066f91a7d39b705f4e61498f37291ffab) Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/internal/storage/file/RefDirectory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 91f5d7dc8..8338b2c8a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -1093,7 +1093,7 @@ public class RefDirectory extends RefDatabase { File dir = file.getParentFile(); for (int i = 0; i < depth; ++i) { try { - Files.delete(dir.toPath()); + Files.deleteIfExists(dir.toPath()); } catch (DirectoryNotEmptyException e) { // Don't log; normal case when there are other refs with the // same prefix