diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,7 @@ compat/glibc_sanity.cpp compat/glibcxx_sanity.cpp compat/strnlen.cpp + fs.cpp random.cpp rpc/protocol.cpp support/cleanse.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -112,6 +112,7 @@ core_memusage.h \ cuckoocache.h \ dstencode.h \ + fs.h \ globals.h \ httprpc.h \ httpserver.h \ @@ -357,6 +358,7 @@ compat/glibc_sanity.cpp \ compat/glibcxx_sanity.cpp \ compat/strnlen.cpp \ + fs.cpp \ random.cpp \ rpc/protocol.cpp \ support/cleanse.cpp \ diff --git a/src/addrdb.h b/src/addrdb.h --- a/src/addrdb.h +++ b/src/addrdb.h @@ -6,9 +6,9 @@ #ifndef BITCOIN_ADDRDB_H #define BITCOIN_ADDRDB_H +#include "fs.h" #include "serialize.h" -#include #include #include @@ -71,7 +71,7 @@ /** Access to the (IP) address database (peers.dat) */ class CAddrDB { private: - boost::filesystem::path pathAddr; + fs::path pathAddr; public: CAddrDB(); @@ -83,7 +83,7 @@ /** Access to the banlist database (banlist.dat) */ class CBanDB { private: - boost::filesystem::path pathBanlist; + fs::path pathBanlist; public: CBanDB(); diff --git a/src/addrdb.cpp b/src/addrdb.cpp --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -8,14 +8,13 @@ #include "addrman.h" #include "chainparams.h" #include "clientversion.h" +#include "fs.h" #include "hash.h" #include "random.h" #include "streams.h" #include "tinyformat.h" #include "util.h" -#include - CBanDB::CBanDB() { pathBanlist = GetDataDir() / "banlist.dat"; } @@ -34,8 +33,8 @@ ssBanlist << hash; // open temp output file, and associate with CAutoFile - boost::filesystem::path pathTmp = GetDataDir() / tmpfn; - FILE *file = fopen(pathTmp.string().c_str(), "wb"); + fs::path pathTmp = GetDataDir() / tmpfn; + FILE *file = fsbridge::fopen(pathTmp, "wb"); CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); if (fileout.IsNull()) return error("%s: Failed to open file %s", __func__, pathTmp.string()); @@ -58,14 +57,14 @@ bool CBanDB::Read(banmap_t &banSet) { // open input file, and associate with CAutoFile - FILE *file = fopen(pathBanlist.string().c_str(), "rb"); + FILE *file = fsbridge::fopen(pathBanlist, "rb"); CAutoFile filein(file, SER_DISK, CLIENT_VERSION); if (filein.IsNull()) return error("%s: Failed to open file %s", __func__, pathBanlist.string()); // use file size to size memory buffer - uint64_t fileSize = boost::filesystem::file_size(pathBanlist); + uint64_t fileSize = fs::file_size(pathBanlist); uint64_t dataSize = 0; // Don't try to resize to a negative number if file is small if (fileSize >= sizeof(uint256)) dataSize = fileSize - sizeof(uint256); @@ -127,8 +126,8 @@ ssPeers << hash; // open temp output file, and associate with CAutoFile - boost::filesystem::path pathTmp = GetDataDir() / tmpfn; - FILE *file = fopen(pathTmp.string().c_str(), "wb"); + fs::path pathTmp = GetDataDir() / tmpfn; + FILE *file = fsbridge::fopen(pathTmp, "wb"); CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); if (fileout.IsNull()) return error("%s: Failed to open file %s", __func__, pathTmp.string()); @@ -151,13 +150,13 @@ bool CAddrDB::Read(CAddrMan &addr) { // open input file, and associate with CAutoFile - FILE *file = fopen(pathAddr.string().c_str(), "rb"); + FILE *file = fsbridge::fopen(pathAddr, "rb"); CAutoFile filein(file, SER_DISK, CLIENT_VERSION); if (filein.IsNull()) return error("%s: Failed to open file %s", __func__, pathAddr.string()); // use file size to size memory buffer - uint64_t fileSize = boost::filesystem::file_size(pathAddr); + uint64_t fileSize = fs::file_size(pathAddr); uint64_t dataSize = 0; // Don't try to resize to a negative number if file is small if (fileSize >= sizeof(uint256)) dataSize = fileSize - sizeof(uint256); diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -120,7 +120,7 @@ } return EXIT_SUCCESS; } - if (!boost::filesystem::is_directory(GetDataDir(false))) { + if (!fs::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str()); diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -11,6 +11,7 @@ #include "clientversion.h" #include "compat.h" #include "config.h" +#include "fs.h" #include "httprpc.h" #include "httpserver.h" #include "init.h" @@ -21,7 +22,6 @@ #include "utilstrencodings.h" #include -#include #include #include @@ -103,7 +103,7 @@ } try { - if (!boost::filesystem::is_directory(GetDataDir(false))) { + if (!fs::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str()); diff --git a/src/dbwrapper.h b/src/dbwrapper.h --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -6,14 +6,13 @@ #define BITCOIN_DBWRAPPER_H #include "clientversion.h" +#include "fs.h" #include "serialize.h" #include "streams.h" #include "util.h" #include "utilstrencodings.h" #include "version.h" -#include - #include #include @@ -220,9 +219,8 @@ * false, XOR * with a zero'd byte array. */ - CDBWrapper(const boost::filesystem::path &path, size_t nCacheSize, - bool fMemory = false, bool fWipe = false, - bool obfuscate = false); + CDBWrapper(const fs::path &path, size_t nCacheSize, bool fMemory = false, + bool fWipe = false, bool obfuscate = false); ~CDBWrapper(); template bool Read(const K &key, V &value) const { diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -32,8 +32,8 @@ return options; } -CDBWrapper::CDBWrapper(const boost::filesystem::path &path, size_t nCacheSize, - bool fMemory, bool fWipe, bool obfuscate) { +CDBWrapper::CDBWrapper(const fs::path &path, size_t nCacheSize, bool fMemory, + bool fWipe, bool obfuscate) { penv = nullptr; readoptions.verify_checksums = true; iteroptions.verify_checksums = true; diff --git a/src/fs.h b/src/fs.h new file mode 100644 --- /dev/null +++ b/src/fs.h @@ -0,0 +1,24 @@ +// Copyright (c) 2017 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_FS_H +#define BITCOIN_FS_H + +#include +#include + +#include +#include +#include + +/** Filesystem operations and types */ +namespace fs = boost::filesystem; + +/** Bridge operations to C stdio */ +namespace fsbridge { +FILE *fopen(const fs::path &p, const char *mode); +FILE *freopen(const fs::path &p, const char *mode, FILE *stream); +}; + +#endif diff --git a/src/fs.cpp b/src/fs.cpp new file mode 100644 --- /dev/null +++ b/src/fs.cpp @@ -0,0 +1,15 @@ +#include "fs.h" + +#include + +namespace fsbridge { + +FILE *fopen(const fs::path &p, const char *mode) { + return ::fopen(p.string().c_str(), mode); +} + +FILE *freopen(const fs::path &p, const char *mode, FILE *stream) { + return ::freopen(p.string().c_str(), mode, stream); +} + +} // fsbridge diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -17,6 +17,7 @@ #include "compat/sanity.h" #include "config.h" #include "consensus/validation.h" +#include "fs.h" #include "httprpc.h" #include "httpserver.h" #include "key.h" @@ -59,7 +60,6 @@ #include #include #include -#include #include #include @@ -206,9 +206,8 @@ if (fDumpMempoolLater) DumpMempool(); if (fFeeEstimatesInitialized) { - boost::filesystem::path est_path = - GetDataDir() / FEE_ESTIMATES_FILENAME; - CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, + fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; + CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION); if (!est_fileout.IsNull()) mempool.WriteFeeEstimates(est_fileout); @@ -246,8 +245,8 @@ #ifndef WIN32 try { - boost::filesystem::remove(GetPidFile()); - } catch (const boost::filesystem::filesystem_error &e) { + fs::remove(GetPidFile()); + } catch (const fs::filesystem_error &e) { LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); } #endif @@ -935,16 +934,16 @@ // with what's actually on disk by the time we start downloading, so that // pruning works correctly. void CleanupBlockRevFiles() { - std::map mapBlockFiles; + std::map mapBlockFiles; // Glob all blk?????.dat and rev?????.dat files from the blocks directory. // Remove the rev files immediately and insert the blk file paths into an // ordered map keyed by block file index. LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for " "-reindex with -prune\n"); - boost::filesystem::path blocksdir = GetDataDir() / "blocks"; - for (boost::filesystem::directory_iterator it(blocksdir); - it != boost::filesystem::directory_iterator(); it++) { + fs::path blocksdir = GetDataDir() / "blocks"; + for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); + it++) { if (is_regular_file(*it) && it->path().filename().string().length() == 12 && it->path().filename().string().substr(8, 4) == ".dat") { @@ -961,8 +960,7 @@ // a separate counter. Once we hit a gap (or if 0 doesn't exist) start // removing block files. int nContigCounter = 0; - for (const std::pair &item : - mapBlockFiles) { + for (const std::pair &item : mapBlockFiles) { if (atoi(item.first) == nContigCounter) { nContigCounter++; continue; @@ -971,8 +969,7 @@ } } -void ThreadImport(const Config &config, - std::vector vImportFiles) { +void ThreadImport(const Config &config, std::vector vImportFiles) { RenameThread("bitcoin-loadblk"); { @@ -983,7 +980,7 @@ int nFile = 0; while (true) { CDiskBlockPos pos(nFile, 0); - if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk"))) + if (!fs::exists(GetBlockPosFilename(pos, "blk"))) break; // No block files left to reindex FILE *file = OpenBlockFile(pos, true); if (!file) break; // This error is logged in OpenBlockFile @@ -1001,12 +998,11 @@ } // hardcoded $DATADIR/bootstrap.dat - boost::filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; - if (boost::filesystem::exists(pathBootstrap)) { - FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); + fs::path pathBootstrap = GetDataDir() / "bootstrap.dat"; + if (fs::exists(pathBootstrap)) { + FILE *file = fsbridge::fopen(pathBootstrap, "rb"); if (file) { - boost::filesystem::path pathBootstrapOld = - GetDataDir() / "bootstrap.dat.old"; + fs::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; LogPrintf("Importing bootstrap.dat...\n"); LoadExternalBlockFile(config, file); RenameOver(pathBootstrap, pathBootstrapOld); @@ -1017,8 +1013,8 @@ } // -loadblock= - for (const boost::filesystem::path &path : vImportFiles) { - FILE *file = fopen(path.string().c_str(), "rb"); + for (const fs::path &path : vImportFiles) { + FILE *file = fsbridge::fopen(path, "rb"); if (file) { LogPrintf("Importing blocks file %s...\n", path.string()); LoadExternalBlockFile(config, file); @@ -1584,9 +1580,9 @@ std::string strDataDir = GetDataDir().string(); // Make sure only a single Bitcoin process is using the data directory. - boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; + fs::path pathLockFile = GetDataDir() / ".lock"; // empty lock file; created if it doesn't exist. - FILE *file = fopen(pathLockFile.string().c_str(), "a"); + FILE *file = fsbridge::fopen(pathLockFile, "a"); if (file) fclose(file); try { @@ -1880,26 +1876,24 @@ bool fReindexChainState = GetBoolArg("-reindex-chainstate", false); // Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/ - boost::filesystem::path blocksDir = GetDataDir() / "blocks"; - if (!boost::filesystem::exists(blocksDir)) { - boost::filesystem::create_directories(blocksDir); + fs::path blocksDir = GetDataDir() / "blocks"; + if (!fs::exists(blocksDir)) { + fs::create_directories(blocksDir); bool linked = false; for (unsigned int i = 1; i < 10000; i++) { - boost::filesystem::path source = - GetDataDir() / strprintf("blk%04u.dat", i); + fs::path source = GetDataDir() / strprintf("blk%04u.dat", i); - if (!boost::filesystem::exists(source)) { + if (!fs::exists(source)) { break; } - boost::filesystem::path dest = - blocksDir / strprintf("blk%05u.dat", i - 1); + fs::path dest = blocksDir / strprintf("blk%05u.dat", i - 1); try { - boost::filesystem::create_hard_link(source, dest); + fs::create_hard_link(source, dest); LogPrintf("Hardlinked %s -> %s\n", source.string(), dest.string()); linked = true; - } catch (const boost::filesystem::filesystem_error &e) { + } catch (const fs::filesystem_error &e) { // Note: hardlink creation failing is not a disaster, it just // means blocks will get re-downloaded from peers. LogPrintf("Error hardlinking blk%04u.dat: %s\n", i, e.what()); @@ -2105,8 +2099,8 @@ } LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart); - boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; - CAutoFile est_filein(fopen(est_path.string().c_str(), "rb"), SER_DISK, + fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; + CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, CLIENT_VERSION); // Allowed to fail as this file IS missing on first startup. if (!est_filein.IsNull()) mempool.ReadFeeEstimates(est_filein); @@ -2155,7 +2149,7 @@ if (IsArgSet("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); - std::vector vImportFiles; + std::vector vImportFiles; if (mapMultiArgs.count("-loadblock")) { for (const std::string &strFile : mapMultiArgs.at("-loadblock")) { vImportFiles.push_back(strFile); diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -13,6 +13,7 @@ #include "bloom.h" #include "chainparams.h" #include "compat.h" +#include "fs.h" #include "hash.h" #include "limitedmap.h" #include "netaddress.h" @@ -34,7 +35,6 @@ #include #endif -#include #include class CAddrMan; diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -675,7 +675,7 @@ /// 6. Determine availability of data directory and parse bitcoin.conf /// - Do not call GetDataDir(true) before this step finishes. - if (!boost::filesystem::is_directory(GetDataDir(false))) { + if (!fs::is_directory(GetDataDir(false))) { QMessageBox::critical( 0, QObject::tr(PACKAGE_NAME), QObject::tr( diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -6,6 +6,7 @@ #define BITCOIN_QT_GUIUTIL_H #include "amount.h" +#include "fs.h" #include #include @@ -16,8 +17,6 @@ #include #include -#include - class QValidatedLineEdit; class SendCoinsRecipient; class CChainParams; @@ -211,10 +210,10 @@ const QSize &defaultSizeIn, QWidget *parent); /* Convert QString to OS specific boost path through UTF-8 */ -boost::filesystem::path qstringToBoostPath(const QString &path); +fs::path qstringToBoostPath(const QString &path); /* Convert OS specific boost path to QString through UTF-8 */ -QString boostPathToQString(const boost::filesystem::path &path); +QString boostPathToQString(const fs::path &path); /* Convert seconds into a QString with days, hours, mins, secs */ QString formatDurationStr(int secs); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -13,6 +13,7 @@ #include "cashaddr.h" #include "config.h" #include "dstencode.h" +#include "fs.h" #include "init.h" #include "policy/policy.h" #include "primitives/transaction.h" @@ -40,7 +41,6 @@ #include "shlwapi.h" #endif -#include #include #if BOOST_FILESYSTEM_VERSION >= 3 #include @@ -73,7 +73,7 @@ #endif #if BOOST_FILESYSTEM_VERSION >= 3 -static boost::filesystem::detail::utf8_codecvt_facet utf8; +static fs::detail::utf8_codecvt_facet utf8; #endif #if defined(Q_OS_MAC) @@ -429,10 +429,10 @@ } void openDebugLogfile() { - boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; + fs::path pathDebug = GetDataDir() / "debug.log"; /* Open debug.log with the associated application */ - if (boost::filesystem::exists(pathDebug)) + if (fs::exists(pathDebug)) QDesktopServices::openUrl( QUrl::fromLocalFile(boostPathToQString(pathDebug))); } @@ -620,7 +620,7 @@ } #ifdef WIN32 -static boost::filesystem::path StartupShortcutPath() { +static fs::path StartupShortcutPath() { std::string chain = ChainNameFromCommandLine(); if (chain == CBaseChainParams::MAIN) return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk"; @@ -633,12 +633,12 @@ bool GetStartOnSystemStartup() { // check for Bitcoin*.lnk - return boost::filesystem::exists(StartupShortcutPath()); + return fs::exists(StartupShortcutPath()); } bool SetStartOnSystemStartup(bool fAutoStart) { // If the shortcut exists already, remove it for updating - boost::filesystem::remove(StartupShortcutPath()); + fs::remove(StartupShortcutPath()); if (fAutoStart) { CoInitialize(nullptr); @@ -710,9 +710,7 @@ // Follow the Desktop Application Autostart Spec: // http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html -static boost::filesystem::path GetAutostartDir() { - namespace fs = boost::filesystem; - +static fs::path GetAutostartDir() { char *pszConfigHome = getenv("XDG_CONFIG_HOME"); if (pszConfigHome) return fs::path(pszConfigHome) / "autostart"; char *pszHome = getenv("HOME"); @@ -720,7 +718,7 @@ return fs::path(); } -static boost::filesystem::path GetAutostartFilePath() { +static fs::path GetAutostartFilePath() { std::string chain = ChainNameFromCommandLine(); if (chain == CBaseChainParams::MAIN) return GetAutostartDir() / "bitcoin.desktop"; @@ -728,7 +726,7 @@ } bool GetStartOnSystemStartup() { - boost::filesystem::ifstream optionFile(GetAutostartFilePath()); + fs::ifstream optionFile(GetAutostartFilePath()); if (!optionFile.good()) return false; // Scan through file for "Hidden=true": std::string line; @@ -745,7 +743,7 @@ bool SetStartOnSystemStartup(bool fAutoStart) { if (!fAutoStart) - boost::filesystem::remove(GetAutostartFilePath()); + fs::remove(GetAutostartFilePath()); else { char pszExePath[MAX_PATH + 1]; memset(pszExePath, 0, sizeof(pszExePath)); @@ -753,10 +751,10 @@ -1) return false; - boost::filesystem::create_directories(GetAutostartDir()); + fs::create_directories(GetAutostartDir()); - boost::filesystem::ofstream optionFile( - GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc); + fs::ofstream optionFile(GetAutostartFilePath(), + std::ios_base::out | std::ios_base::trunc); if (!optionFile.good()) return false; std::string chain = ChainNameFromCommandLine(); // Write a bitcoin.desktop file to the autostart directory: @@ -905,20 +903,20 @@ } #if BOOST_FILESYSTEM_VERSION >= 3 -boost::filesystem::path qstringToBoostPath(const QString &path) { - return boost::filesystem::path(path.toStdString(), utf8); +fs::path qstringToBoostPath(const QString &path) { + return fs::path(path.toStdString(), utf8); } -QString boostPathToQString(const boost::filesystem::path &path) { +QString boostPathToQString(const fs::path &path) { return QString::fromStdString(path.string(utf8)); } #else #warning Conversion between boost path and QString can use invalid character encoding with boost_filesystem v2 and older -boost::filesystem::path qstringToBoostPath(const QString &path) { - return boost::filesystem::path(path.toStdString()); +fs::path qstringToBoostPath(const QString &path) { + return fs::path(path.toStdString()); } -QString boostPathToQString(const boost::filesystem::path &path) { +QString boostPathToQString(const fs::path &path) { return QString::fromStdString(path.string()); } #endif diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -6,15 +6,12 @@ #include "config/bitcoin-config.h" #endif +#include "fs.h" +#include "guiutil.h" #include "intro.h" #include "ui_intro.h" - -#include "guiutil.h" - #include "util.h" -#include - #include #include #include @@ -68,7 +65,6 @@ } void FreespaceChecker::check() { - namespace fs = boost::filesystem; QString dataDirStr = intro->getPathToCheck(); fs::path dataDir = GUIUtil::qstringToBoostPath(dataDirStr); uint64_t freeBytesAvailable = 0; @@ -160,7 +156,6 @@ } bool Intro::pickDataDirectory() { - namespace fs = boost::filesystem; QSettings settings; /* If data directory provided on command line, no need to look at settings or show a picking dialog */ diff --git a/src/qt/test/rpcnestedtests.cpp b/src/qt/test/rpcnestedtests.cpp --- a/src/qt/test/rpcnestedtests.cpp +++ b/src/qt/test/rpcnestedtests.cpp @@ -8,6 +8,7 @@ #include "config.h" #include "config.h" #include "consensus/validation.h" +#include "fs.h" #include "rpc/register.h" #include "rpc/server.h" #include "rpcconsole.h" @@ -19,8 +20,6 @@ #include #include -#include - static UniValue rpcNestedTest_rpc(const Config &config, const JSONRPCRequest &request) { if (request.fHelp) { @@ -215,5 +214,5 @@ delete pcoinsdbview; delete pblocktree; - boost::filesystem::remove_all(boost::filesystem::path(path)); + fs::remove_all(fs::path(path)); } diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -6,7 +6,8 @@ #ifndef BITCOIN_RPCPROTOCOL_H #define BITCOIN_RPCPROTOCOL_H -#include +#include "fs.h" + #include #include #include @@ -119,7 +120,7 @@ UniValue JSONRPCError(int code, const std::string &message); /** Get name of RPC authentication cookie file */ -boost::filesystem::path GetAuthCookieFile(); +fs::path GetAuthCookieFile(); /** Generate a new RPC authentication cookie and write it to disk */ bool GenerateAuthCookie(std::string *cookie_out); /** Read the RPC authentication cookie from disk */ diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -65,8 +65,8 @@ /** Default name for auth cookie file */ static const std::string COOKIEAUTH_FILE = ".cookie"; -boost::filesystem::path GetAuthCookieFile() { - boost::filesystem::path path(GetArg("-rpccookiefile", COOKIEAUTH_FILE)); +fs::path GetAuthCookieFile() { + fs::path path(GetArg("-rpccookiefile", COOKIEAUTH_FILE)); if (!path.is_complete()) path = GetDataDir() / path; return path; } @@ -82,7 +82,7 @@ * these are set to 077 in init.cpp unless overridden with -sysperms. */ std::ofstream file; - boost::filesystem::path filepath = GetAuthCookieFile(); + fs::path filepath = GetAuthCookieFile(); file.open(filepath.string().c_str()); if (!file.is_open()) { LogPrintf("Unable to open cookie authentication file %s for writing\n", @@ -100,7 +100,7 @@ bool GetAuthCookie(std::string *cookie_out) { std::ifstream file; std::string cookie; - boost::filesystem::path filepath = GetAuthCookieFile(); + fs::path filepath = GetAuthCookieFile(); file.open(filepath.string().c_str()); if (!file.is_open()) return false; std::getline(file, cookie); @@ -112,8 +112,8 @@ void DeleteAuthCookie() { try { - boost::filesystem::remove(GetAuthCookieFile()); - } catch (const boost::filesystem::filesystem_error &e) { + fs::remove(GetAuthCookieFile()); + } catch (const fs::filesystem_error &e) { LogPrintf("%s: Unable to remove random auth cookie file: %s\n", __func__, e.what()); } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -7,6 +7,7 @@ #include "base58.h" #include "config.h" +#include "fs.h" #include "init.h" #include "random.h" #include "sync.h" @@ -18,7 +19,6 @@ #include // for to_upper() #include -#include #include #include diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -27,8 +27,7 @@ // Perform tests both obfuscated and non-obfuscated. for (int i = 0; i < 2; i++) { bool obfuscate = (bool)i; - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + fs::path ph = fs::temp_directory_path() / fs::unique_path(); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); char key = 'k'; uint256 in = InsecureRand256(); @@ -49,8 +48,7 @@ // Perform tests both obfuscated and non-obfuscated. for (int i = 0; i < 2; i++) { bool obfuscate = (bool)i; - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + fs::path ph = fs::temp_directory_path() / fs::unique_path(); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); char key = 'i'; @@ -86,8 +84,7 @@ // Perform tests both obfuscated and non-obfuscated. for (int i = 0; i < 2; i++) { bool obfuscate = (bool)i; - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + fs::path ph = fs::temp_directory_path() / fs::unique_path(); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); // The two keys are intentionally chosen for ordering @@ -126,9 +123,8 @@ // Test that we do not obfuscation if there is existing data. BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) { - // We're going to share this boost::filesystem::path between two wrappers - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + // We're going to share this fs::path between two wrappers + fs::path ph = fs::temp_directory_path() / fs::unique_path(); create_directories(ph); // Set up a non-obfuscated wrapper to write some initial data. @@ -169,9 +165,8 @@ // Ensure that we start obfuscating during a reindex. BOOST_AUTO_TEST_CASE(existing_data_reindex) { - // We're going to share this boost::filesystem::path between two wrappers - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + // We're going to share this fs::path between two wrappers + fs::path ph = fs::temp_directory_path() / fs::unique_path(); create_directories(ph); // Set up a non-obfuscated wrapper to write some initial data. @@ -205,8 +200,7 @@ } BOOST_AUTO_TEST_CASE(iterator_ordering) { - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + fs::path ph = fs::temp_directory_path() / fs::unique_path(); CDBWrapper dbw(ph, (1 << 20), true, false, false); for (int x = 0x00; x < 256; ++x) { uint8_t key = x; @@ -280,8 +274,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering) { char buf[10]; - boost::filesystem::path ph = boost::filesystem::temp_directory_path() / - boost::filesystem::unique_path(); + fs::path ph = fs::temp_directory_path() / fs::unique_path(); CDBWrapper dbw(ph, (1 << 20), true, false, false); for (int x = 0x00; x < 10; ++x) { for (int y = 0; y < 10; y++) { diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -6,13 +6,13 @@ #define BITCOIN_TEST_TEST_BITCOIN_H #include "chainparamsbase.h" +#include "fs.h" #include "key.h" #include "pubkey.h" #include "random.h" #include "txdb.h" #include "txmempool.h" -#include #include extern uint256 insecure_rand_seed; @@ -63,7 +63,7 @@ class CConnman; struct TestingSetup : public BasicTestingSetup { CCoinsViewDB *pcoinsdbview; - boost::filesystem::path pathTemp; + fs::path pathTemp; boost::thread_group threadGroup; CConnman *connman; diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -10,6 +10,7 @@ #include "config.h" #include "consensus/consensus.h" #include "consensus/validation.h" +#include "fs.h" #include "key.h" #include "miner.h" #include "net_processing.h" @@ -26,7 +27,6 @@ #include "test/testutil.h" -#include #include #include @@ -80,7 +80,7 @@ pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(100000))); - boost::filesystem::create_directories(pathTemp); + fs::create_directories(pathTemp); ForceSetArg("-datadir", pathTemp.string()); mempool.setSanityCheck(1.0); pblocktree = new CBlockTreeDB(1 << 20, true); @@ -111,7 +111,7 @@ delete pcoinsTip; delete pcoinsdbview; delete pblocktree; - boost::filesystem::remove_all(pathTemp); + fs::remove_all(pathTemp); } TestChain100Setup::TestChain100Setup() diff --git a/src/test/testutil.h b/src/test/testutil.h --- a/src/test/testutil.h +++ b/src/test/testutil.h @@ -8,8 +8,8 @@ #ifndef BITCOIN_TEST_TESTUTIL_H #define BITCOIN_TEST_TESTUTIL_H -#include +#include "fs.h" -boost::filesystem::path GetTempPath(); +fs::path GetTempPath(); #endif // BITCOIN_TEST_TESTUTIL_H diff --git a/src/test/testutil.cpp b/src/test/testutil.cpp --- a/src/test/testutil.cpp +++ b/src/test/testutil.cpp @@ -3,31 +3,30 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "testutil.h" +#include "fs.h" #ifdef WIN32 #include #endif -#include - -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 diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -35,7 +35,7 @@ buffer size for CBufferedFile set to 2 * MAX_TX_SIZE. Test with a value of 10 * MAX_TX_SIZE. */ BOOST_AUTO_TEST_CASE(validation_load_external_block_file) { - boost::filesystem::path tmpfile_name = + fs::path tmpfile_name = pathTemp / strprintf("vlebf_test_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(100000))); diff --git a/src/util.h b/src/util.h --- a/src/util.h +++ b/src/util.h @@ -15,6 +15,7 @@ #endif #include "compat.h" +#include "fs.h" #include "tinyformat.h" #include "utiltime.h" @@ -25,7 +26,6 @@ #include #include -#include #include #include @@ -95,19 +95,19 @@ bool TruncateFile(FILE *file, unsigned int length); int RaiseFileDescriptorLimit(int nMinFD); void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length); -bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest); -bool TryCreateDirectory(const boost::filesystem::path &p); -boost::filesystem::path GetDefaultDataDir(); -const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); +bool RenameOver(fs::path src, fs::path dest); +bool TryCreateDirectory(const fs::path &p); +fs::path GetDefaultDataDir(); +const fs::path &GetDataDir(bool fNetSpecific = true); void ClearDatadirCache(); -boost::filesystem::path GetConfigFile(const std::string &confPath); +fs::path GetConfigFile(const std::string &confPath); #ifndef WIN32 -boost::filesystem::path GetPidFile(); -void CreatePidFile(const boost::filesystem::path &path, pid_t pid); +fs::path GetPidFile(); +void CreatePidFile(const fs::path &path, pid_t pid); #endif void ReadConfigFile(const std::string &confPath); #ifdef WIN32 -boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); +fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true); #endif void OpenDebugLog(); void ShrinkDebugFile(); diff --git a/src/util.cpp b/src/util.cpp --- a/src/util.cpp +++ b/src/util.cpp @@ -10,6 +10,7 @@ #include "util.h" #include "chainparamsbase.h" +#include "fs.h" #include "random.h" #include "serialize.h" #include "sync.h" @@ -79,7 +80,6 @@ #include // for to_lower() #include #include // for startswith() and endswith() -#include #include #include #include @@ -196,8 +196,8 @@ assert(fileout == nullptr); assert(vMsgsBeforeOpenLog); - boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; - fileout = fopen(pathDebug.string().c_str(), "a"); + fs::path pathDebug = GetDataDir() / "debug.log"; + fileout = fsbridge::fopen(pathDebug, "a"); if (fileout) { // Unbuffered. setbuf(fileout, nullptr); @@ -296,9 +296,8 @@ // Reopen the log file, if requested. if (fReopenDebugLog) { fReopenDebugLog = false; - boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; - if (freopen(pathDebug.string().c_str(), "a", fileout) != - nullptr) { + fs::path pathDebug = GetDataDir() / "debug.log"; + if (fsbridge::freopen(pathDebug, "a", fileout) != nullptr) { // unbuffered. setbuf(fileout, nullptr); } @@ -452,8 +451,7 @@ fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); } -boost::filesystem::path GetDefaultDataDir() { - namespace fs = boost::filesystem; +fs::path GetDefaultDataDir() { // Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin // Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin // Mac: ~/Library/Application Support/Bitcoin @@ -478,13 +476,11 @@ #endif } -static boost::filesystem::path pathCached; -static boost::filesystem::path pathCachedNetSpecific; +static fs::path pathCached; +static fs::path pathCachedNetSpecific; static CCriticalSection csPathCached; -const boost::filesystem::path &GetDataDir(bool fNetSpecific) { - namespace fs = boost::filesystem; - +const fs::path &GetDataDir(bool fNetSpecific) { LOCK(csPathCached); fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached; @@ -512,12 +508,12 @@ void ClearDatadirCache() { LOCK(csPathCached); - pathCached = boost::filesystem::path(); - pathCachedNetSpecific = boost::filesystem::path(); + pathCached = fs::path(); + pathCachedNetSpecific = fs::path(); } -boost::filesystem::path GetConfigFile(const std::string &confPath) { - boost::filesystem::path pathConfigFile(confPath); +fs::path GetConfigFile(const std::string &confPath) { + fs::path pathConfigFile(confPath); if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile; @@ -525,7 +521,7 @@ } void ReadConfigFile(const std::string &confPath) { - boost::filesystem::ifstream streamConfig(GetConfigFile(confPath)); + fs::ifstream streamConfig(GetConfigFile(confPath)); // No bitcoin.conf file is OK if (!streamConfig.good()) return; @@ -553,14 +549,14 @@ } #ifndef WIN32 -boost::filesystem::path GetPidFile() { - boost::filesystem::path pathPidFile(GetArg("-pid", BITCOIN_PID_FILENAME)); +fs::path GetPidFile() { + fs::path pathPidFile(GetArg("-pid", BITCOIN_PID_FILENAME)); if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile; return pathPidFile; } -void CreatePidFile(const boost::filesystem::path &path, pid_t pid) { - FILE *file = fopen(path.string().c_str(), "w"); +void CreatePidFile(const fs::path &path, pid_t pid) { + FILE *file = fsbridge::fopen(path, "w"); if (file) { fprintf(file, "%d\n", pid); fclose(file); @@ -568,7 +564,7 @@ } #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(), MOVEFILE_REPLACE_EXISTING) != 0; @@ -583,12 +579,11 @@ * directory exists. 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; } } @@ -699,20 +694,19 @@ // Amount of debug.log to save at end when shrinking (must fit in memory) constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000; // Scroll debug.log if it's getting too big. - boost::filesystem::path pathLog = GetDataDir() / "debug.log"; - FILE *file = fopen(pathLog.string().c_str(), "r"); + fs::path pathLog = GetDataDir() / "debug.log"; + FILE *file = fsbridge::fopen(pathLog, "r"); // If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE // trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes. if (file && - boost::filesystem::file_size(pathLog) > - 11 * (RECENT_DEBUG_HISTORY_SIZE / 10)) { + fs::file_size(pathLog) > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10)) { // Restart the file with some of the end. std::vector vch(RECENT_DEBUG_HISTORY_SIZE, 0); fseek(file, -((long)vch.size()), SEEK_END); int nBytes = fread(vch.data(), 1, vch.size(), file); fclose(file); - file = fopen(pathLog.string().c_str(), "w"); + file = fsbridge::fopen(pathLog, "w"); if (file) { fwrite(vch.data(), 1, nBytes, file); fclose(file); @@ -722,9 +716,7 @@ } #ifdef WIN32 -boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate) { - namespace fs = boost::filesystem; - +fs::path GetSpecialFolderPath(int nFolder, bool fCreate) { char pszPath[MAX_PATH] = ""; if (SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate)) { @@ -784,9 +776,9 @@ // The path locale is lazy initialized and to avoid deinitialization errors // 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); + // fs::path, which is then used to explicitly imbue the path. + std::locale loc = fs::path::imbue(std::locale::classic()); + fs::path::imbue(loc); } bool SetupNetworking() { diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -14,13 +14,12 @@ #include "amount.h" #include "chain.h" #include "coins.h" +#include "fs.h" #include "protocol.h" // For CMessageHeader::MessageMagic #include "script/script_error.h" #include "sync.h" #include "versionbits.h" -#include - #include #include #include @@ -279,8 +278,7 @@ /** 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); +fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix); /** Import blocks from an external file */ bool LoadExternalBlockFile(const Config &config, FILE *fileIn, CDiskBlockPos *dbp = nullptr); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -14,6 +14,7 @@ #include "consensus/consensus.h" #include "consensus/merkle.h" #include "consensus/validation.h" +#include "fs.h" #include "hash.h" #include "init.h" #include "policy/fees.h" @@ -44,7 +45,6 @@ #include #include -#include #include #include #include @@ -3840,8 +3840,8 @@ for (std::set::iterator it = setFilesToPrune.begin(); it != setFilesToPrune.end(); ++it) { CDiskBlockPos pos(*it, 0); - boost::filesystem::remove(GetBlockPosFilename(pos, "blk")); - boost::filesystem::remove(GetBlockPosFilename(pos, "rev")); + fs::remove(GetBlockPosFilename(pos, "blk")); + fs::remove(GetBlockPosFilename(pos, "rev")); LogPrintf("Prune: %s deleted blk/rev (%05u)\n", __func__, *it); } } @@ -3941,8 +3941,7 @@ } bool CheckDiskSpace(uint64_t nAdditionalBytes) { - uint64_t nFreeBytesAvailable = - boost::filesystem::space(GetDataDir()).available; + uint64_t nFreeBytesAvailable = fs::space(GetDataDir()).available; // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) @@ -3954,10 +3953,12 @@ FILE *OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) { if (pos.IsNull()) return nullptr; - 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) file = fopen(path.string().c_str(), "wb+"); + fs::path path = GetBlockPosFilename(pos, prefix); + fs::create_directories(path.parent_path()); + FILE *file = fsbridge::fopen(path, "rb+"); + if (!file && !fReadOnly) { + file = fsbridge::fopen(path, "wb+"); + } if (!file) { LogPrintf("Unable to open file %s\n", path.string()); return nullptr; @@ -3981,8 +3982,7 @@ return OpenDiskFile(pos, "rev", fReadOnly); } -boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, - const char *prefix) { +fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix) { return GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile); } @@ -4922,8 +4922,7 @@ bool LoadMempool(const Config &config) { int64_t nExpiryTimeout = GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60; - FILE *filestr = - fopen((GetDataDir() / "mempool.dat").string().c_str(), "rb"); + FILE *filestr = fsbridge::fopen(GetDataDir() / "mempool.dat", "rb"); CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); if (file.IsNull()) { LogPrintf( @@ -5011,8 +5010,7 @@ int64_t mid = GetTimeMicros(); try { - FILE *filestr = - fopen((GetDataDir() / "mempool.dat.new").string().c_str(), "wb"); + FILE *filestr = fsbridge::fopen(GetDataDir() / "mempool.dat.new", "wb"); if (!filestr) { return; } diff --git a/src/wallet/db.h b/src/wallet/db.h --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -7,6 +7,7 @@ #define BITCOIN_WALLET_DB_H #include "clientversion.h" +#include "fs.h" #include "serialize.h" #include "streams.h" #include "sync.h" @@ -16,8 +17,6 @@ #include #include -#include - #include static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100; @@ -27,7 +26,7 @@ private: bool fDbEnvInit; bool fMockDb; - // Don't change into boost::filesystem::path, as that can result in + // Don't change into fs::path, as that can result in // shutdown problems/crashes caused by a static initialized internal // pointer. std::string strPath; @@ -69,7 +68,7 @@ bool Salvage(const std::string &strFile, bool fAggressive, std::vector &vResult); - bool Open(const boost::filesystem::path &path); + bool Open(const fs::path &path); void Close(); void Flush(bool fShutdown); void CheckpointLSN(const std::string &strFile); diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -6,12 +6,12 @@ #include "db.h" #include "addrman.h" +#include "fs.h" #include "hash.h" #include "protocol.h" #include "util.h" #include "utilstrencodings.h" -#include #include #include @@ -66,7 +66,7 @@ EnvShutdown(); } -bool CDBEnv::Open(const boost::filesystem::path &pathIn) { +bool CDBEnv::Open(const fs::path &pathIn) { if (fDbEnvInit) { return true; } @@ -74,9 +74,9 @@ boost::this_thread::interruption_point(); strPath = pathIn.string(); - boost::filesystem::path pathLogDir = pathIn / "database"; + fs::path pathLogDir = pathIn / "database"; TryCreateDirectory(pathLogDir); - boost::filesystem::path pathErrorFile = pathIn / "db.log"; + fs::path pathErrorFile = pathIn / "db.log"; LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string()); @@ -93,7 +93,7 @@ dbenv->set_lk_max_locks(40000); dbenv->set_lk_max_objects(40000); /// debug - dbenv->set_errfile(fopen(pathErrorFile.string().c_str(), "a")); + dbenv->set_errfile(fsbridge::fopen(pathErrorFile, "a")); dbenv->set_flags(DB_AUTO_COMMIT, 1); dbenv->set_flags(DB_TXN_WRITE_NOSYNC, 1); dbenv->log_set_config(DB_LOG_AUTO_REMOVE, 1); @@ -480,8 +480,7 @@ dbenv->log_archive(&listp, DB_ARCH_REMOVE); Close(); if (!fMockDb) { - boost::filesystem::remove_all( - boost::filesystem::path(strPath) / "database"); + fs::remove_all(fs::path(strPath) / "database"); } } } diff --git a/src/wallet/test/walletdb_tests.cpp b/src/wallet/test/walletdb_tests.cpp --- a/src/wallet/test/walletdb_tests.cpp +++ b/src/wallet/test/walletdb_tests.cpp @@ -22,12 +22,12 @@ } }; -static std::unique_ptr TmpDB(const boost::filesystem::path &pathTemp, +static std::unique_ptr TmpDB(const fs::path &pathTemp, const std::string &testname) { - boost::filesystem::path dir = pathTemp / testname; - BOOST_CHECK_MESSAGE(boost::filesystem::create_directory(dir), + fs::path dir = pathTemp / testname; + BOOST_CHECK_MESSAGE(fs::create_directory(dir), "Unable to create a directory for test " + testname); - boost::filesystem::path path = + fs::path path = dir / strprintf("testwallet%i", static_cast(GetRand(1000000))); return std::unique_ptr(new CWalletDB(path.string(), "cr+")); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -11,6 +11,7 @@ #include "consensus/consensus.h" #include "consensus/validation.h" #include "dstencode.h" +#include "fs.h" #include "key.h" #include "keystore.h" #include "net.h" @@ -30,7 +31,6 @@ #include "wallet/finaltx.h" #include -#include #include #include @@ -538,9 +538,7 @@ uiInterface.InitMessage(_("Verifying wallet...")); // Wallet file must be a plain filename without a directory. - if (walletFile != - boost::filesystem::basename(walletFile) + - boost::filesystem::extension(walletFile)) { + if (walletFile != fs::basename(walletFile) + fs::extension(walletFile)) { return InitError( strprintf(_("Wallet %s resides outside data directory %s"), walletFile, GetDataDir().string())); @@ -548,14 +546,14 @@ if (!bitdb.Open(GetDataDir())) { // Try moving the database env out of the way. - boost::filesystem::path pathDatabase = GetDataDir() / "database"; - boost::filesystem::path pathDatabaseBak = + fs::path pathDatabase = GetDataDir() / "database"; + fs::path pathDatabaseBak = GetDataDir() / strprintf("database.%d.bak", GetTime()); try { - boost::filesystem::rename(pathDatabase, pathDatabaseBak); + fs::rename(pathDatabase, pathDatabaseBak); LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string()); - } catch (const boost::filesystem::filesystem_error &) { + } catch (const fs::filesystem_error &) { // Failure is ok (well, not really, but it's not worse than what we // started with) } @@ -575,7 +573,7 @@ if (!CWalletDB::Recover(bitdb, walletFile, true)) return false; } - if (boost::filesystem::exists(GetDataDir() / walletFile)) { + if (fs::exists(GetDataDir() / walletFile)) { CDBEnv::VerifyResult r = bitdb.Verify(walletFile, CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) { InitWarning(strprintf( @@ -4389,31 +4387,30 @@ bitdb.mapFileUseCount.erase(strWalletFile); // Copy wallet file. - boost::filesystem::path pathSrc = GetDataDir() / strWalletFile; - boost::filesystem::path pathDest(strDest); - if (boost::filesystem::is_directory(pathDest)) { + fs::path pathSrc = GetDataDir() / strWalletFile; + fs::path pathDest(strDest); + if (fs::is_directory(pathDest)) { pathDest /= strWalletFile; } try { - if (boost::filesystem::equivalent(pathSrc, pathDest)) { + if (fs::equivalent(pathSrc, pathDest)) { LogPrintf("cannot backup to wallet source file %s\n", pathDest.string()); return false; } #if BOOST_VERSION >= 104000 - boost::filesystem::copy_file( - pathSrc, pathDest, - boost::filesystem::copy_option::overwrite_if_exists); + fs::copy_file(pathSrc, pathDest, + fs::copy_option::overwrite_if_exists); #else - boost::filesystem::copy_file(pathSrc, pathDest); + fs::copy_file(pathSrc, pathDest); #endif LogPrintf("copied %s to %s\n", strWalletFile, pathDest.string()); return true; - } catch (const boost::filesystem::filesystem_error &e) { + } catch (const fs::filesystem_error &e) { LogPrintf("error copying %s to %s - %s\n", strWalletFile, pathDest.string(), e.what()); return false; diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -9,6 +9,7 @@ #include "base58.h" #include "consensus/validation.h" #include "dstencode.h" +#include "fs.h" #include "protocol.h" #include "serialize.h" #include "sync.h" @@ -17,7 +18,6 @@ #include "validation.h" // For CheckRegularTransaction #include "wallet/wallet.h" -#include #include #include