Skip to content

Commit

Permalink
[Refactor] Complete boost::filesystem namespace in util
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Apr 11, 2020
1 parent 81ddbf4 commit 15c0da4
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
strMiscWarning = message;
}

boost::filesystem::path GetDefaultDataDir()
fs::path GetDefaultDataDir()
{
// Windows < Vista: C:\Documents and Settings\Username\Application Data\PIVX
// Windows >= Vista: C:\Users\Username\AppData\Roaming\PIVX
Expand Down Expand Up @@ -349,30 +349,30 @@ const fs::path& GetDataDir(bool fNetSpecific)

void ClearDatadirCache()
{
pathCached = boost::filesystem::path();
pathCachedNetSpecific = boost::filesystem::path();
pathCached = fs::path();
pathCachedNetSpecific = fs::path();
}

boost::filesystem::path GetConfigFile()
fs::path GetConfigFile()
{
boost::filesystem::path pathConfigFile(GetArg("-conf", "pivx.conf"));
fs::path pathConfigFile(GetArg("-conf", "pivx.conf"));
if (!pathConfigFile.is_complete())
pathConfigFile = GetDataDir(false) / pathConfigFile;

return pathConfigFile;
}

boost::filesystem::path GetMasternodeConfigFile()
fs::path GetMasternodeConfigFile()
{
boost::filesystem::path pathConfigFile(GetArg("-mnconf", "masternode.conf"));
fs::path pathConfigFile(GetArg("-mnconf", "masternode.conf"));
if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile;
return pathConfigFile;
}

void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet)
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
fs::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good()) {
// Create empty pivx.conf if it does not exist
FILE* configFile = fopen(GetConfigFile().string().c_str(), "a");
Expand All @@ -398,14 +398,14 @@ void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
}

#ifndef WIN32
boost::filesystem::path GetPidFile()
fs::path GetPidFile()
{
boost::filesystem::path pathPidFile(GetArg("-pid", "pivxd.pid"));
fs::path pathPidFile(GetArg("-pid", "pivxd.pid"));
if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile;
return pathPidFile;
}

void CreatePidFile(const boost::filesystem::path& path, pid_t pid)
void CreatePidFile(const fs::path& path, pid_t pid)
{
FILE* file = fopen(path.string().c_str(), "w");
if (file) {
Expand All @@ -415,7 +415,7 @@ void CreatePidFile(const boost::filesystem::path& path, pid_t pid)
}
#endif

bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
bool RenameOver(fs::path src, fs::path dest)
{
#ifdef WIN32
return MoveFileExA(src.string().c_str(), dest.string().c_str(),
Expand All @@ -431,12 +431,12 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
* Specifically handles case where path p exists, but it wasn't possible for the user to
* write to the parent directory.
*/
bool TryCreateDirectory(const boost::filesystem::path& p)
bool TryCreateDirectory(const fs::path& p)
{
try {
return boost::filesystem::create_directory(p);
} catch (const boost::filesystem::filesystem_error&) {
if (!boost::filesystem::exists(p) || !boost::filesystem::is_directory(p))
return fs::create_directory(p);
} catch (const fs::filesystem_error&) {
if (!fs::exists(p) || !fs::is_directory(p))
throw;
}

Expand Down Expand Up @@ -542,7 +542,7 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
}

#ifdef WIN32
boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate)
fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
{
char pszPath[MAX_PATH] = "";

Expand All @@ -555,24 +555,24 @@ boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate)
}
#endif

boost::filesystem::path GetTempPath()
fs::path GetTempPath()
{
#if BOOST_FILESYSTEM_VERSION == 3
return boost::filesystem::temp_directory_path();
return fs::temp_directory_path();
#else
// TODO: remove when we don't support filesystem v2 anymore
boost::filesystem::path path;
fs::path path;
#ifdef WIN32
char pszPath[MAX_PATH] = "";

if (GetTempPathA(MAX_PATH, pszPath))
path = boost::filesystem::path(pszPath);
path = fs::path(pszPath);
#else
path = boost::filesystem::path("/tmp");
path = fs::path("/tmp");
#endif
if (path.empty() || !boost::filesystem::is_directory(path)) {
if (path.empty() || !fs::is_directory(path)) {
LogPrintf("GetTempPath(): failed to find temp path\n");
return boost::filesystem::path("");
return fs::path("");
}
return path;
#endif
Expand Down Expand Up @@ -620,8 +620,8 @@ void SetupEnvironment()
// in multithreading environments, it is set explicitly by the main thread.
// A dummy locale is used to extract the internal default locale, used by
// boost::filesystem::path, which is then used to explicitly imbue the path.
std::locale loc = boost::filesystem::path::imbue(std::locale::classic());
boost::filesystem::path::imbue(loc);
std::locale loc = fs::path::imbue(std::locale::classic());
fs::path::imbue(loc);
}

bool SetupNetworking()
Expand Down

0 comments on commit 15c0da4

Please sign in to comment.