]> source.dussan.org Git - jgit.git/commitdiff
Fix handling of missing pack index file 52/205552/4
authorDariusz Luksza <dariusz.luksza@gmail.com>
Mon, 20 Nov 2023 11:00:51 +0000 (11:00 +0000)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 28 Jan 2024 15:47:48 +0000 (16:47 +0100)
As demonstrated in
`UploadPackHandleDeletedPackFile.testV2IdxFileRemovedDuringUploadPack`
the fetch operation will fail when the pack index file is removed.

This is due to a wrapping of `FileNotFoundException` (which is a
subclass of `IOExeption`) in an `IOException` at PackIndex L#68. This
is then changing the behaviour of error handling in
`Pack.file.getBitmapIndex()` where the `FileNotFoundException` is
swallowed and allows the fetch process to continue. With FNFE being
wrapped in IOE, this blows up and breaks the fetch operation.

Simply rethrowing `FileNotFoundException` from `PackFile.open()` fixes
the broken fetch operation. This will also mark the whole pack as
invalid in the `IOException` handler in `Pack.idx()` method.

Change-Id: Ibe321aa1af21d26500e1cb2eb3464cc99a6dbc62
Signed-off-by: Dariusz Luksza <dariusz.luksza@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackHandleDeletedPackFileTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java

index b1c9447c7f31130461fe313cf3bd1a12f1cfa40e..417ce61df2e929ee693893ffce89d4cbf1795f62 100644 (file)
@@ -32,7 +32,6 @@ import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.transport.UploadPack.RequestPolicy;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -80,7 +79,6 @@ public class UploadPackHandleDeletedPackFileTest
        }
 
        @Test
-       @Ignore("pending fix")
        public void testV2IdxFileRemovedDuringUploadPack() throws Exception {
                doRemovePackFileDuringUploadPack(PackExt.INDEX);
        }
index 90f9811679b3c296928fbef153fe205a8f590ee6..27ad4fb07af537820913a6c407393577bb890a74 100644 (file)
@@ -1153,9 +1153,9 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
                                return idx;
                        }
                } catch (FileNotFoundException e) {
-                       // Once upon a time this bitmap file existed. Now it
-                       // has been removed. Most likely an external gc  has
-                       // removed this packfile and the bitmap
+                       // Once upon a time the bitmap or index files existed. Now one
+                       // of them has been removed. Most likely an external gc has
+                       // removed index, packfile or the bitmap
                }
                bitmapIdxFile = null;
                return null;
index 99987cd6354fadde0f1e97690b1ec283435f339c..c42d1c8866abefddeecd940521c646bf5cb408e6 100644 (file)
@@ -64,7 +64,9 @@ public abstract class PackIndex
        public static PackIndex open(File idxFile) throws IOException {
                try (SilentFileInputStream fd = new SilentFileInputStream(
                                idxFile)) {
-                               return read(fd);
+                       return read(fd);
+               } catch (FileNotFoundException e) {
+                       throw e;
                } catch (IOException ioe) {
                        throw new IOException(
                                        MessageFormat.format(JGitText.get().unreadablePackIndex,