If we're using -prune with -reindex, then delete block files that will be ignored by the reindex. Since reindexing works by starting at block file 0 and looping until a blockfile is missing, do the same here to delete any later block files after a gap. Also delete all rev files since they'll be rewritten by the reindex anyway. This ensures that m_blockfile_info is in sync with what's actually o
| 452 | // is in sync with what's actually on disk by the time we start downloading, so that pruning |
| 453 | // works correctly. |
| 454 | void CleanupBlockRevFiles() |
| 455 | { |
| 456 | std::map<std::string, fs::path> mapBlockFiles; |
| 457 | |
| 458 | // Glob all blk?????.dat and rev?????.dat files from the blocks directory. |
| 459 | // Remove the rev files immediately and insert the blk file paths into an |
| 460 | // ordered map keyed by block file index. |
| 461 | LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n"); |
| 462 | fs::path blocksdir = gArgs.GetBlocksDirPath(); |
| 463 | for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) { |
| 464 | const std::string path = fs::PathToString(it->path().filename()); |
| 465 | if (fs::is_regular_file(*it) && |
| 466 | path.length() == 12 && |
| 467 | path.substr(8,4) == ".dat") |
| 468 | { |
| 469 | if (path.substr(0, 3) == "blk") { |
| 470 | mapBlockFiles[path.substr(3, 5)] = it->path(); |
| 471 | } else if (path.substr(0, 3) == "rev") { |
| 472 | remove(it->path()); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | // Remove all block files that aren't part of a contiguous set starting at |
| 478 | // zero by walking the ordered map (keys are block file indices) by |
| 479 | // keeping a separate counter. Once we hit a gap (or if 0 doesn't exist) |
| 480 | // start removing block files. |
| 481 | int nContigCounter = 0; |
| 482 | for (const std::pair<const std::string, fs::path>& item : mapBlockFiles) { |
| 483 | if (LocaleIndependentAtoi<int>(item.first) == nContigCounter) { |
| 484 | nContigCounter++; |
| 485 | continue; |
| 486 | } |
| 487 | remove(item.second); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n) |
| 492 | { |
no test coverage detected