GC: deleteOrphans: Use PackFile

It's easier to follow the logic here when we can use our own objects
instead of Strings.

Change-Id: I6a166edcc67903fc1ca3544f458634c4cef8fde7
Signed-off-by: Nasser Grainawi <quic_nasserg@quicinc.com>
This commit is contained in:
Nasser Grainawi 2021-03-03 17:05:21 -07:00
parent c57b2935cd
commit 093020864f
1 changed files with 16 additions and 13 deletions

View File

@ -12,6 +12,8 @@
import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
import static org.eclipse.jgit.internal.storage.pack.PackExt.KEEP;
import java.io.File;
import java.io.FileOutputStream;
@ -965,20 +967,21 @@ private void deleteOrphans() {
return;
}
String base = null;
String latestId = null;
for (String n : fileNames) {
if (n.endsWith(PACK_EXT) || n.endsWith(KEEP_EXT)) {
base = n.substring(0, n.lastIndexOf('.'));
} else {
if (base == null || !n.startsWith(base)) {
try {
Path delete = packDir.resolve(n);
FileUtils.delete(delete.toFile(),
FileUtils.RETRY | FileUtils.SKIP_MISSING);
LOG.warn(JGitText.get().deletedOrphanInPackDir, delete);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
PackFile pf = new PackFile(packDir.toFile(), n);
PackExt ext = pf.getPackExt();
if (ext.equals(PACK) || ext.equals(KEEP)) {
latestId = pf.getId();
}
if (latestId == null || !pf.getId().equals(latestId)) {
// no pack or keep for this id
try {
FileUtils.delete(pf,
FileUtils.RETRY | FileUtils.SKIP_MISSING);
LOG.warn(JGitText.get().deletedOrphanInPackDir, pf);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
}