summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java3
2 files changed, 16 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java
index 3caae72fc6..d450f94941 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java
@@ -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);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 037338e364..d4d6936a85 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -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())) {