Skip to content

Commit 1d1ea9f

Browse files
author
Marko Bencun
committed
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.
1 parent a4ca0b0 commit 1d1ea9f

File tree

6 files changed

+8
-10
lines changed

6 files changed

+8
-10
lines changed

src/dbwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bo
108108
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
109109
dbwrapper_private::HandleError(result);
110110
}
111-
TryCreateDirectory(path);
111+
TryCreateDirectories(path);
112112
LogPrintf("Opening LevelDB in %s\n", path.string());
113113
}
114114
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);

src/init.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14101410
fReindex = GetBoolArg("-reindex", false);
14111411
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false);
14121412

1413-
fs::create_directories(GetDataDir() / "blocks");
1414-
14151413
// cache size calculations
14161414
int64_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
14171415
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache

src/qt/intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ bool Intro::pickDataDirectory()
214214
}
215215
dataDir = intro.getDataDirectory();
216216
try {
217-
TryCreateDirectory(GUIUtil::qstringToBoostPath(dataDir));
217+
TryCreateDirectories(GUIUtil::qstringToBoostPath(dataDir));
218218
break;
219219
} catch (const fs::filesystem_error&) {
220220
QMessageBox::critical(0, tr(PACKAGE_NAME),

src/util.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,21 +653,21 @@ bool RenameOver(fs::path src, fs::path dest)
653653
}
654654

655655
/**
656-
* Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
656+
* Ignores exceptions thrown by Boost's create_directories if the requested directory exists.
657657
* Specifically handles case where path p exists, but it wasn't possible for the user to
658658
* write to the parent directory.
659659
*/
660-
bool TryCreateDirectory(const fs::path& p)
660+
bool TryCreateDirectories(const fs::path& p)
661661
{
662662
try
663663
{
664-
return fs::create_directory(p);
664+
return fs::create_directories(p);
665665
} catch (const fs::filesystem_error&) {
666666
if (!fs::exists(p) || !fs::is_directory(p))
667667
throw;
668668
}
669669

670-
// create_directory didn't create the directory, it had to have existed already
670+
// create_directories didn't create the directory, it had to have existed already
671671
return false;
672672
}
673673

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bool TruncateFile(FILE *file, unsigned int length);
153153
int RaiseFileDescriptorLimit(int nMinFD);
154154
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
155155
bool RenameOver(fs::path src, fs::path dest);
156-
bool TryCreateDirectory(const fs::path& p);
156+
bool TryCreateDirectories(const fs::path& p);
157157
fs::path GetDefaultDataDir();
158158
const fs::path &GetDataDir(bool fNetSpecific = true);
159159
void ClearDatadirCache();

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool CDBEnv::Open(const fs::path& pathIn)
7575

7676
strPath = pathIn.string();
7777
fs::path pathLogDir = pathIn / "database";
78-
TryCreateDirectory(pathLogDir);
78+
TryCreateDirectories(pathLogDir);
7979
fs::path pathErrorFile = pathIn / "db.log";
8080
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
8181

0 commit comments

Comments
 (0)