Skip to content

Commit

Permalink
filesystem: compat with std::experimental::filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
theuni committed Mar 2, 2017
1 parent 346de63 commit b208705
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/rpc/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static const std::string COOKIEAUTH_FILE = ".cookie";
fs::path GetAuthCookieFile()
{
fs::path path(GetArg("-rpccookiefile", COOKIEAUTH_FILE));
if (!path.is_complete()) path = GetDataDir() / path;
if (!path.is_absolute()) path = GetDataDir() / path;
return path;
}

Expand Down
7 changes: 4 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#endif // __linux__

#include <algorithm>
#include <fstream>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -546,15 +547,15 @@ void ClearDatadirCache()
fs::path GetConfigFile(const std::string& confPath)
{
fs::path pathConfigFile(confPath);
if (!pathConfigFile.is_complete())
if (!pathConfigFile.is_absolute())
pathConfigFile = GetDataDir(false) / pathConfigFile;

return pathConfigFile;
}

void ReadConfigFile(const std::string& confPath)
{
fs::ifstream streamConfig(GetConfigFile(confPath));
std::ifstream streamConfig(GetConfigFile(confPath));
if (!streamConfig.good())
return; // No bitcoin.conf file is OK

Expand Down Expand Up @@ -582,7 +583,7 @@ void ReadConfigFile(const std::string& confPath)
fs::path GetPidFile()
{
fs::path pathPidFile(GetArg("-pid", BITCOIN_PID_FILENAME));
if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile;
if (!pathPidFile.is_absolute()) pathPidFile = GetDataDir() / pathPidFile;
return pathPidFile;
}

Expand Down
10 changes: 8 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ bool CWallet::Verify()
uiInterface.InitMessage(_("Verifying wallet..."));

// Wallet file must be a plain filename without a directory
if (walletFile != fs::basename(walletFile) + fs::extension(walletFile))
if (fs::path(walletFile).has_parent_path())
return InitError(strprintf(_("Wallet %s resides outside data directory %s"), walletFile, GetDataDir().string()));

if (!bitdb.Open(GetDataDir()))
Expand Down Expand Up @@ -3899,7 +3899,13 @@ bool CWallet::BackupWallet(const std::string& strDest)
pathDest /= strWalletFile;

try {
fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
fs::file_status s = fs::symlink_status(pathDest);
if (fs::status_known(s)) {
if (fs::is_symlink(s))
pathDest = read_symlink(pathDest);
fs::remove(pathDest);
}
fs::copy_file(pathSrc, pathDest);
LogPrintf("copied %s to %s\n", strWalletFile, pathDest.string());
return true;
} catch (const fs::filesystem_error& e) {
Expand Down

0 comments on commit b208705

Please sign in to comment.