summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2013-11-17 23:50:41 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-11-17 23:50:41 -0500
commit216d9981f51ca4b68eef4ed6d465745f5d10190c (patch)
tree146f74a9df5a3b28163946d710dd3ee47ff9b721 /org.eclipse.jgit
parent97b8115be4fd5c8901ce39e53e11b3b425697574 (diff)
parent8da939221c2e244fe0ba979fa8419a90bf618315 (diff)
downloadjgit-216d9981f51ca4b68eef4ed6d465745f5d10190c.tar.gz
jgit-216d9981f51ca4b68eef4ed6d465745f5d10190c.zip
Merge "Don't delete .idx file if .pack file can't be deleted"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java57
1 files changed, 39 insertions, 18 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 3e26bc3e62..9eaeaa8c14 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -175,21 +175,9 @@ public class GC {
*
* @param oldPacks
* @param newPacks
- * @param ignoreErrors
- * <code>true</code> if we should ignore the fact that a certain
- * pack files or index files couldn't be deleted.
- * <code>false</code> if an exception should be thrown in such
- * cases
- * @throws IOException
- * if a pack file couldn't be deleted and
- * <code>ignoreErrors</code> is set to <code>false</code>
*/
private void deleteOldPacks(Collection<PackFile> oldPacks,
- Collection<PackFile> newPacks, boolean ignoreErrors)
- throws IOException {
- int deleteOptions = FileUtils.RETRY | FileUtils.SKIP_MISSING;
- if (ignoreErrors)
- deleteOptions |= FileUtils.IGNORE_ERRORS;
+ Collection<PackFile> newPacks) {
oldPackLoop: for (PackFile oldPack : oldPacks) {
String oldName = oldPack.getPackName();
// check whether an old pack file is also among the list of new
@@ -200,10 +188,7 @@ public class GC {
if (!oldPack.shouldBeKept()) {
oldPack.close();
- for (PackExt ext : PackExt.values()) {
- File f = nameFor(oldName, "." + ext.getExtension()); //$NON-NLS-1$
- FileUtils.delete(f, deleteOptions);
- }
+ prunePack(oldName);
}
}
// close the complete object database. Thats my only chance to force
@@ -212,6 +197,42 @@ public class GC {
}
/**
+ * Delete files associated with a single pack file. First try to delete the
+ * ".pack" file because on some platforms the ".pack" file may be locked and
+ * can't be deleted. In such a case it is better to detect this early and
+ * give up on deleting files for this packfile. Otherwise we may delete the
+ * ".index" file and when failing to delete the ".pack" file we are left
+ * with a ".pack" file without a ".index" file.
+ *
+ * @param packName
+ */
+ private void prunePack(String packName) {
+ PackExt[] extensions = PackExt.values();
+ try {
+ // Delete the .pack file first and if this fails give up on deleting
+ // the other files
+ int deleteOptions = FileUtils.RETRY | FileUtils.SKIP_MISSING;
+ for (PackExt ext : extensions)
+ if (PackExt.PACK.equals(ext)) {
+ File f = nameFor(packName, "." + ext.getExtension()); //$NON-NLS-1$
+ FileUtils.delete(f, deleteOptions);
+ break;
+ }
+ // The .pack file has been deleted. Delete as many as the other
+ // files as you can.
+ deleteOptions |= FileUtils.IGNORE_ERRORS;
+ for (PackExt ext : extensions) {
+ if (!PackExt.PACK.equals(ext)) {
+ File f = nameFor(packName, "." + ext.getExtension()); //$NON-NLS-1$
+ FileUtils.delete(f, deleteOptions);
+ }
+ }
+ } catch (IOException e) {
+ // Deletion of the .pack file failed. Silently return.
+ }
+ }
+
+ /**
* Like "git prune-packed" this method tries to prune all loose objects
* which can be found in packs. If certain objects can't be pruned (e.g.
* because the filesystem delete operation fails) this is silently ignored.
@@ -533,7 +554,7 @@ public class GC {
if (rest != null)
ret.add(rest);
}
- deleteOldPacks(toBeDeleted, ret, true);
+ deleteOldPacks(toBeDeleted, ret);
prunePacked();
lastPackedRefs = refsBefore;