Delete existing repository before extracting bootstrap

This limits the amount of additional space needed to the size of the compressed bootstrap (currently just under 4GB for full nodes, or 200MB for top-only nodes).
This commit is contained in:
CalDescent 2021-10-04 09:15:54 +01:00
parent de3ebf664f
commit 0135f25b9d

View File

@ -385,11 +385,6 @@ public class Bootstrap {
blockchainLock.lockInterruptibly();
try {
this.updateStatus("Extracting bootstrap...");
Path input = path.toAbsolutePath();
Path output = path.toAbsolutePath().getParent().toAbsolutePath();
SevenZ.decompress(input.toString(), output.toFile());
this.updateStatus("Stopping repository...");
// Close the repository while we are still able to
// Otherwise, the caller will run into difficulties when it tries to close it
@ -398,15 +393,22 @@ public class Bootstrap {
// Now close the repository factory so that we can swap out the database files
RepositoryManager.closeRepositoryFactory();
this.updateStatus("Deleting existing repository...");
Path input = path.toAbsolutePath();
Path output = path.toAbsolutePath().getParent().toAbsolutePath();
Path inputPath = Paths.get(output.toString(), "bootstrap");
Path outputPath = Paths.get(Settings.getInstance().getRepositoryPath());
FileUtils.deleteDirectory(outputPath.toFile());
this.updateStatus("Extracting bootstrap...");
SevenZ.decompress(input.toString(), output.toFile());
if (!inputPath.toFile().exists()) {
throw new DataException("Extracted bootstrap doesn't exist");
}
// Move the "bootstrap" folder in place of the "db" folder
this.updateStatus("Moving files to output directory...");
FileUtils.deleteDirectory(outputPath.toFile());
Files.move(inputPath, outputPath);
this.updateStatus("Starting repository from bootstrap...");