Skip to content

Commit

Permalink
Switch boost::filesystem -> std::filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaron-zilliqa committed Aug 11, 2023
1 parent ff0c512 commit 40791da
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 147 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ find_package(Protobuf REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

find_package(Boost COMPONENTS filesystem system unit_test_framework program_options REQUIRED)
find_package(Boost COMPONENTS system unit_test_framework program_options REQUIRED)

find_package(Schnorr REQUIRED)
find_package(CryptoUtils REQUIRED)
Expand Down
9 changes: 4 additions & 5 deletions src/cmd/genTxnBodiesFromS3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
/// true

#include <boost/exception/diagnostic_information.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>

Expand Down Expand Up @@ -60,7 +59,7 @@ int main(int argc, char* argv[]) {
"Save the txns in json format to file")(
"jsonOutputPath,p",
po::value<string>(&jsonOutputPath)
->default_value(bfs::current_path().string() + "/" +
->default_value(std::filesystem::current_path().string() + "/" +
JSON_OUTPUT_FOLDER),
"Json folder path to store txns in json format");

Expand All @@ -81,7 +80,7 @@ int main(int argc, char* argv[]) {

string remoteS3Path = "s3://" + bucketName + "/" + backupFolderName;
string localBackupPath =
bfs::current_path().string() + "/" + backupFolderName;
std::filesystem::current_path().string() + "/" + backupFolderName;
// Download from S3
if (!SysCommand::ExecuteCmd(
SysCommand::WITHOUT_OUTPUT,
Expand All @@ -95,8 +94,8 @@ int main(int argc, char* argv[]) {

// create json output folder
if (saveToJsonFormat) {
if (!(boost::filesystem::exists(jsonOutputPath))) {
if (!boost::filesystem::create_directories(jsonOutputPath)) {
if (!(std::filesystem::exists(jsonOutputPath))) {
if (!std::filesystem::create_directories(jsonOutputPath)) {
cerr << "Failed to created JSON output folder ! will skip creating "
"txns in json format"
<< endl;
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/gentxn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <boost/filesystem.hpp>
#include <climits>
#include <fstream>
#include <string>
Expand Down Expand Up @@ -195,7 +194,7 @@ int main(int argc, char** argv) {
auto toAddr = Account::GetAddressFromPublicKey(receiver.second);

std::string txn_path{TXN_PATH};
if (!boost::filesystem::exists(txn_path)) {
if (!std::filesystem::exists(txn_path)) {
std::cerr << "Cannot find path '" << txn_path
<< "', check TXN_PATH in constants.xml\n";
return 1;
Expand Down
1 change: 0 additions & 1 deletion src/cmd/validateDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <boost/filesystem/operations.hpp>
#include "libMediator/Mediator.h"
#include "libNetwork/Guard.h"
#include "libNode/Node.h"
Expand Down
2 changes: 1 addition & 1 deletion src/depends/libDatabase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library (Database LevelDB.cpp MemoryDB.cpp OverlayDB.cpp)
target_compile_options(Database PRIVATE "-Wno-unused-parameter")
target_include_directories (Database PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_link_libraries (Database PUBLIC Common leveldb::leveldb Utils PRIVATE Boost::filesystem)
target_link_libraries (Database PUBLIC Common leveldb::leveldb Utils)
17 changes: 8 additions & 9 deletions src/depends/libDatabase/LevelDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <string>

#include <boost/filesystem/operations.hpp>

#include "LevelDB.h"
#include "common/Constants.h"
Expand All @@ -42,7 +41,7 @@ LevelDB::LevelDB(const string& dbName, const string& path, const string& subdire
this->m_dbName = dbName;
this->m_db = NULL;

if(!(boost::filesystem::exists(path)))
if(!(std::filesystem::exists(path)))
{
LOG_GENERAL(WARNING, path + " does not exist");
return;
Expand All @@ -62,9 +61,9 @@ LevelDB::LevelDB(const string& dbName, const string& path, const string& subdire
}
else
{
if (!(boost::filesystem::exists(path + "/" + this->m_subdirectory)))
if (!(std::filesystem::exists(path + "/" + this->m_subdirectory)))
{
boost::filesystem::create_directories(path + "/" + this->m_subdirectory);
std::filesystem::create_directories(path + "/" + this->m_subdirectory);
}
m_open_db_path = path + "/" + this->m_subdirectory + "/" + this->m_dbName;
status = leveldb::DB::Open(m_options,
Expand Down Expand Up @@ -97,9 +96,9 @@ LevelDB::LevelDB(const std::string & dbName, const std::string& subdirectory, bo
// Its default value is false, and the non-diagnostic path is preserved
// from the original code.
string db_path = diagnostic ? (m_subdirectory + PERSISTENCE_PATH) : (STORAGE_PATH + PERSISTENCE_PATH + (m_subdirectory.empty() ? "" : "/" + m_subdirectory));
if (!boost::filesystem::exists(db_path))
if (!std::filesystem::exists(db_path))
{
boost::filesystem::create_directories(db_path);
std::filesystem::create_directories(db_path);
}

m_open_db_path = db_path + "/" + this->m_dbName;
Expand Down Expand Up @@ -549,7 +548,7 @@ int LevelDB::DeleteDBForNormalNode()

if(this->m_subdirectory.size())
{
boost::filesystem::remove_all(STORAGE_PATH + PERSISTENCE_PATH + "/" + this->m_subdirectory + "/" + this->m_dbName);
std::filesystem::remove_all(STORAGE_PATH + PERSISTENCE_PATH + "/" + this->m_subdirectory + "/" + this->m_dbName);
}

return 0;
Expand All @@ -559,7 +558,7 @@ bool LevelDB::ResetDBForNormalNode()
{
if(DeleteDBForNormalNode() == 0 && this->m_subdirectory.empty())
{
boost::filesystem::remove_all(STORAGE_PATH + PERSISTENCE_PATH + "/" + this->m_dbName);
std::filesystem::remove_all(STORAGE_PATH + PERSISTENCE_PATH + "/" + this->m_dbName);

leveldb::Options options;
options.max_open_files = 256;
Expand Down Expand Up @@ -602,7 +601,7 @@ bool LevelDB::ResetDBForLookupNode()
{
if(DeleteDBForLookupNode()==0)
{
boost::filesystem::remove_all(STORAGE_PATH + PERSISTENCE_PATH + "/" + this->m_dbName);
std::filesystem::remove_all(STORAGE_PATH + PERSISTENCE_PATH + "/" + this->m_dbName);

leveldb::Options options;
options.max_open_files = 256;
Expand Down
13 changes: 6 additions & 7 deletions src/libCps/ScillaHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "libUtils/Logger.h"
#include "libUtils/TimeUtils.h"

#include <boost/filesystem.hpp>
#include <fstream>

namespace libCps {
Expand Down Expand Up @@ -67,11 +66,11 @@ bool ScillaHelpers::ExportContractFiles(
LOG_MARKER();
std::chrono::system_clock::time_point tpStart;

boost::filesystem::remove_all("./" + SCILLA_FILES);
boost::filesystem::create_directories("./" + SCILLA_FILES);
std::filesystem::remove_all("./" + SCILLA_FILES);
std::filesystem::create_directories("./" + SCILLA_FILES);

if (!(boost::filesystem::exists("./" + SCILLA_LOG))) {
boost::filesystem::create_directories("./" + SCILLA_LOG);
if (!(std::filesystem::exists("./" + SCILLA_LOG))) {
std::filesystem::create_directories("./" + SCILLA_LOG);
}

if (ENABLE_CHECK_PERFORMANCE_LOG) {
Expand Down Expand Up @@ -310,8 +309,8 @@ bool ScillaHelpers::PopulateExtlibsExports(
std::string code_path = EXTLIB_FOLDER + '/' + libAddr.hex();
code_path += LIBRARY_CODE_EXTENSION;
std::string json_path = EXTLIB_FOLDER + '/' + libAddr.hex() + ".json";
if (boost::filesystem::exists(code_path) &&
boost::filesystem::exists(json_path)) {
if (std::filesystem::exists(code_path) &&
std::filesystem::exists(json_path)) {
continue;
}

Expand Down
1 change: 0 additions & 1 deletion src/libCps/ScillaHelpersCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "libUtils/Logger.h"
#include "libUtils/TimeUtils.h"

#include <boost/filesystem.hpp>
#include <fstream>

namespace libCps {
Expand Down
5 changes: 2 additions & 3 deletions src/libData/AccountStore/AccountStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include <leveldb/db.h>
#include <boost/filesystem/operations.hpp>
#include <regex>

#include "libData/AccountStore/AccountStore.h"
Expand Down Expand Up @@ -104,7 +103,7 @@ AccountStore::AccountStore()
if (ENABLE_SC || ENABLE_EVM || ISOLATED_SERVER) {
/// Scilla IPC Server
/// clear path
boost::filesystem::remove_all(SCILLA_IPC_SOCKET_PATH);
std::filesystem::remove_all(SCILLA_IPC_SOCKET_PATH);
m_scillaIPCServer =
make_shared<ScillaIPCServer>(this, m_scillaIPCServerConnector);

Expand Down Expand Up @@ -135,7 +134,7 @@ AccountStore::AccountStore()
}

AccountStore::~AccountStore() {
// boost::filesystem::remove_all("./state");
// std::filesystem::remove_all("./state");
if (m_scillaIPCServer != nullptr) {
m_scillaIPCServer->StopListening();
}
Expand Down
33 changes: 16 additions & 17 deletions src/libData/AccountStore/AccountStoreSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
#include <chrono>

#include <boost/filesystem.hpp>

#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -139,8 +138,8 @@ void AccountStoreSC::Init() {
m_curGasLimit = 0;
m_curGasPrice = 0;
m_txnProcessTimeout = false;
boost::filesystem::remove_all(EXTLIB_FOLDER);
boost::filesystem::create_directories(EXTLIB_FOLDER);
std::filesystem::remove_all(EXTLIB_FOLDER);
std::filesystem::create_directories(EXTLIB_FOLDER);
}

void AccountStoreSC::InvokeInterpreter(
Expand Down Expand Up @@ -878,8 +877,8 @@ bool AccountStoreSC::PopulateExtlibsExports(
std::string code_path = EXTLIB_FOLDER + '/' + libAddr.hex();
code_path += LIBRARY_CODE_EXTENSION;
std::string json_path = EXTLIB_FOLDER + '/' + libAddr.hex() + ".json";
if (boost::filesystem::exists(code_path) &&
boost::filesystem::exists(json_path)) {
if (std::filesystem::exists(code_path) &&
std::filesystem::exists(json_path)) {
continue;
}

Expand Down Expand Up @@ -925,11 +924,11 @@ bool AccountStoreSC::ExportCreateContractFiles(
&extlibs_exports) {
LOG_MARKER();

boost::filesystem::remove_all("./" + SCILLA_FILES);
boost::filesystem::create_directories("./" + SCILLA_FILES);
std::filesystem::remove_all("./" + SCILLA_FILES);
std::filesystem::create_directories("./" + SCILLA_FILES);

if (!(boost::filesystem::exists("./" + SCILLA_LOG))) {
boost::filesystem::create_directories("./" + SCILLA_LOG);
if (!(std::filesystem::exists("./" + SCILLA_LOG))) {
std::filesystem::create_directories("./" + SCILLA_LOG);
}

if (!ScillaUtils::PrepareRootPathWVersion(scilla_version, m_root_w_version)) {
Expand Down Expand Up @@ -970,15 +969,15 @@ void AccountStoreSC::ExportCommonFiles(
std::string code_path =
EXTLIB_FOLDER + '/' + "0x" + extlib_export.first.hex();
code_path += LIBRARY_CODE_EXTENSION;
boost::filesystem::remove(code_path);
std::filesystem::remove(code_path);

os.open(code_path);
os << extlib_export.second.first;
os.close();

std::string init_path =
EXTLIB_FOLDER + '/' + "0x" + extlib_export.first.hex() + ".json";
boost::filesystem::remove(init_path);
std::filesystem::remove(init_path);

os.open(init_path);
os << extlib_export.second.second;
Expand All @@ -993,11 +992,11 @@ bool AccountStoreSC::ExportContractFiles(
LOG_MARKER();
std::chrono::system_clock::time_point tpStart;

boost::filesystem::remove_all("./" + SCILLA_FILES);
boost::filesystem::create_directories("./" + SCILLA_FILES);
std::filesystem::remove_all("./" + SCILLA_FILES);
std::filesystem::create_directories("./" + SCILLA_FILES);

if (!(boost::filesystem::exists("./" + SCILLA_LOG))) {
boost::filesystem::create_directories("./" + SCILLA_LOG);
if (!(std::filesystem::exists("./" + SCILLA_LOG))) {
std::filesystem::create_directories("./" + SCILLA_LOG);
}

if (ENABLE_CHECK_PERFORMANCE_LOG) {
Expand Down Expand Up @@ -1732,8 +1731,8 @@ void AccountStoreSC::SetScillaIPCServer(

void AccountStoreSC::CleanNewLibrariesCache() {
for (const auto &addr : m_newLibrariesCreated) {
boost::filesystem::remove(addr.hex() + LIBRARY_CODE_EXTENSION);
boost::filesystem::remove(addr.hex() + ".json");
std::filesystem::remove(addr.hex() + LIBRARY_CODE_EXTENSION);
std::filesystem::remove(addr.hex() + ".json");
}
m_newLibrariesCreated.clear();
}
15 changes: 7 additions & 8 deletions src/libData/AccountStore/services/evm/EvmClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include "EvmClient.h"
#include <boost/filesystem.hpp>
#include <boost/process/args.hpp>
#include <boost/process/child.hpp>
#include <filesystem>
Expand Down Expand Up @@ -55,24 +54,24 @@ bool LaunchEvmDaemon(boost::process::child& child,
LOG_MARKER();

const std::vector<std::string>& args = GetEvmDaemonArgs();
boost::filesystem::path bin_path(binaryPath);
boost::filesystem::path socket_path(socketPath);
std::filesystem::path bin_path(binaryPath);
std::filesystem::path socket_path(socketPath);
boost::system::error_code ec;

if (boost::filesystem::exists(socket_path)) {
boost::filesystem::remove(socket_path, ec);
if (std::filesystem::exists(socket_path)) {
std::filesystem::remove(socket_path, ec);
if (ec.failed()) {
TRACE_ERROR("Problem removing filesystem entry for socket ");
}
}
if (not boost::filesystem::exists(bin_path)) {
if (not std::filesystem::exists(bin_path)) {
std::stringstream ss;
TRACE_ERROR("Cannot create a subprocess that does not exist " +
EVM_SERVER_BINARY);
return false;
}
boost::process::child c =
boost::process::child(bin_path, boost::process::args(args));
boost::process::child(bin_path.native(), boost::process::args(args));
child = std::move(c);
pid_t thread_id = child.id();
if (thread_id > 0 && child.valid()) {
Expand All @@ -84,7 +83,7 @@ bool LaunchEvmDaemon(boost::process::child& child,
return false;
}
int counter{0};
while (not boost::filesystem::exists(socket_path)) {
while (not std::filesystem::exists(socket_path)) {
if ((counter++ % 10) == 0)
LOG_GENERAL(WARNING, "Awaiting Launch of the evm-ds daemon ");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand Down
7 changes: 3 additions & 4 deletions src/libNode/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/readable_pipe.hpp>
#include <boost/filesystem.hpp>
#include <boost/process/v2/process.hpp>
#include <boost/process/v2/start_dir.hpp>
#include <boost/process/v2/stdio.hpp>
Expand Down Expand Up @@ -1327,7 +1326,7 @@ bool Node::StartRetrieveHistory(const SyncType syncType,
void Node::GetIpMapping(unordered_map<string, Peer> &ipMapping) {
LOG_MARKER();

if (!boost::filesystem::exists(IP_MAPPING_FILE_NAME)) {
if (!std::filesystem::exists(IP_MAPPING_FILE_NAME)) {
LOG_GENERAL(WARNING, IP_MAPPING_FILE_NAME << " not existed!");
return;
}
Expand All @@ -1349,8 +1348,8 @@ void Node::GetIpMapping(unordered_map<string, Peer> &ipMapping) {
void Node::RemoveIpMapping() {
LOG_MARKER();

if (boost::filesystem::exists(IP_MAPPING_FILE_NAME)) {
if (boost::filesystem::remove(IP_MAPPING_FILE_NAME)) {
if (std::filesystem::exists(IP_MAPPING_FILE_NAME)) {
if (std::filesystem::remove(IP_MAPPING_FILE_NAME)) {
LOG_GENERAL(INFO,
IP_MAPPING_FILE_NAME << " has been removed successfully.");
} else {
Expand Down
Loading

0 comments on commit 40791da

Please sign in to comment.