c++17: drop experimental::filesystem
Use the real filesystem library, and drop support for building with
experimental under c++14.
Change-Id: I47cbfc30b223db9dc28e9536ceb84e9fe3342e96
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/Makefile.am b/Makefile.am
index 24ba434..8488bac 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -59,7 +59,6 @@
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
$(SDBUSPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
- -lstdc++fs \
-lssl \
-lcrypto
diff --git a/activation.cpp b/activation.cpp
index e7a6714..8765181 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -11,7 +11,7 @@
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-#include <experimental/filesystem>
+#include <filesystem>
#ifdef WANT_SIGNATURE_VERIFY
#include "image_verify.hpp"
@@ -24,7 +24,6 @@
namespace updater
{
-namespace fs = std::experimental::filesystem;
namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
using namespace phosphor::logging;
@@ -242,7 +241,7 @@
bool Activation::validateSignature(const std::string& pnorFileName)
{
using Signature = openpower::software::image::Signature;
- fs::path imageDir(IMG_DIR);
+ std::filesystem::path imageDir(IMG_DIR);
Signature signature(imageDir / versionId, pnorFileName,
PNOR_SIGNED_IMAGE_CONF_PATH);
diff --git a/image_verify.cpp b/image_verify.cpp
index cf955d7..71bcb58 100644
--- a/image_verify.cpp
+++ b/image_verify.cpp
@@ -31,13 +31,13 @@
constexpr auto keyTypeTag = "KeyType";
constexpr auto hashFunctionTag = "HashType";
-Signature::Signature(const fs::path& imageDirPath,
+Signature::Signature(const std::filesystem::path& imageDirPath,
const std::string& pnorFileName,
- const fs::path& signedConfPath) :
+ const std::filesystem::path& signedConfPath) :
imageDirPath(imageDirPath),
pnorFileName(pnorFileName), signedConfPath(signedConfPath)
{
- fs::path file(imageDirPath / MANIFEST_FILE);
+ std::filesystem::path file(imageDirPath / MANIFEST_FILE);
auto keyValues =
Version::getValue(file, {{keyTypeTag, " "}, {hashFunctionTag, " "}});
@@ -50,7 +50,7 @@
AvailableKeyTypes keyTypes{};
// Find the path of all the files
- if (!fs::is_directory(signedConfPath))
+ if (!std::filesystem::is_directory(signedConfPath))
{
log<level::ERR>("Signed configuration path not found in the system");
elog<InternalFailure>();
@@ -64,7 +64,8 @@
// /etc/activationdata/GA/hashfunc
// Set will have OpenPOWER, GA
- for (const auto& p : fs::recursive_directory_iterator(signedConfPath))
+ for (const auto& p :
+ std::filesystem::recursive_directory_iterator(signedConfPath))
{
if ((p.path().filename() == HASH_FILE_NAME) ||
(p.path().filename() == PUBLICKEY_FILE_NAME))
@@ -81,8 +82,8 @@
inline KeyHashPathPair Signature::getKeyHashFileNames(const Key_t& key) const
{
- fs::path hashpath(signedConfPath / key / HASH_FILE_NAME);
- fs::path keyPath(signedConfPath / key / PUBLICKEY_FILE_NAME);
+ std::filesystem::path hashpath(signedConfPath / key / HASH_FILE_NAME);
+ std::filesystem::path keyPath(signedConfPath / key / PUBLICKEY_FILE_NAME);
return std::make_pair(std::move(hashpath), std::move(keyPath));
}
@@ -100,16 +101,16 @@
}
// image specific publickey file name.
- fs::path publicKeyFile(imageDirPath / PUBLICKEY_FILE_NAME);
+ std::filesystem::path publicKeyFile(imageDirPath / PUBLICKEY_FILE_NAME);
// Validate the PNOR image file.
// Build Image File name
- fs::path file(imageDirPath);
+ std::filesystem::path file(imageDirPath);
file /= pnorFileName;
// Build Signature File name
std::string fileName = file.filename();
- fs::path sigFile(imageDirPath);
+ std::filesystem::path sigFile(imageDirPath);
sigFile /= fileName + SIGNATURE_FILE_EXT;
// Verify the signature.
@@ -147,13 +148,13 @@
}
// Build publickey and its signature file name.
- fs::path pkeyFile(imageDirPath / PUBLICKEY_FILE_NAME);
- fs::path pkeyFileSig(pkeyFile);
+ std::filesystem::path pkeyFile(imageDirPath / PUBLICKEY_FILE_NAME);
+ std::filesystem::path pkeyFileSig(pkeyFile);
pkeyFileSig.replace_extension(SIGNATURE_FILE_EXT);
// Build manifest and its signature file name.
- fs::path manifestFile(imageDirPath / MANIFEST_FILE);
- fs::path manifestFileSig(manifestFile);
+ std::filesystem::path manifestFile(imageDirPath / MANIFEST_FILE);
+ std::filesystem::path manifestFileSig(manifestFile);
manifestFileSig.replace_extension(SIGNATURE_FILE_EXT);
auto valid = false;
@@ -194,13 +195,14 @@
return valid;
}
-bool Signature::verifyFile(const fs::path& file, const fs::path& sigFile,
- const fs::path& publicKey,
+bool Signature::verifyFile(const std::filesystem::path& file,
+ const std::filesystem::path& sigFile,
+ const std::filesystem::path& publicKey,
const std::string& hashFunc)
{
// Check existence of the files in the system.
- if (!(fs::exists(file) && fs::exists(sigFile)))
+ if (!(std::filesystem::exists(file) && std::filesystem::exists(sigFile)))
{
log<level::ERR>("Failed to find the Data or signature file.",
entry("FILE=%s", file.c_str()));
@@ -246,7 +248,7 @@
}
// Hash the data file and update the verification context
- auto size = fs::file_size(file);
+ auto size = std::filesystem::file_size(file);
auto dataPtr = mapFile(file, size);
result = EVP_DigestVerifyUpdate(rsaVerifyCtx.get(), dataPtr(), size);
@@ -258,7 +260,7 @@
}
// Verify the data with signature.
- size = fs::file_size(sigFile);
+ size = std::filesystem::file_size(sigFile);
auto signature = mapFile(sigFile, size);
result = EVP_DigestVerifyFinal(
@@ -282,10 +284,10 @@
return true;
}
-inline RSA* Signature::createPublicRSA(const fs::path& publicKey)
+inline RSA* Signature::createPublicRSA(const std::filesystem::path& publicKey)
{
RSA* rsa = nullptr;
- auto size = fs::file_size(publicKey);
+ auto size = std::filesystem::file_size(publicKey);
// Read public key file
auto data = mapFile(publicKey, size);
@@ -302,7 +304,7 @@
return rsa;
}
-CustomMap Signature::mapFile(const fs::path& path, size_t size)
+CustomMap Signature::mapFile(const std::filesystem::path& path, size_t size)
{
CustomFd fd(open(path.c_str(), O_RDONLY));
diff --git a/image_verify.hpp b/image_verify.hpp
index 3e3f4d4..d909afe 100644
--- a/image_verify.hpp
+++ b/image_verify.hpp
@@ -7,7 +7,7 @@
#include <sys/mman.h>
#include <unistd.h>
-#include <experimental/filesystem>
+#include <filesystem>
#include <set>
#include <string>
@@ -18,11 +18,10 @@
namespace image
{
-namespace fs = std::experimental::filesystem;
using Key_t = std::string;
using Hash_t = std::string;
-using PublicKeyPath = fs::path;
-using HashFilePath = fs::path;
+using PublicKeyPath = std::filesystem::path;
+using HashFilePath = std::filesystem::path;
using KeyHashPathPair = std::pair<HashFilePath, PublicKeyPath>;
using AvailableKeyTypes = std::set<Key_t>;
@@ -129,9 +128,9 @@
* @param[in] signedConfPath - Path of public key
* hash function files
*/
- explicit Signature(const fs::path& imageDirPath,
+ explicit Signature(const std::filesystem::path& imageDirPath,
const std::string& pnorFileName,
- const fs::path& signedConfPath);
+ const std::filesystem::path& signedConfPath);
/**
* @brief Image signature verification function.
@@ -182,15 +181,17 @@
* @param[in] - Hash function name
* @return true if signature verification was successful, false if not
*/
- bool verifyFile(const fs::path& file, const fs::path& signature,
- const fs::path& publicKey, const std::string& hashFunc);
+ bool verifyFile(const std::filesystem::path& file,
+ const std::filesystem::path& signature,
+ const std::filesystem::path& publicKey,
+ const std::string& hashFunc);
/**
* @brief Create RSA object from the public key
* @param[in] - publickey
* @param[out] - RSA Object.
*/
- inline RSA* createPublicRSA(const fs::path& publicKey);
+ inline RSA* createPublicRSA(const std::filesystem::path& publicKey);
/**
* @brief Memory map the file
@@ -198,16 +199,16 @@
* @param[in] - file size
* @param[out] - Custom Mmap address
*/
- CustomMap mapFile(const fs::path& path, size_t size);
+ CustomMap mapFile(const std::filesystem::path& path, size_t size);
/** @brief Directory where software images are placed*/
- fs::path imageDirPath;
+ std::filesystem::path imageDirPath;
/** @brief The PNOR file name in imageDirPath */
std::string pnorFileName;
/** @brief Path of public key and hash function files */
- fs::path signedConfPath;
+ std::filesystem::path signedConfPath;
/** @brief key type defined in mainfest file */
Key_t keyType;
diff --git a/msl_verify.cpp b/msl_verify.cpp
index f80e179..36d4ffe 100644
--- a/msl_verify.cpp
+++ b/msl_verify.cpp
@@ -4,7 +4,7 @@
#include <phosphor-logging/log.hpp>
-#include <experimental/filesystem>
+#include <filesystem>
#include <fstream>
#include <regex>
@@ -15,7 +15,6 @@
namespace image
{
-namespace fs = std::experimental::filesystem;
using namespace phosphor::logging;
using AssociationList =
std::vector<std::tuple<std::string, std::string, std::string>>;
diff --git a/test/Makefile.am b/test/Makefile.am
index 2026535..ed9fefe 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -44,5 +44,3 @@
test_version.cpp \
test_item_updater_static.cpp \
msl_verify.cpp
-
-utest_LDADD = -lstdc++fs
diff --git a/test/test_signature.cpp b/test/test_signature.cpp
index 9e8de4b..f852382 100644
--- a/test/test_signature.cpp
+++ b/test/test_signature.cpp
@@ -2,7 +2,7 @@
#include <openssl/sha.h>
-#include <experimental/filesystem>
+#include <filesystem>
#include <string>
#include <gtest/gtest.h>
@@ -26,7 +26,7 @@
virtual void SetUp()
{
// Create test base directory.
- fs::create_directories(testPath);
+ std::filesystem::create_directories(testPath);
// Create unique temporary path for images.
std::string tmpDir(testPath);
@@ -90,9 +90,9 @@
command("rm -rf " + std::string(testPath));
}
std::unique_ptr<Signature> signature;
- fs::path extractPath;
- fs::path signedConfPath;
- fs::path signedConfPNORPath;
+ std::filesystem::path extractPath;
+ std::filesystem::path signedConfPath;
+ std::filesystem::path signedConfPNORPath;
};
/** @brief Test for success scenario*/
diff --git a/ubi/activation_ubi.cpp b/ubi/activation_ubi.cpp
index 97358e8..946a741 100644
--- a/ubi/activation_ubi.cpp
+++ b/ubi/activation_ubi.cpp
@@ -5,7 +5,7 @@
#include <phosphor-logging/log.hpp>
-#include <experimental/filesystem>
+#include <filesystem>
namespace openpower
{
@@ -13,7 +13,6 @@
{
namespace updater
{
-namespace fs = std::experimental::filesystem;
namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
using namespace phosphor::logging;
@@ -63,9 +62,9 @@
// verify that this happened, we check for the mount dirs PNOR_PRSV
// and PNOR_RW_PREFIX_<versionid>, as well as the image dir R0.
- if ((fs::is_directory(PNOR_PRSV)) &&
- (fs::is_directory(PNOR_RW_PREFIX + versionId)) &&
- (fs::is_directory(PNOR_RO_PREFIX + versionId)))
+ if ((std::filesystem::is_directory(PNOR_PRSV)) &&
+ (std::filesystem::is_directory(PNOR_RW_PREFIX + versionId)) &&
+ (std::filesystem::is_directory(PNOR_RO_PREFIX + versionId)))
{
finishActivation();
if (Activation::checkApplyTimeImmediate())
diff --git a/ubi/item_updater_ubi.cpp b/ubi/item_updater_ubi.cpp
index ee87965..9b8897b 100644
--- a/ubi/item_updater_ubi.cpp
+++ b/ubi/item_updater_ubi.cpp
@@ -12,7 +12,7 @@
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Software/Version/server.hpp>
-#include <experimental/filesystem>
+#include <filesystem>
#include <fstream>
#include <queue>
#include <string>
@@ -26,7 +26,6 @@
// When you see server:: you know we're referencing our base class
namespace server = sdbusplus::xyz::openbmc_project::Software::server;
-namespace fs = std::experimental::filesystem;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace phosphor::logging;
@@ -65,7 +64,7 @@
{
// Read pnor.toc from folders under /media/
// to get Active Software Versions.
- for (const auto& iter : fs::directory_iterator(MEDIA_DIR))
+ for (const auto& iter : std::filesystem::directory_iterator(MEDIA_DIR))
{
auto activationState = server::Activation::Activations::Active;
@@ -80,7 +79,7 @@
// for example /media/pnor-ro-2a1022fe.
auto id = iter.path().native().substr(PNOR_RO_PREFIX_LEN);
auto pnorTOC = iter.path() / PNOR_TOC_FILE;
- if (!fs::is_regular_file(pnorTOC))
+ if (!std::filesystem::is_regular_file(pnorTOC))
{
log<level::ERR>("Failed to read pnorTOC.",
entry("FILENAME=%s", pnorTOC.c_str()));
@@ -106,7 +105,7 @@
}
auto purpose = server::Version::VersionPurpose::Host;
- auto path = fs::path(SOFTWARE_OBJPATH) / id;
+ auto path = std::filesystem::path(SOFTWARE_OBJPATH) / id;
AssociationList associations = {};
if (activationState == server::Activation::Activations::Active)
@@ -157,7 +156,7 @@
{
auto id = iter.path().native().substr(PNOR_RW_PREFIX_LEN);
auto roDir = PNOR_RO_PREFIX + id;
- if (!fs::is_directory(roDir))
+ if (!std::filesystem::is_directory(roDir))
{
log<level::ERR>("No corresponding read-only volume found.",
entry("DIRNAME=%s", roDir.c_str()));
@@ -177,8 +176,8 @@
int ItemUpdaterUbi::validateSquashFSImage(const std::string& filePath)
{
- auto file = fs::path(filePath) / squashFSImage;
- if (fs::is_regular_file(file))
+ auto file = std::filesystem::path(filePath) / squashFSImage;
+ if (std::filesystem::is_regular_file(file))
{
return 0;
}
@@ -216,11 +215,11 @@
utils::hiomapdSuspend(bus);
constexpr static auto patchDir = "/usr/local/share/pnor";
- if (fs::is_directory(patchDir))
+ if (std::filesystem::is_directory(patchDir))
{
- for (const auto& iter : fs::directory_iterator(patchDir))
+ for (const auto& iter : std::filesystem::directory_iterator(patchDir))
{
- fs::remove_all(iter);
+ std::filesystem::remove_all(iter);
}
}
@@ -228,21 +227,21 @@
for (const auto& it : activations)
{
auto rwDir = PNOR_RW_PREFIX + it.first;
- if (fs::is_directory(rwDir))
+ if (std::filesystem::is_directory(rwDir))
{
- for (const auto& iter : fs::directory_iterator(rwDir))
+ for (const auto& iter : std::filesystem::directory_iterator(rwDir))
{
- fs::remove_all(iter);
+ std::filesystem::remove_all(iter);
}
}
}
// Clear the preserved partition.
- if (fs::is_directory(PNOR_PRSV))
+ if (std::filesystem::is_directory(PNOR_PRSV))
{
- for (const auto& iter : fs::directory_iterator(PNOR_PRSV))
+ for (const auto& iter : std::filesystem::directory_iterator(PNOR_PRSV))
{
- fs::remove_all(iter);
+ std::filesystem::remove_all(iter);
}
}
@@ -251,14 +250,15 @@
bool ItemUpdaterUbi::isVersionFunctional(const std::string& versionId)
{
- if (!fs::exists(PNOR_RO_ACTIVE_PATH))
+ if (!std::filesystem::exists(PNOR_RO_ACTIVE_PATH))
{
return false;
}
- fs::path activeRO = fs::read_symlink(PNOR_RO_ACTIVE_PATH);
+ std::filesystem::path activeRO =
+ std::filesystem::read_symlink(PNOR_RO_ACTIVE_PATH);
- if (!fs::is_directory(activeRO))
+ if (!std::filesystem::is_directory(activeRO))
{
return false;
}
@@ -393,15 +393,15 @@
std::string ItemUpdaterUbi::determineId(const std::string& symlinkPath)
{
- if (!fs::exists(symlinkPath))
+ if (!std::filesystem::exists(symlinkPath))
{
return {};
}
- auto target = fs::canonical(symlinkPath).string();
+ auto target = std::filesystem::canonical(symlinkPath).string();
// check to make sure the target really exists
- if (!fs::is_regular_file(target + "/" + PNOR_TOC_FILE))
+ if (!std::filesystem::is_regular_file(target + "/" + PNOR_TOC_FILE))
{
return {};
}
@@ -415,14 +415,14 @@
{
// The GARD partition is currently misspelled "GUARD." This file path will
// need to be updated in the future.
- auto path = fs::path(PNOR_PRSV_ACTIVE_PATH);
+ auto path = std::filesystem::path(PNOR_PRSV_ACTIVE_PATH);
path /= "GUARD";
utils::hiomapdSuspend(bus);
- if (fs::is_regular_file(path))
+ if (std::filesystem::is_regular_file(path))
{
- fs::remove(path);
+ std::filesystem::remove(path);
}
utils::hiomapdResume(bus);
diff --git a/ubi/serialize.cpp b/ubi/serialize.cpp
index e047b87..2c31638 100644
--- a/ubi/serialize.cpp
+++ b/ubi/serialize.cpp
@@ -5,7 +5,7 @@
#include <cereal/archives/json.hpp>
#include <sdbusplus/server.hpp>
-#include <experimental/filesystem>
+#include <filesystem>
#include <fstream>
namespace openpower
@@ -15,15 +15,13 @@
namespace updater
{
-namespace fs = std::experimental::filesystem;
-
void storeToFile(const std::string& versionId, uint8_t priority)
{
auto bus = sdbusplus::bus::new_default();
- if (!fs::is_directory(PERSIST_DIR))
+ if (!std::filesystem::is_directory(PERSIST_DIR))
{
- fs::create_directories(PERSIST_DIR);
+ std::filesystem::create_directories(PERSIST_DIR);
}
// store one copy in /var/lib/obmc/openpower-pnor-code-mgmt/[versionId]
@@ -32,7 +30,7 @@
cereal::JSONOutputArchive varArchive(varOutput);
varArchive(cereal::make_nvp("priority", priority));
- if (fs::is_directory(PNOR_RW_PREFIX + versionId))
+ if (std::filesystem::is_directory(PNOR_RW_PREFIX + versionId))
{
// store another copy in /media/pnor-rw-[versionId]/[versionId]
auto rwPath = PNOR_RW_PREFIX + versionId + "/" + versionId;
@@ -53,7 +51,7 @@
bool restoreFromFile(const std::string& versionId, uint8_t& priority)
{
auto varPath = PERSIST_DIR + versionId;
- if (fs::exists(varPath))
+ if (std::filesystem::exists(varPath))
{
std::ifstream varInput(varPath.c_str(), std::ios::in);
try
@@ -64,12 +62,12 @@
}
catch (cereal::RapidJSONException& e)
{
- fs::remove(varPath);
+ std::filesystem::remove(varPath);
}
}
auto rwPath = PNOR_RW_PREFIX + versionId + "/" + versionId;
- if (fs::exists(rwPath))
+ if (std::filesystem::exists(rwPath))
{
std::ifstream rwInput(rwPath.c_str(), std::ios::in);
try
@@ -80,7 +78,7 @@
}
catch (cereal::RapidJSONException& e)
{
- fs::remove(rwPath);
+ std::filesystem::remove(rwPath);
}
}
@@ -88,7 +86,7 @@
{
std::string devicePath = "/dev/mtd/u-boot-env";
- if (fs::exists(devicePath) && !devicePath.empty())
+ if (std::filesystem::exists(devicePath) && !devicePath.empty())
{
std::ifstream input(devicePath.c_str());
std::string envVars;
@@ -130,9 +128,9 @@
// so the file /media/pnor-rw-[versionId]/[versionId] will also be deleted
// along with its surrounding directory.
std::string path = PERSIST_DIR + versionId;
- if (fs::exists(path))
+ if (std::filesystem::exists(path))
{
- fs::remove(path);
+ std::filesystem::remove(path);
}
}
diff --git a/ubi/watch.cpp b/ubi/watch.cpp
index fd2cad2..9cbed5d 100644
--- a/ubi/watch.cpp
+++ b/ubi/watch.cpp
@@ -11,7 +11,7 @@
#include <cstddef>
#include <cstring>
-#include <experimental/filesystem>
+#include <filesystem>
#include <functional>
#include <stdexcept>
#include <string>
@@ -24,7 +24,6 @@
{
using namespace phosphor::logging;
-namespace fs = std::experimental::filesystem;
Watch::Watch(sd_event* loop,
std::function<void(const std::string&)> functionalCallback) :
@@ -33,9 +32,9 @@
{
// Create PNOR_ACTIVE_PATH if doesn't exist.
- if (!fs::is_directory(PNOR_ACTIVE_PATH))
+ if (!std::filesystem::is_directory(PNOR_ACTIVE_PATH))
{
- fs::create_directories(PNOR_ACTIVE_PATH);
+ std::filesystem::create_directories(PNOR_ACTIVE_PATH);
}
wd = inotify_add_watch(fd(), PNOR_ACTIVE_PATH, IN_CREATE);
@@ -90,9 +89,9 @@
auto event = reinterpret_cast<inotify_event*>(&buffer[offset]);
// Update the functional association on a RO
// active image symlink change
- fs::path path(PNOR_ACTIVE_PATH);
+ std::filesystem::path path(PNOR_ACTIVE_PATH);
path /= event->name;
- if (fs::equivalent(path, PNOR_RO_ACTIVE_PATH))
+ if (std::filesystem::equivalent(path, PNOR_RO_ACTIVE_PATH))
{
auto id = ItemUpdaterUbi::determineId(path);
static_cast<Watch*>(userdata)->functionalCallback(id);