aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-01-14 11:37:12 -0800
committerGavin Andresen <gavinandresen@gmail.com>2013-01-14 11:37:12 -0800
commitdd46c88f2fe644d08b76159f5cb55cd5a1862504 (patch)
tree505a99247d8495152358a20a2dc7d743c62680bc /src
parent40e31fd373492ff85d48e4b59053fd497f078893 (diff)
parentf4445f9982a760869c430f3d4b1302f7eb509bd8 (diff)
downloadbitcoin-dd46c88f2fe644d08b76159f5cb55cd5a1862504.tar.xz
Merge pull request #2099 from gavinandresen/blkfile_upgrade
Upgrading to 0.8: re-use blkNNNN.dat files.
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 79e9b2fb10..29062452cd 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -729,6 +729,33 @@ bool AppInit2()
return InitError(msg);
}
+ // Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/
+ filesystem::path blocksDir = GetDataDir() / "blocks";
+ if (!filesystem::exists(blocksDir))
+ {
+ filesystem::create_directories(blocksDir);
+ bool linked = false;
+ for (unsigned int i = 1; i < 10000; i++) {
+ filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i);
+ if (!filesystem::exists(source)) break;
+ filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i-1);
+ try {
+ filesystem::create_hard_link(source, dest);
+ printf("Hardlinked %s -> %s\n", source.string().c_str(), dest.string().c_str());
+ linked = true;
+ } catch (filesystem::filesystem_error & e) {
+ // Note: hardlink creation failing is not a disaster, it just means
+ // blocks will get re-downloaded from peers.
+ printf("Error hardlinking blk%04u.dat : %s\n", i, e.what());
+ break;
+ }
+ }
+ if (linked)
+ {
+ fReindex = true;
+ }
+ }
+
// cache size calculations
size_t nTotalCache = GetArg("-dbcache", 25) << 20;
if (nTotalCache < (1 << 22))