]> source.dussan.org Git - jgit.git/commitdiff
Fix GC to delete empty fanout directories after repacking 18/139118/1
authorMatthias Sohn <matthias.sohn@sap.com>
Wed, 20 Mar 2019 12:54:10 +0000 (13:54 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 20 Mar 2019 13:10:30 +0000 (14:10 +0100)
The prune method did not delete empty fanout directories when loose
objects moved to a new pack file but only when loose unreferenced
objects were pruned.

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

index 5b1a4178a6df4ac870f6e78752a9827a1c605d52..345207089fbad6bb5ce5250c3984b9bb15f88cb3 100644 (file)
@@ -47,6 +47,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.util.Collections;
 import java.util.Date;
 
@@ -113,8 +114,24 @@ public class GcPruneNonReferencedTest extends GcTestCase {
                fsTick();
                gc.gc();
                stats = gc.getStatistics();
+               assertNoEmptyFanoutDirectories();
                assertEquals(0, stats.numberOfLooseObjects);
                assertEquals(8, stats.numberOfPackedObjects);
                assertEquals(2, stats.numberOfPackFiles);
        }
+
+       private void assertNoEmptyFanoutDirectories() {
+               File[] fanout = repo.getObjectsDirectory().listFiles();
+               for (File f : fanout) {
+                       if (f.isDirectory()) {
+                               String[] entries = f.list();
+                               if (entries == null || entries.length == 0) {
+                                       assertFalse(
+                                                       "Found empty fanout directory "
+                                                                       + f.getAbsolutePath() + " after pruning",
+                                                       f.getName().length() == 2);
+                               }
+                       }
+               }
+       }
 }
index 1b62c14dd35edbbadd837849ecf32aa30a5e2ad6..092bd6da8c31a3bd78223905781b406298130b0b 100644 (file)
@@ -545,9 +545,12 @@ public class GC {
                                pm.update(1);
                                if (d.length() != 2)
                                        continue;
-                               File[] entries = new File(objects, d).listFiles();
-                               if (entries == null)
+                               File dir = new File(objects, d);
+                               File[] entries = dir.listFiles();
+                               if (entries == null || entries.length == 0) {
+                                       FileUtils.delete(dir, FileUtils.IGNORE_ERRORS);
                                        continue;
+                               }
                                for (File f : entries) {
                                        checkCancelled();
                                        String fName = f.getName();