Skip to content

Commit

Permalink
Merge pull request #2099 from gavinandresen/blkfile_upgrade
Browse files Browse the repository at this point in the history
Upgrading to 0.8: re-use blkNNNN.dat files.
  • Loading branch information
gavinandresen committed Jan 14, 2013
2 parents 40e31fd + f4445f9 commit dd46c88
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit dd46c88

Please sign in to comment.