Skip to content

Commit

Permalink
refactor: Remove boost filesystem (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterChen13579 authored Jan 29, 2025
1 parent 73f375f commit 7c27420
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
5 changes: 2 additions & 3 deletions src/util/newconfig/ConfigFileJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
#include <cstddef>
#include <cstdint>
#include <exception>
#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -82,7 +81,7 @@ ConfigFileJson::ConfigFileJson(boost::json::object jsonObj)
}

std::expected<ConfigFileJson, Error>
ConfigFileJson::makeConfigFileJson(boost::filesystem::path configFilePath)
ConfigFileJson::makeConfigFileJson(std::filesystem::path const& configFilePath)
{
try {
if (auto const in = std::ifstream(configFilePath.string(), std::ios::in | std::ios::binary); in) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/newconfig/ConfigFileJson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include "util/newconfig/Error.hpp"
#include "util/newconfig/Types.hpp"

#include <boost/filesystem/path.hpp>
#include <boost/json/object.hpp>

#include <expected>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -79,7 +79,7 @@ class ConfigFileJson final : public ConfigFileInterface {
* @return A ConfigFileJson object if parsing user file is successful. Error otherwise
*/
[[nodiscard]] static std::expected<ConfigFileJson, Error>
makeConfigFileJson(boost::filesystem::path configFilePath);
makeConfigFileJson(std::filesystem::path const& configFilePath);

private:
/**
Expand Down
31 changes: 2 additions & 29 deletions tests/unit/ConfigTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "util/Assert.hpp"
#include "util/LoggerFixtures.hpp"
#include "util/TmpFile.hpp"
#include "util/config/Config.hpp"

#include <boost/filesystem/operations.hpp>
Expand All @@ -29,8 +30,6 @@
#include <gtest/gtest.h>

#include <cstdint>
#include <cstdio>
#include <fstream>
#include <optional>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -236,36 +235,10 @@ TEST_F(ConfigTest, Extend)
ASSERT_EQ(custom.c, true);
}

/**
* @brief Simple temporary file util
*/
class TmpFile {
public:
TmpFile(std::string const& data) : tmpPath_{boost::filesystem::unique_path().string()}
{
std::ofstream of;
of.open(tmpPath_);
of << data;
of.close();
}
~TmpFile()
{
std::remove(tmpPath_.c_str());
}
std::string
path() const
{
return tmpPath_;
}

private:
std::string tmpPath_;
};

TEST_F(ConfigTest, File)
{
auto tmp = TmpFile(kJSON_DATA);
auto conf = ConfigReader::open(tmp.path());
auto conf = ConfigReader::open(tmp.path);

ASSERT_EQ(conf.value<int64_t>("top"), 420);

Expand Down

0 comments on commit 7c27420

Please sign in to comment.