Skip to content

Commit bac5c9c

Browse files
committed
Replace uses of boost::filesystem with fs
Step two in abstracting away boost::filesystem. To repeat this, simply run: ``` git ls-files \*.cpp \*.h | xargs sed -i 's/boost::filesystem/fs/g' ```
1 parent 7d5172d commit bac5c9c

28 files changed

+139
-139
lines changed

src/addrdb.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bool CBanDB::Write(const banmap_t& banSet)
3636
ssBanlist << hash;
3737

3838
// open temp output file, and associate with CAutoFile
39-
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
39+
fs::path pathTmp = GetDataDir() / tmpfn;
4040
FILE *file = fopen(pathTmp.string().c_str(), "wb");
4141
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
4242
if (fileout.IsNull())
@@ -68,7 +68,7 @@ bool CBanDB::Read(banmap_t& banSet)
6868
return error("%s: Failed to open file %s", __func__, pathBanlist.string());
6969

7070
// use file size to size memory buffer
71-
uint64_t fileSize = boost::filesystem::file_size(pathBanlist);
71+
uint64_t fileSize = fs::file_size(pathBanlist);
7272
uint64_t dataSize = 0;
7373
// Don't try to resize to a negative number if file is small
7474
if (fileSize >= sizeof(uint256))
@@ -133,7 +133,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
133133
ssPeers << hash;
134134

135135
// open temp output file, and associate with CAutoFile
136-
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
136+
fs::path pathTmp = GetDataDir() / tmpfn;
137137
FILE *file = fopen(pathTmp.string().c_str(), "wb");
138138
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
139139
if (fileout.IsNull())
@@ -165,7 +165,7 @@ bool CAddrDB::Read(CAddrMan& addr)
165165
return error("%s: Failed to open file %s", __func__, pathAddr.string());
166166

167167
// use file size to size memory buffer
168-
uint64_t fileSize = boost::filesystem::file_size(pathAddr);
168+
uint64_t fileSize = fs::file_size(pathAddr);
169169
uint64_t dataSize = 0;
170170
// Don't try to resize to a negative number if file is small
171171
if (fileSize >= sizeof(uint256))

src/addrdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef std::map<CSubNet, CBanEntry> banmap_t;
8080
class CAddrDB
8181
{
8282
private:
83-
boost::filesystem::path pathAddr;
83+
fs::path pathAddr;
8484
public:
8585
CAddrDB();
8686
bool Write(const CAddrMan& addr);
@@ -92,7 +92,7 @@ class CAddrDB
9292
class CBanDB
9393
{
9494
private:
95-
boost::filesystem::path pathBanlist;
95+
fs::path pathBanlist;
9696
public:
9797
CBanDB();
9898
bool Write(const banmap_t& banSet);

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int AppInitRPC(int argc, char* argv[])
9696
}
9797
return EXIT_SUCCESS;
9898
}
99-
if (!boost::filesystem::is_directory(GetDataDir(false))) {
99+
if (!fs::is_directory(GetDataDir(false))) {
100100
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str());
101101
return EXIT_FAILURE;
102102
}

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool AppInit(int argc, char* argv[])
9797

9898
try
9999
{
100-
if (!boost::filesystem::is_directory(GetDataDir(false)))
100+
if (!fs::is_directory(GetDataDir(false)))
101101
{
102102
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str());
103103
return false;

src/dbwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
9090
return options;
9191
}
9292

93-
CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
93+
CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
9494
{
9595
penv = NULL;
9696
readoptions.verify_checksums = true;

src/dbwrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class CDBWrapper
194194
* @param[in] obfuscate If true, store data obfuscated via simple XOR. If false, XOR
195195
* with a zero'd byte array.
196196
*/
197-
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
197+
CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
198198
~CDBWrapper();
199199

200200
template <typename K, typename V>

src/init.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void Shutdown()
212212

213213
if (fFeeEstimatesInitialized)
214214
{
215-
boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
215+
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
216216
CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION);
217217
if (!est_fileout.IsNull())
218218
mempool.WriteFeeEstimates(est_fileout);
@@ -250,8 +250,8 @@ void Shutdown()
250250

251251
#ifndef WIN32
252252
try {
253-
boost::filesystem::remove(GetPidFile());
254-
} catch (const boost::filesystem::filesystem_error& e) {
253+
fs::remove(GetPidFile());
254+
} catch (const fs::filesystem_error& e) {
255255
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what());
256256
}
257257
#endif
@@ -578,14 +578,14 @@ struct CImportingNow
578578
// works correctly.
579579
void CleanupBlockRevFiles()
580580
{
581-
std::map<std::string, boost::filesystem::path> mapBlockFiles;
581+
std::map<std::string, fs::path> mapBlockFiles;
582582

583583
// Glob all blk?????.dat and rev?????.dat files from the blocks directory.
584584
// Remove the rev files immediately and insert the blk file paths into an
585585
// ordered map keyed by block file index.
586586
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
587-
boost::filesystem::path blocksdir = GetDataDir() / "blocks";
588-
for (boost::filesystem::directory_iterator it(blocksdir); it != boost::filesystem::directory_iterator(); it++) {
587+
fs::path blocksdir = GetDataDir() / "blocks";
588+
for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
589589
if (is_regular_file(*it) &&
590590
it->path().filename().string().length() == 12 &&
591591
it->path().filename().string().substr(8,4) == ".dat")
@@ -602,7 +602,7 @@ void CleanupBlockRevFiles()
602602
// keeping a separate counter. Once we hit a gap (or if 0 doesn't exist)
603603
// start removing block files.
604604
int nContigCounter = 0;
605-
BOOST_FOREACH(const PAIRTYPE(std::string, boost::filesystem::path)& item, mapBlockFiles) {
605+
BOOST_FOREACH(const PAIRTYPE(std::string, fs::path)& item, mapBlockFiles) {
606606
if (atoi(item.first) == nContigCounter) {
607607
nContigCounter++;
608608
continue;
@@ -611,7 +611,7 @@ void CleanupBlockRevFiles()
611611
}
612612
}
613613

614-
void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
614+
void ThreadImport(std::vector<fs::path> vImportFiles)
615615
{
616616
const CChainParams& chainparams = Params();
617617
RenameThread("bitcoin-loadblk");
@@ -624,7 +624,7 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
624624
int nFile = 0;
625625
while (true) {
626626
CDiskBlockPos pos(nFile, 0);
627-
if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk")))
627+
if (!fs::exists(GetBlockPosFilename(pos, "blk")))
628628
break; // No block files left to reindex
629629
FILE *file = OpenBlockFile(pos, true);
630630
if (!file)
@@ -641,11 +641,11 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
641641
}
642642

643643
// hardcoded $DATADIR/bootstrap.dat
644-
boost::filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat";
645-
if (boost::filesystem::exists(pathBootstrap)) {
644+
fs::path pathBootstrap = GetDataDir() / "bootstrap.dat";
645+
if (fs::exists(pathBootstrap)) {
646646
FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
647647
if (file) {
648-
boost::filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
648+
fs::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
649649
LogPrintf("Importing bootstrap.dat...\n");
650650
LoadExternalBlockFile(chainparams, file);
651651
RenameOver(pathBootstrap, pathBootstrapOld);
@@ -655,7 +655,7 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
655655
}
656656

657657
// -loadblock=
658-
BOOST_FOREACH(const boost::filesystem::path& path, vImportFiles) {
658+
BOOST_FOREACH(const fs::path& path, vImportFiles) {
659659
FILE *file = fopen(path.string().c_str(), "rb");
660660
if (file) {
661661
LogPrintf("Importing blocks file %s...\n", path.string());
@@ -1123,7 +1123,7 @@ static bool LockDataDirectory(bool probeOnly)
11231123
std::string strDataDir = GetDataDir().string();
11241124

11251125
// Make sure only a single Bitcoin process is using the data directory.
1126-
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
1126+
fs::path pathLockFile = GetDataDir() / ".lock";
11271127
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
11281128
if (file) fclose(file);
11291129

@@ -1388,7 +1388,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
13881388
fReindex = GetBoolArg("-reindex", false);
13891389
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false);
13901390

1391-
boost::filesystem::create_directories(GetDataDir() / "blocks");
1391+
fs::create_directories(GetDataDir() / "blocks");
13921392

13931393
// cache size calculations
13941394
int64_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
@@ -1534,7 +1534,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15341534
}
15351535
LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);
15361536

1537-
boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
1537+
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
15381538
CAutoFile est_filein(fopen(est_path.string().c_str(), "rb"), SER_DISK, CLIENT_VERSION);
15391539
// Allowed to fail as this file IS missing on first startup.
15401540
if (!est_filein.IsNull())
@@ -1590,7 +1590,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15901590
if (IsArgSet("-blocknotify"))
15911591
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
15921592

1593-
std::vector<boost::filesystem::path> vImportFiles;
1593+
std::vector<fs::path> vImportFiles;
15941594
if (mapMultiArgs.count("-loadblock"))
15951595
{
15961596
BOOST_FOREACH(const std::string& strFile, mapMultiArgs.at("-loadblock"))

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ int main(int argc, char *argv[])
608608

609609
/// 6. Determine availability of data directory and parse bitcoin.conf
610610
/// - Do not call GetDataDir(true) before this step finishes
611-
if (!boost::filesystem::is_directory(GetDataDir(false)))
611+
if (!fs::is_directory(GetDataDir(false)))
612612
{
613613
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
614614
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(GetArg("-datadir", ""))));

src/qt/guiutil.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#include <QFontDatabase>
6464
#endif
6565

66-
static boost::filesystem::detail::utf8_codecvt_facet utf8;
66+
static fs::detail::utf8_codecvt_facet utf8;
6767

6868
#if defined(Q_OS_MAC)
6969
extern double NSAppKitVersionNumber;
@@ -408,10 +408,10 @@ bool isObscured(QWidget *w)
408408

409409
void openDebugLogfile()
410410
{
411-
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
411+
fs::path pathDebug = GetDataDir() / "debug.log";
412412

413413
/* Open debug.log with the associated application */
414-
if (boost::filesystem::exists(pathDebug))
414+
if (fs::exists(pathDebug))
415415
QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathDebug)));
416416
}
417417

@@ -595,7 +595,7 @@ TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* t
595595
}
596596

597597
#ifdef WIN32
598-
boost::filesystem::path static StartupShortcutPath()
598+
fs::path static StartupShortcutPath()
599599
{
600600
std::string chain = ChainNameFromCommandLine();
601601
if (chain == CBaseChainParams::MAIN)
@@ -608,13 +608,13 @@ boost::filesystem::path static StartupShortcutPath()
608608
bool GetStartOnSystemStartup()
609609
{
610610
// check for Bitcoin*.lnk
611-
return boost::filesystem::exists(StartupShortcutPath());
611+
return fs::exists(StartupShortcutPath());
612612
}
613613

614614
bool SetStartOnSystemStartup(bool fAutoStart)
615615
{
616616
// If the shortcut exists already, remove it for updating
617-
boost::filesystem::remove(StartupShortcutPath());
617+
fs::remove(StartupShortcutPath());
618618

619619
if (fAutoStart)
620620
{
@@ -684,9 +684,9 @@ bool SetStartOnSystemStartup(bool fAutoStart)
684684
// Follow the Desktop Application Autostart Spec:
685685
// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
686686

687-
boost::filesystem::path static GetAutostartDir()
687+
fs::path static GetAutostartDir()
688688
{
689-
namespace fs = boost::filesystem;
689+
namespace fs = fs;
690690

691691
char* pszConfigHome = getenv("XDG_CONFIG_HOME");
692692
if (pszConfigHome) return fs::path(pszConfigHome) / "autostart";
@@ -695,7 +695,7 @@ boost::filesystem::path static GetAutostartDir()
695695
return fs::path();
696696
}
697697

698-
boost::filesystem::path static GetAutostartFilePath()
698+
fs::path static GetAutostartFilePath()
699699
{
700700
std::string chain = ChainNameFromCommandLine();
701701
if (chain == CBaseChainParams::MAIN)
@@ -705,7 +705,7 @@ boost::filesystem::path static GetAutostartFilePath()
705705

706706
bool GetStartOnSystemStartup()
707707
{
708-
boost::filesystem::ifstream optionFile(GetAutostartFilePath());
708+
fs::ifstream optionFile(GetAutostartFilePath());
709709
if (!optionFile.good())
710710
return false;
711711
// Scan through file for "Hidden=true":
@@ -725,17 +725,17 @@ bool GetStartOnSystemStartup()
725725
bool SetStartOnSystemStartup(bool fAutoStart)
726726
{
727727
if (!fAutoStart)
728-
boost::filesystem::remove(GetAutostartFilePath());
728+
fs::remove(GetAutostartFilePath());
729729
else
730730
{
731731
char pszExePath[MAX_PATH+1];
732732
memset(pszExePath, 0, sizeof(pszExePath));
733733
if (readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1) == -1)
734734
return false;
735735

736-
boost::filesystem::create_directories(GetAutostartDir());
736+
fs::create_directories(GetAutostartDir());
737737

738-
boost::filesystem::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
738+
fs::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
739739
if (!optionFile.good())
740740
return false;
741741
std::string chain = ChainNameFromCommandLine();
@@ -857,12 +857,12 @@ void setClipboard(const QString& str)
857857
QApplication::clipboard()->setText(str, QClipboard::Selection);
858858
}
859859

860-
boost::filesystem::path qstringToBoostPath(const QString &path)
860+
fs::path qstringToBoostPath(const QString &path)
861861
{
862-
return boost::filesystem::path(path.toStdString(), utf8);
862+
return fs::path(path.toStdString(), utf8);
863863
}
864864

865-
QString boostPathToQString(const boost::filesystem::path &path)
865+
QString boostPathToQString(const fs::path &path)
866866
{
867867
return QString::fromStdString(path.string(utf8));
868868
}

src/qt/guiutil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ namespace GUIUtil
182182
void restoreWindowGeometry(const QString& strSetting, const QSize &defaultSizeIn, QWidget *parent);
183183

184184
/* Convert QString to OS specific boost path through UTF-8 */
185-
boost::filesystem::path qstringToBoostPath(const QString &path);
185+
fs::path qstringToBoostPath(const QString &path);
186186

187187
/* Convert OS specific boost path to QString through UTF-8 */
188-
QString boostPathToQString(const boost::filesystem::path &path);
188+
QString boostPathToQString(const fs::path &path);
189189

190190
/* Convert seconds into a QString with days, hours, mins, secs */
191191
QString formatDurationStr(int secs);

0 commit comments

Comments
 (0)