aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2014-09-08 13:29:14 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2014-09-10 13:51:53 -0400
commitec7eb0fa80ce50f0c45c7f764bf4958224721ca0 (patch)
treece421586d0340a7f10fae45f9f844b0f38301148 /src
parentdf623d83dad6aa39141b066ebd2f870ee05acf41 (diff)
When reindexing check for file before trying to open (refactored)
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp4
-rw-r--r--src/main.cpp8
-rw-r--r--src/main.h2
3 files changed, 12 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 31f64878fb..4b95f29365 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -401,9 +401,11 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
int nFile = 0;
while (true) {
CDiskBlockPos pos(nFile, 0);
+ if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk")))
+ break; // No block files left to reindex
FILE *file = OpenBlockFile(pos, true);
if (!file)
- break;
+ break; // This error is logged in OpenBlockFile
LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
LoadExternalBlockFile(file, &pos);
nFile++;
diff --git a/src/main.cpp b/src/main.cpp
index a3b31b719d..0816e36633 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2766,7 +2766,7 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
{
if (pos.IsNull())
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());
FILE* file = fopen(path.string().c_str(), "rb+");
if (!file && !fReadOnly)
@@ -2793,6 +2793,12 @@ FILE* OpenUndoFile(const CDiskBlockPos &pos, bool 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)
{
if (hash == 0)
diff --git a/src/main.h b/src/main.h
index 8c0a743e24..09de2187c4 100644
--- a/src/main.h
+++ b/src/main.h
@@ -145,6 +145,8 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
/** Open an undo file (rev?????.dat) */
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 */
bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp = NULL);
/** Initialize a new block tree database + block data on disk */