]> source.dussan.org Git - jgit.git/commitdiff
Fix GC.deleteEmptyRefsFolders 09/135809/3
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 27 Jan 2019 01:22:34 +0000 (02:22 +0100)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 28 Jan 2019 07:04:45 +0000 (02:04 -0500)
This method tried to iterate spurious files which may exist in the
.git/refs folder, e.g. on Mac a .DS_Store may have been created there by
inspecting the folder using the finder application. This led to a
NotDirectoryException when deleteEmptyRefsFolders tried to create an
iterator for such a file entry. Skip files contained in the refs folder
to ensure the method only tries to iterate contained folders but not
files.

Change-Id: I5f31e733072a35db1e93908a9c69a8891ae5c206
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

index 3caae72fc6e178cda58545f821c0a6baf06e4e04..d450f94941eabf65fb72908a104738911419f2b4 100644 (file)
@@ -91,6 +91,20 @@ public class GcDeleteEmptyRefsFoldersTest extends GcTestCase {
                assertFalse(refDir02.getParent().getParent().toFile().exists());
        }
 
+       @Test
+       public void emptyRefFoldersSkipFiles() throws Exception {
+               FileTime fileTime = FileTime.from(Instant.now().minusSeconds(31));
+               Path refFile = Files.createFile(refsDir.resolve(".DS_Store"));
+               Path refDir01 = Files.createDirectories(heads.resolve(REF_FOLDER_01));
+               Path refDir02 = Files.createDirectories(heads.resolve(REF_FOLDER_02));
+               setLastModifiedTime(fileTime, heads, REF_FOLDER_01);
+               setLastModifiedTime(fileTime, heads, REF_FOLDER_02);
+               assertTrue(refDir01.toFile().exists());
+               assertTrue(refDir02.toFile().exists());
+               gc.gc();
+               assertTrue(Files.exists(refFile));
+       }
+
        private void setLastModifiedTime(FileTime fileTime, Path path, String folder) throws IOException {
                long numParents = folder.chars().filter(c -> c == '/').count();
                Path folderPath = path.resolve(folder);
index 037338e36403dd25105708d87048b2fe4b9709fa..d4d6936a85c8798dc3a8a273e5264c19e92865de 100644 (file)
@@ -910,7 +910,8 @@ public class GC {
                // Avoid deleting a folder that was created after the threshold so that concurrent
                // operations trying to create a reference are not impacted
                Instant threshold = Instant.now().minus(30, ChronoUnit.SECONDS);
-               try (Stream<Path> entries = Files.list(refs)) {
+               try (Stream<Path> entries = Files.list(refs)
+                               .filter(Files::isDirectory)) {
                        Iterator<Path> iterator = entries.iterator();
                        while (iterator.hasNext()) {
                                try (Stream<Path> s = Files.list(iterator.next())) {