|
|
@@ -346,7 +346,7 @@ public class GC { |
|
|
|
if (shouldLoosen) { |
|
|
|
loosen(inserter, reader, oldPack, ids); |
|
|
|
} |
|
|
|
prunePack(oldName); |
|
|
|
prunePack(oldPack.getPackFile()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -360,19 +360,17 @@ public class GC { |
|
|
|
* moves the pack file to the preserved directory |
|
|
|
* |
|
|
|
* @param packFile |
|
|
|
* @param packName |
|
|
|
* @param ext |
|
|
|
* @param deleteOptions |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
private void removeOldPack(File packFile, String packName, PackExt ext, |
|
|
|
int deleteOptions) throws IOException { |
|
|
|
private void removeOldPack(PackFile packFile, int deleteOptions) |
|
|
|
throws IOException { |
|
|
|
if (pconfig.isPreserveOldPacks()) { |
|
|
|
File oldPackDir = repo.getObjectDatabase().getPreservedDirectory(); |
|
|
|
FileUtils.mkdir(oldPackDir, true); |
|
|
|
|
|
|
|
String oldPackName = "pack-" + packName + ".old-" + ext.getExtension(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
|
|
File oldPackFile = new File(oldPackDir, oldPackName); |
|
|
|
PackFile oldPackFile = packFile |
|
|
|
.createPreservedForDirectory(oldPackDir); |
|
|
|
FileUtils.rename(packFile, oldPackFile); |
|
|
|
} else { |
|
|
|
FileUtils.delete(packFile, deleteOptions); |
|
|
@@ -401,27 +399,21 @@ public class GC { |
|
|
|
* ".index" file and when failing to delete the ".pack" file we are left |
|
|
|
* with a ".pack" file without a ".index" file. |
|
|
|
* |
|
|
|
* @param packName |
|
|
|
* @param packFile |
|
|
|
*/ |
|
|
|
private void prunePack(String packName) { |
|
|
|
PackExt[] extensions = PackExt.values(); |
|
|
|
private void prunePack(PackFile packFile) { |
|
|
|
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$ |
|
|
|
removeOldPack(f, packName, ext, deleteOptions); |
|
|
|
break; |
|
|
|
} |
|
|
|
removeOldPack(packFile.create(PackExt.PACK), deleteOptions); |
|
|
|
|
|
|
|
// The .pack file has been deleted. Delete as many as the other |
|
|
|
// files as you can. |
|
|
|
deleteOptions |= FileUtils.IGNORE_ERRORS; |
|
|
|
for (PackExt ext : extensions) { |
|
|
|
for (PackExt ext : PackExt.values()) { |
|
|
|
if (!PackExt.PACK.equals(ext)) { |
|
|
|
File f = nameFor(packName, "." + ext.getExtension()); //$NON-NLS-1$ |
|
|
|
removeOldPack(f, packName, ext, deleteOptions); |
|
|
|
removeOldPack(packFile.create(ext), deleteOptions); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
@@ -1218,7 +1210,7 @@ public class GC { |
|
|
|
} |
|
|
|
|
|
|
|
// rename the temporary files to real files |
|
|
|
File realPack = nameFor(id, ".pack"); //$NON-NLS-1$ |
|
|
|
File realPack = nameFor(id, PackExt.PACK); |
|
|
|
|
|
|
|
repo.getObjectDatabase().closeAllPackHandles(realPack); |
|
|
|
tmpPack.setReadOnly(); |
|
|
@@ -1228,8 +1220,7 @@ public class GC { |
|
|
|
File tmpExt = tmpEntry.getValue(); |
|
|
|
tmpExt.setReadOnly(); |
|
|
|
|
|
|
|
File realExt = nameFor(id, |
|
|
|
"." + tmpEntry.getKey().getExtension()); //$NON-NLS-1$ |
|
|
|
File realExt = nameFor(id, tmpEntry.getKey()); |
|
|
|
try { |
|
|
|
FileUtils.rename(tmpExt, realExt, |
|
|
|
StandardCopyOption.ATOMIC_MOVE); |
|
|
@@ -1275,9 +1266,9 @@ public class GC { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private File nameFor(String name, String ext) { |
|
|
|
File packdir = repo.getObjectDatabase().getPackDirectory(); |
|
|
|
return new File(packdir, "pack-" + name + ext); //$NON-NLS-1$ |
|
|
|
private PackFile nameFor(String name, PackExt ext) { |
|
|
|
return new PackFile(repo.getObjectDatabase().getPackDirectory(), |
|
|
|
"pack-" + name).create(ext); //$NON-NLS-1$ |
|
|
|
} |
|
|
|
|
|
|
|
private void checkCancelled() throws CancelledException { |