Browse Source

When reindexing check for file before trying to open (refactored)

0.10
Suhas Daftuar 10 years ago
parent
commit
ec7eb0fa80
  1. 4
      src/init.cpp
  2. 8
      src/main.cpp
  3. 2
      src/main.h

4
src/init.cpp

@ -401,9 +401,11 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
int nFile = 0; int nFile = 0;
while (true) { while (true) {
CDiskBlockPos pos(nFile, 0); CDiskBlockPos pos(nFile, 0);
if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk")))
break; // No block files left to reindex
FILE *file = OpenBlockFile(pos, true); FILE *file = OpenBlockFile(pos, true);
if (!file) if (!file)
break; break; // This error is logged in OpenBlockFile
LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile); LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
LoadExternalBlockFile(file, &pos); LoadExternalBlockFile(file, &pos);
nFile++; nFile++;

8
src/main.cpp

@ -2766,7 +2766,7 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
{ {
if (pos.IsNull()) if (pos.IsNull())
return NULL; return NULL;
boost::filesystem::path path = GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile); boost::filesystem::path path = GetBlockPosFilename(pos, prefix);
boost::filesystem::create_directories(path.parent_path()); boost::filesystem::create_directories(path.parent_path());
FILE* file = fopen(path.string().c_str(), "rb+"); FILE* file = fopen(path.string().c_str(), "rb+");
if (!file && !fReadOnly) if (!file && !fReadOnly)
@ -2793,6 +2793,12 @@ FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly) {
return OpenDiskFile(pos, "rev", fReadOnly); return OpenDiskFile(pos, "rev", fReadOnly);
} }
boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
{
boost::filesystem::path path = GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile);
return path;
}
CBlockIndex * InsertBlockIndex(uint256 hash) CBlockIndex * InsertBlockIndex(uint256 hash)
{ {
if (hash == 0) if (hash == 0)

2
src/main.h

@ -145,6 +145,8 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false); FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
/** Open an undo file (rev?????.dat) */ /** Open an undo file (rev?????.dat) */
FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false); FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false);
/** Translation to a filesystem path */
boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
/** Import blocks from an external file */ /** Import blocks from an external file */
bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp = NULL); bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp = NULL);
/** Initialize a new block tree database + block data on disk */ /** Initialize a new block tree database + block data on disk */

Loading…
Cancel
Save