Turn TryCreateDirectory() into TryCreateDirectories()
Use case: TryCreateDirectory(GetDataDir() / "blocks" / "index") would fail if the blocks directory was not explicitly created before. The line that did so was in a weird location and could be removed as a result.
This commit is contained in:
parent
a4ca0b0423
commit
1d1ea9f096
6 changed files with 8 additions and 10 deletions
|
@ -108,7 +108,7 @@ CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bo
|
||||||
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
||||||
dbwrapper_private::HandleError(result);
|
dbwrapper_private::HandleError(result);
|
||||||
}
|
}
|
||||||
TryCreateDirectory(path);
|
TryCreateDirectories(path);
|
||||||
LogPrintf("Opening LevelDB in %s\n", path.string());
|
LogPrintf("Opening LevelDB in %s\n", path.string());
|
||||||
}
|
}
|
||||||
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
||||||
|
|
|
@ -1410,8 +1410,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||||
fReindex = GetBoolArg("-reindex", false);
|
fReindex = GetBoolArg("-reindex", false);
|
||||||
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false);
|
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false);
|
||||||
|
|
||||||
fs::create_directories(GetDataDir() / "blocks");
|
|
||||||
|
|
||||||
// cache size calculations
|
// cache size calculations
|
||||||
int64_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
|
int64_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
|
||||||
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
|
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
|
||||||
|
|
|
@ -214,7 +214,7 @@ bool Intro::pickDataDirectory()
|
||||||
}
|
}
|
||||||
dataDir = intro.getDataDirectory();
|
dataDir = intro.getDataDirectory();
|
||||||
try {
|
try {
|
||||||
TryCreateDirectory(GUIUtil::qstringToBoostPath(dataDir));
|
TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir));
|
||||||
break;
|
break;
|
||||||
} catch (const fs::filesystem_error&) {
|
} catch (const fs::filesystem_error&) {
|
||||||
QMessageBox::critical(0, tr(PACKAGE_NAME),
|
QMessageBox::critical(0, tr(PACKAGE_NAME),
|
||||||
|
|
|
@ -653,21 +653,21 @@ bool RenameOver(fs::path src, fs::path dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
|
* Ignores exceptions thrown by Boost's create_directories if the requested directory exists.
|
||||||
* Specifically handles case where path p exists, but it wasn't possible for the user to
|
* Specifically handles case where path p exists, but it wasn't possible for the user to
|
||||||
* write to the parent directory.
|
* write to the parent directory.
|
||||||
*/
|
*/
|
||||||
bool TryCreateDirectory(const fs::path& p)
|
bool TryCreateDirectories(const fs::path& p)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return fs::create_directory(p);
|
return fs::create_directories(p);
|
||||||
} catch (const fs::filesystem_error&) {
|
} catch (const fs::filesystem_error&) {
|
||||||
if (!fs::exists(p) || !fs::is_directory(p))
|
if (!fs::exists(p) || !fs::is_directory(p))
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_directory didn't create the directory, it had to have existed already
|
// create_directories didn't create the directory, it had to have existed already
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ bool TruncateFile(FILE *file, unsigned int length);
|
||||||
int RaiseFileDescriptorLimit(int nMinFD);
|
int RaiseFileDescriptorLimit(int nMinFD);
|
||||||
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
|
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
|
||||||
bool RenameOver(fs::path src, fs::path dest);
|
bool RenameOver(fs::path src, fs::path dest);
|
||||||
bool TryCreateDirectory(const fs::path& p);
|
bool TryCreateDirectories(const fs::path& p);
|
||||||
fs::path GetDefaultDataDir();
|
fs::path GetDefaultDataDir();
|
||||||
const fs::path &GetDataDir(bool fNetSpecific = true);
|
const fs::path &GetDataDir(bool fNetSpecific = true);
|
||||||
void ClearDatadirCache();
|
void ClearDatadirCache();
|
||||||
|
|
|
@ -75,7 +75,7 @@ bool CDBEnv::Open(const fs::path& pathIn)
|
||||||
|
|
||||||
strPath = pathIn.string();
|
strPath = pathIn.string();
|
||||||
fs::path pathLogDir = pathIn / "database";
|
fs::path pathLogDir = pathIn / "database";
|
||||||
TryCreateDirectory(pathLogDir);
|
TryCreateDirectories(pathLogDir);
|
||||||
fs::path pathErrorFile = pathIn / "db.log";
|
fs::path pathErrorFile = pathIn / "db.log";
|
||||||
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
|
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue