mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-26 08:30:30 +00:00
Merge origin/develop: resolve conflicts keeping std::filesystem, update new GTest FileUtilities, remove stale boost::filesystem includes
This commit is contained in:
committed by
GitHub
parent
4b7a21bdfe
commit
3b1e9f2a8a
@@ -1,18 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
=======
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
>>>>>>> origin/develop
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
|
||||
@@ -9,12 +9,9 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <filesystem>
|
||||
=======
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
>>>>>>> origin/develop
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
|
||||
namespace beast {
|
||||
|
||||
<<<<<<< HEAD
|
||||
/** Generate a unique, non-existing path under @p base with an optional @p prefix
|
||||
and a random hex suffix.
|
||||
|
||||
Attempts up to @p maxAttempts paths. Throws `std::runtime_error` if a
|
||||
unique path cannot be found or if the filesystem returns an error while
|
||||
checking for existence.
|
||||
*/
|
||||
/**
|
||||
* Generate a unique, non-existing path under @p base with an optional @p prefix
|
||||
* and a random hex suffix.
|
||||
*
|
||||
* Attempts up to @p maxAttempts paths. Throws `std::runtime_error` if a
|
||||
* unique path cannot be found or if the filesystem returns an error while
|
||||
* checking for existence.
|
||||
*/
|
||||
inline std::filesystem::path
|
||||
uniqueRandomPath(
|
||||
std::filesystem::path const& base,
|
||||
@@ -44,19 +44,12 @@ uniqueRandomPath(
|
||||
throw std::runtime_error("Unable to generate a unique path under '" + base.string() + "'");
|
||||
}
|
||||
|
||||
/** RAII temporary directory.
|
||||
|
||||
The directory and all its contents are deleted when
|
||||
the instance of `TempDir` is destroyed.
|
||||
*/
|
||||
=======
|
||||
/**
|
||||
* RAII temporary directory.
|
||||
*
|
||||
* The directory and all its contents are deleted when
|
||||
* the instance of `temp_dir` is destroyed.
|
||||
* the instance of `TempDir` is destroyed.
|
||||
*/
|
||||
>>>>>>> origin/develop
|
||||
class TempDir
|
||||
{
|
||||
std::filesystem::path path_;
|
||||
|
||||
@@ -6,19 +6,14 @@
|
||||
#include <xrpl/core/StartUpType.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <filesystem>
|
||||
=======
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <soci/statement.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
>>>>>>> origin/develop
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -4,13 +4,9 @@
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
>>>>>>> origin/develop
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
struct SavedState
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#include <test/unit_test/FileDirGuard.h>
|
||||
|
||||
#include <xrpl/basics/ByteUtilities.h>
|
||||
#include <xrpl/basics/FileUtilities.h>
|
||||
#include <xrpl/beast/unit_test/suite.h>
|
||||
|
||||
#include <system_error>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class FileUtilities_test : public beast::unit_test::Suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
testGetFileContents()
|
||||
{
|
||||
using namespace xrpl::detail;
|
||||
|
||||
static constexpr char const* kExpectedContents =
|
||||
"This file is very short. That's all we need.";
|
||||
|
||||
FileDirGuard const file(
|
||||
*this, "test_file", "test.txt", "This is temporary text that should get overwritten");
|
||||
|
||||
std::error_code ec;
|
||||
auto const path = file.file();
|
||||
|
||||
writeFileContents(ec, path, kExpectedContents);
|
||||
BEAST_EXPECT(!ec);
|
||||
|
||||
{
|
||||
// Test with no max
|
||||
auto const good = getFileContents(ec, path);
|
||||
BEAST_EXPECT(!ec);
|
||||
BEAST_EXPECT(good == kExpectedContents);
|
||||
}
|
||||
|
||||
{
|
||||
// Test with large max
|
||||
auto const good = getFileContents(ec, path, kilobytes(1));
|
||||
BEAST_EXPECT(!ec);
|
||||
BEAST_EXPECT(good == kExpectedContents);
|
||||
}
|
||||
|
||||
{
|
||||
// Test with small max
|
||||
auto const bad = getFileContents(ec, path, 16);
|
||||
BEAST_EXPECT(ec && ec == std::errc::file_too_large);
|
||||
BEAST_EXPECT(bad.empty());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testGetFileContents();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(FileUtilities, basics, xrpl);
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <xrpl/rdb/SociDB.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/optional/optional.hpp> // IWYU pragma: keep
|
||||
|
||||
#include <soci/boost-optional.h> // IWYU pragma: keep
|
||||
|
||||
@@ -3,13 +3,8 @@
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/beast/unit_test/suite.h>
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <filesystem>
|
||||
=======
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <exception>
|
||||
>>>>>>> origin/develop
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#include <xrpl/basics/FileUtilities.h>
|
||||
|
||||
#include <xrpl/basics/ByteUtilities.h>
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/system/detail/errc.hpp>
|
||||
#include <boost/system/detail/error_code.hpp>
|
||||
#include <xrpl/beast/utility/temp_dir.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -20,15 +19,16 @@ namespace {
|
||||
class TempFile
|
||||
{
|
||||
public:
|
||||
explicit TempFile(boost::filesystem::path file, std::string const& contents)
|
||||
: dir_(
|
||||
boost::filesystem::temp_directory_path() /
|
||||
boost::filesystem::unique_path("xrpl-file-utilities-%%%%-%%%%-%%%%"))
|
||||
explicit TempFile(std::filesystem::path file, std::string const& contents)
|
||||
: dir_(beast::uniqueRandomPath(
|
||||
std::filesystem::temp_directory_path(),
|
||||
100,
|
||||
"xrpl-file-utilities-"))
|
||||
, file_(dir_ / file)
|
||||
{
|
||||
boost::filesystem::create_directory(dir_);
|
||||
std::filesystem::create_directory(dir_);
|
||||
|
||||
std::ofstream output(file_.string());
|
||||
std::ofstream output(file_);
|
||||
if (!output)
|
||||
throw std::runtime_error("Unable to create temporary test file");
|
||||
|
||||
@@ -37,33 +37,31 @@ public:
|
||||
|
||||
~TempFile()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::remove(file_, ec);
|
||||
boost::filesystem::remove(dir_, ec);
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(file_, ec);
|
||||
std::filesystem::remove(dir_, ec);
|
||||
}
|
||||
|
||||
[[nodiscard]] boost::filesystem::path const&
|
||||
[[nodiscard]] std::filesystem::path const&
|
||||
file() const
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
|
||||
private:
|
||||
boost::filesystem::path dir_;
|
||||
boost::filesystem::path file_;
|
||||
std::filesystem::path dir_;
|
||||
std::filesystem::path file_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(FileUtilitiesTest, get_file_contents)
|
||||
{
|
||||
using namespace boost::system;
|
||||
|
||||
constexpr char const* kExpectedContents = "This file is very short. That's all we need.";
|
||||
|
||||
TempFile const file("test_file", "This is temporary text that should get overwritten");
|
||||
|
||||
error_code ec;
|
||||
std::error_code ec;
|
||||
auto const path = file.file();
|
||||
|
||||
writeFileContents(ec, path, kExpectedContents);
|
||||
@@ -86,7 +84,7 @@ TEST(FileUtilitiesTest, get_file_contents)
|
||||
{
|
||||
// Test with small max
|
||||
auto const bad = getFileContents(ec, path, 16);
|
||||
EXPECT_TRUE(ec && ec.value() == boost::system::errc::file_too_large);
|
||||
EXPECT_TRUE(ec && ec.value() == static_cast<int>(std::errc::file_too_large));
|
||||
EXPECT_TRUE(bad.empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,13 @@
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <filesystem>
|
||||
=======
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
>>>>>>> origin/develop
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
|
||||
@@ -11,13 +11,8 @@
|
||||
#include <xrpl/protocol/XRPAmount.h>
|
||||
#include <xrpl/rdb/DatabaseCon.h>
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include <boost/filesystem.hpp> // VFALCO FIX: This include should not be here
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
>>>>>>> origin/develop
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
@@ -98,15 +93,10 @@ public:
|
||||
static char const* const kDatabaseDirName;
|
||||
static char const* const kValidatorsFileName;
|
||||
|
||||
<<<<<<< HEAD
|
||||
/** Returns the full path and filename of the debug log file. */
|
||||
[[nodiscard]] std::filesystem::path
|
||||
=======
|
||||
/**
|
||||
* Returns the full path and filename of the debug log file.
|
||||
*/
|
||||
[[nodiscard]] boost::filesystem::path
|
||||
>>>>>>> origin/develop
|
||||
[[nodiscard]] std::filesystem::path
|
||||
getDebugLogFile() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -1013,19 +1013,9 @@ Config::loadFromString(std::string const& fileContents)
|
||||
|
||||
if (!validatorsFile.empty())
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
if (!std::filesystem::exists(validatorsFile))
|
||||
{
|
||||
validatorsFile.clear();
|
||||
}
|
||||
else if (
|
||||
!std::filesystem::is_regular_file(validatorsFile) &&
|
||||
!std::filesystem::is_symlink(validatorsFile))
|
||||
=======
|
||||
if (!boost::filesystem::exists(validatorsFile) ||
|
||||
(!boost::filesystem::is_regular_file(validatorsFile) &&
|
||||
!boost::filesystem::is_symlink(validatorsFile)))
|
||||
>>>>>>> origin/develop
|
||||
if (!std::filesystem::exists(validatorsFile) ||
|
||||
(!std::filesystem::is_regular_file(validatorsFile) &&
|
||||
!std::filesystem::is_symlink(validatorsFile)))
|
||||
{
|
||||
validatorsFile.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user