From: James Melvin Date: Tue, 27 Dec 2016 21:08:56 +0000 (-0700) Subject: Fix keep pack filename X-Git-Tag: v4.7.0.201704051617-r~142 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d980a3fa85d7f9608f33e8c926c7a7d15f607725;p=jgit.git Fix keep pack filename Previously it was looking for a keep file with the name of a pack file (extenstion included) appended with a '.keep'. However, the keep file name should be the pack file name with a '.keep' extension Change-Id: I9dc4c7c393ae20aefa0b9507df8df83610ce4d42 Signed-off-by: James Melvin --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java index 9e28298823..1a5084477d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java @@ -73,7 +73,10 @@ public class GcKeepFilesTest extends GcTestCase { .iterator(); PackFile singlePack = packIt.next(); assertFalse(packIt.hasNext()); - File keepFile = new File(singlePack.getPackFile().getPath() + ".keep"); + String packFileName = singlePack.getPackFile().getPath(); + String keepFileName = packFileName.substring(0, + packFileName.lastIndexOf('.')) + ".keep"; + File keepFile = new File(keepFileName); assertFalse(keepFile.exists()); assertTrue(keepFile.createNewFile()); bb.commit().add("A", "A2").add("B", "B2").create(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java index b385b8ab73..edf44fb6ec 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.internal.storage.file; import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX; +import static org.eclipse.jgit.internal.storage.pack.PackExt.KEEP; import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX; import java.io.EOFException; @@ -241,7 +242,7 @@ public class PackFile implements Iterable { */ public boolean shouldBeKept() { if (keepFile == null) - keepFile = new File(packFile.getPath() + ".keep"); //$NON-NLS-1$ + keepFile = extFile(KEEP); return keepFile.exists(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackExt.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackExt.java index 4ee27cc845..248692f93f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackExt.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackExt.java @@ -53,6 +53,9 @@ public class PackExt { /** A pack index file extension. */ public static final PackExt INDEX = newPackExt("idx"); //$NON-NLS-1$ + /** A keep pack file extension. */ + public static final PackExt KEEP = newPackExt("keep"); //$NON-NLS-1$ + /** A pack bitmap index file extension. */ public static final PackExt BITMAP_INDEX = newPackExt("bitmap"); //$NON-NLS-1$