Skip to content

Commit

Permalink
Switch to std::filesystem
Browse files Browse the repository at this point in the history
Change-Id: I61a4b4562b3c7fabefb07dced580d2b20d7b6d78
  • Loading branch information
Pesa committed Dec 14, 2024
1 parent 85bde92 commit cde062e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
1 change: 0 additions & 1 deletion .jenkins.d/00-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ APT_PKGS=(
libboost-chrono-dev
libboost-date-time-dev
libboost-dev
libboost-filesystem-dev
libboost-log-dev
libboost-program-options-dev
libboost-stacktrace-dev
Expand Down
2 changes: 1 addition & 1 deletion .waf-tools/default-compiler-flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def getDebugFlags(self, conf):
return {
'CXXFLAGS': [],
'LINKFLAGS': [],
'DEFINES': ['BOOST_ASIO_NO_DEPRECATED', 'BOOST_FILESYSTEM_NO_DEPRECATED'],
'DEFINES': ['BOOST_ASIO_NO_DEPRECATED'],
}

def getOptimizedFlags(self, conf):
Expand Down
14 changes: 7 additions & 7 deletions src/detail/ca-sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include <ndn-cxx/security/validation-policy.hpp>
#include <ndn-cxx/util/sqlite3-statement.hpp>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/property_tree/json_parser.hpp>

#include <filesystem>

namespace ndncert::ca {

using ndn::util::Sqlite3Statement;
Expand Down Expand Up @@ -80,21 +80,21 @@ CaSqlite::CaSqlite(const Name& caName, const std::string& path)
: CaStorage()
{
// Determine the path of sqlite db
boost::filesystem::path dbDir;
std::filesystem::path dbDir;
if (!path.empty()) {
dbDir = boost::filesystem::path(path);
dbDir = std::filesystem::path(path);
}
else {
std::string dbName = caName.toUri();
std::replace(dbName.begin(), dbName.end(), '/', '_');
dbName += ".db";
if (getenv("HOME") != nullptr) {
dbDir = boost::filesystem::path(getenv("HOME")) / ".ndncert";
dbDir = std::filesystem::path(getenv("HOME")) / ".ndncert";
}
else {
dbDir = boost::filesystem::current_path() / ".ndncert";
dbDir = std::filesystem::current_path() / ".ndncert";
}
boost::filesystem::create_directories(dbDir);
std::filesystem::create_directories(dbDir);
dbDir /= dbName;
}

Expand Down
15 changes: 7 additions & 8 deletions tests/global-configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

#include <ndn-cxx/util/exception.hpp>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

#include <filesystem>
#include <stdexcept>
#include <stdlib.h>
#include <system_error>

namespace ndncert::tests {

Expand All @@ -40,10 +39,10 @@ class GlobalConfiguration
m_home.assign(envHome);

// in case an earlier test run crashed without a chance to run the destructor
boost::filesystem::remove_all(TESTDIR);
std::filesystem::remove_all(TESTDIR);

auto testHome = TESTDIR / "test-home";
boost::filesystem::create_directories(testHome);
std::filesystem::create_directories(testHome);

if (::setenv("HOME", testHome.c_str(), 1) != 0)
NDN_THROW(std::runtime_error("setenv() failed"));
Expand All @@ -56,12 +55,12 @@ class GlobalConfiguration
else
::setenv("HOME", m_home.data(), 1);

boost::system::error_code ec;
boost::filesystem::remove_all(TESTDIR, ec); // ignore error
std::error_code ec;
std::filesystem::remove_all(TESTDIR, ec); // ignore error
}

private:
static inline const boost::filesystem::path TESTDIR{UNIT_TESTS_TMPDIR};
static inline const std::filesystem::path TESTDIR{UNIT_TESTS_TMPDIR};
std::string m_home;
};

Expand Down
18 changes: 8 additions & 10 deletions tests/unit-tests/ca-sqlite.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -23,8 +23,8 @@
#include "tests/boost-test.hpp"
#include "tests/key-chain-fixture.hpp"

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <filesystem>
#include <system_error>

namespace ndncert::tests {

Expand All @@ -34,21 +34,19 @@ class DatabaseFixture : public KeyChainFixture
{
public:
DatabaseFixture()
: dbDir(std::filesystem::path{UNIT_TESTS_TMPDIR} / "test-home" / ".ndncert")
{
boost::filesystem::path parentDir{UNIT_TESTS_TMPDIR};
dbDir = parentDir / "test-home" / ".ndncert";
if (!boost::filesystem::exists(dbDir)) {
boost::filesystem::create_directory(dbDir);
}
std::filesystem::create_directory(dbDir);
}

~DatabaseFixture()
{
boost::filesystem::remove_all(dbDir);
std::error_code ec;
std::filesystem::remove_all(dbDir, ec); // ignore error
}

protected:
boost::filesystem::path dbDir;
std::filesystem::path dbDir;
};

BOOST_FIXTURE_TEST_SUITE(TestCaSqlite, DatabaseFixture)
Expand Down
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def configure(conf):
conf.check_sqlite3()
conf.check_openssl(lib='crypto', atleast_version='1.1.1')

conf.check_boost(lib='filesystem', mt=True)
conf.check_boost()
if conf.env.BOOST_VERSION_NUMBER < 107100:
conf.fatal('The minimum supported version of Boost is 1.71.0.\n'
'Please upgrade your distribution or manually install a newer version of Boost.\n'
Expand Down

0 comments on commit cde062e

Please sign in to comment.