Skip to content

Commit

Permalink
Move boost/std fstream to fsbridge
Browse files Browse the repository at this point in the history
Adaptation of btc@a554cc901a32f41162089d6b20ad39d5aeff0583.
  • Loading branch information
furszy committed Aug 1, 2021
1 parent 9d8bcd4 commit 2e57cd4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/masternodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool CMasternodeConfig::read(std::string& strErr)
LOCK(cs_entries);
int linenumber = 1;
fs::path pathMasternodeConfigFile = GetMasternodeConfigFile();
fs::ifstream streamConfig(pathMasternodeConfigFile);
fsbridge::ifstream streamConfig(pathMasternodeConfigFile);

if (!streamConfig.good()) {
FILE* configFile = fsbridge::fopen(pathMasternodeConfigFile, "a");
Expand Down
4 changes: 2 additions & 2 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fs::path static GetAutostartFilePath()

bool GetStartOnSystemStartup()
{
fs::ifstream optionFile(GetAutostartFilePath());
fsbridge::ifstream optionFile(GetAutostartFilePath());
if (!optionFile.good())
return false;
// Scan through file for "Hidden=true":
Expand Down Expand Up @@ -564,7 +564,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)

fs::create_directories(GetAutostartDir());

fs::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc);
fsbridge::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc);
if (!optionFile.good())
return false;
// Write a pivx.desktop file to the autostart directory:
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/masternodeswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void MasterNodesWidget::onDeleteMNClicked()
fs::path pathBootstrap = GetDataDir() / strConfFile;
if (fs::exists(pathBootstrap)) {
fs::path pathMasternodeConfigFile = GetMasternodeConfigFile();
fs::ifstream streamConfig(pathMasternodeConfigFile);
fsbridge::ifstream streamConfig(pathMasternodeConfigFile);

if (!streamConfig.good()) {
inform(tr("Invalid masternode.conf file"));
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/masternodewizarddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ bool MasterNodeWizardDialog::createMN()
}

fs::path pathMasternodeConfigFile = GetMasternodeConfigFile();
fs::ifstream streamConfig(pathMasternodeConfigFile);
fsbridge::ifstream streamConfig(pathMasternodeConfigFile);

if (!streamConfig.good()) {
returnStr = tr("Invalid masternode.conf file");
Expand Down
17 changes: 7 additions & 10 deletions src/rpc/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#include "utiltime.h"
#include "version.h"

#include <fstream>


/**
* JSON-RPC protocol. PIVX speaks version 1.0 for maximum compatibility,
* but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were
Expand Down Expand Up @@ -85,16 +82,16 @@ bool GenerateAuthCookie(std::string *cookie_out)
/** the umask determines what permissions are used to create this file -
* these are set to 077 in init.cpp unless overridden with -sysperms.
*/
std::ofstream file;
fs::path filepath = GetAuthCookieFile();
file.open(filepath.string().c_str());
fsbridge::ofstream file;
fs::path filepath_tmp = GetAuthCookieFile();
file.open(filepath_tmp);
if (!file.is_open()) {
LogPrintf("Unable to open cookie authentication file %s for writing\n", filepath.string());
LogPrintf("Unable to open cookie authentication file %s for writing\n", filepath_tmp.string());
return false;
}
file << cookie;
file.close();
LogPrintf("Generated RPC authentication cookie %s\n", filepath.string());
LogPrintf("Generated RPC authentication cookie %s\n", filepath_tmp.string());

if (cookie_out)
*cookie_out = cookie;
Expand All @@ -103,10 +100,10 @@ bool GenerateAuthCookie(std::string *cookie_out)

bool GetAuthCookie(std::string *cookie_out)
{
std::ifstream file;
fsbridge::ifstream file;
std::string cookie;
fs::path filepath = GetAuthCookieFile();
file.open(filepath.string().c_str());
file.open(filepath);
if (!file.is_open())
return false;
std::getline(file, cookie);
Expand Down
2 changes: 1 addition & 1 deletion src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
m_config_args.clear();
}

fs::ifstream stream(GetConfigFile(confPath));
fsbridge::ifstream stream(GetConfigFile(confPath));

// ok to not have a config file
if (stream.good()) {
Expand Down
12 changes: 6 additions & 6 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "wallet.h"
#include "validation.h"

#include <fstream>
#include <secp256k1.h>
#include <stdint.h>

Expand Down Expand Up @@ -350,10 +349,11 @@ UniValue importwallet(const JSONRPCRequest& request)
"\nImport using the json rpc call\n" +
HelpExampleRpc("importwallet", "\"test\""));

std::ifstream file;
file.open(request.params[0].get_str().c_str(), std::ios::in | std::ios::ate);
if (!file.is_open())
fsbridge::ifstream file;
file.open(request.params[0].get_str(), std::ios::in | std::ios::ate);
if (!file.is_open()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
}

WalletRescanReserver reserver(pwallet);
if (!reserver.reserve()) {
Expand Down Expand Up @@ -547,8 +547,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, filepath.string() + " already exists. If you are sure this is what you want, move it out of the way first");
}

std::ofstream file;
file.open(request.params[0].get_str().c_str());
fsbridge::ofstream file;
file.open(filepath);
if (!file.is_open())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");

Expand Down

0 comments on commit 2e57cd4

Please sign in to comment.