]> source.dussan.org Git - jgit.git/commitdiff
ObjectDirectory: Factor a method to close open pack handles 63/110863/2
authorDave Borowitz <dborowitz@google.com>
Wed, 1 Nov 2017 14:42:46 +0000 (10:42 -0400)
committerDave Borowitz <dborowitz@google.com>
Wed, 1 Nov 2017 16:40:13 +0000 (12:40 -0400)
Change-Id: I9490c4583fdf801de9c0bb09595ebb8fb4926988

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java

index 8cd8ee152207052146987e5ba4ae135c3ac98ad0..f992a334084f994e1a9f38d88852321ad37e30af 100644 (file)
@@ -1173,16 +1173,7 @@ public class GC {
                        // rename the temporary files to real files
                        File realPack = nameFor(id, ".pack"); //$NON-NLS-1$
 
-                       // if the packfile already exists (because we are rewriting a
-                       // packfile for the same set of objects maybe with different
-                       // PackConfig) then make sure we get rid of all handles on the file.
-                       // Windows will not allow for rename otherwise.
-                       if (realPack.exists())
-                               for (PackFile p : repo.getObjectDatabase().getPacks())
-                                       if (realPack.getPath().equals(p.getPackFile().getPath())) {
-                                               p.close();
-                                               break;
-                                       }
+                       repo.getObjectDatabase().closeAllPackHandles(realPack);
                        tmpPack.setReadOnly();
 
                        FileUtils.rename(tmpPack, realPack, StandardCopyOption.ATOMIC_MOVE);
index 9629e36fa568d5f843d58e56f71c16080950bb5a..7d351704d4d699534f9d24ddd873db9de374360a 100644 (file)
@@ -969,6 +969,21 @@ public class ObjectDirectory extends FileObjectDatabase {
                return nameSet;
        }
 
+       void closeAllPackHandles(File packFile) {
+               // if the packfile already exists (because we are rewriting a
+               // packfile for the same set of objects maybe with different
+               // PackConfig) then make sure we get rid of all handles on the file.
+               // Windows will not allow for rename otherwise.
+               if (packFile.exists()) {
+                       for (PackFile p : getPacks()) {
+                               if (packFile.getPath().equals(p.getPackFile().getPath())) {
+                                       p.close();
+                                       break;
+                               }
+                       }
+               }
+       }
+
        AlternateHandle[] myAlternates() {
                AlternateHandle[] alt = alternates.get();
                if (alt == null) {