use std::filesystem directly

This commit is contained in:
Arne Morten Kvarving 2021-11-01 12:31:40 +01:00
parent 1a80378b0a
commit 06bd25575f
9 changed files with 29 additions and 24 deletions

View File

@ -25,7 +25,6 @@
#include <ebos/eclgenericvanguard.hh>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/utility/FileSystem.hpp>
#include <opm/common/utility/TimeService.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquiferCell.hpp>
@ -49,6 +48,7 @@
#include <mpi.h>
#endif // HAVE_MPI
#include <filesystem>
#include <stdexcept>
namespace Opm {
@ -144,18 +144,18 @@ void EclGenericVanguard::setExternalWTestState(std::unique_ptr<WellTestState> wt
std::string EclGenericVanguard::canonicalDeckPath(const std::string& caseName)
{
const auto fileExists = [](const filesystem::path& f) -> bool
const auto fileExists = [](const std::filesystem::path& f) -> bool
{
if (!filesystem::exists(f))
if (!std::filesystem::exists(f))
return false;
if (filesystem::is_regular_file(f))
if (std::filesystem::is_regular_file(f))
return true;
return filesystem::is_symlink(f) && filesystem::is_regular_file(filesystem::read_symlink(f));
return std::filesystem::is_symlink(f) && std::filesystem::is_regular_file(std::filesystem::read_symlink(f));
};
auto simcase = filesystem::path(caseName);
auto simcase = std::filesystem::path(caseName);
if (fileExists(simcase))
return simcase.string();
@ -213,9 +213,9 @@ void EclGenericVanguard::updateOutputDir_(std::string outputDir,
outputDir = ioConfig.getOutputDir();
// ensure that the output directory exists and that it is a directory
if (!filesystem::is_directory(outputDir)) {
if (!std::filesystem::is_directory(outputDir)) {
try {
filesystem::create_directories(outputDir);
std::filesystem::create_directories(outputDir);
}
catch (...) {
throw std::runtime_error("Creation of output directory '"+outputDir+"' failed\n");

View File

@ -29,6 +29,8 @@
#include <dune/common/parallel/mpihelper.hh>
#endif
#include <filesystem>
namespace Opm {
namespace Properties {
namespace TTag {

View File

@ -37,6 +37,7 @@
#include <opm/common/utility/String.hpp>
#include <fmt/format.h>
#include <filesystem>
#if HAVE_DUNE_FEM
#include <dune/fem/misc/mpimanager.hh>
@ -466,7 +467,7 @@ namespace Opm
return;
}
namespace fs = ::Opm::filesystem;
namespace fs = ::std::filesystem;
const std::string& output_dir = eclState().getIOConfig().getOutputDir();
fs::path output_path(output_dir);
fs::path deck_filename(EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName));
@ -578,7 +579,7 @@ namespace Opm
report.reportFullyImplicit(ss);
OpmLog::info(ss.str());
const std::string dir = eclState().getIOConfig().getOutputDir();
namespace fs = ::Opm::filesystem;
namespace fs = ::std::filesystem;
fs::path output_dir(dir);
{
std::string filename = eclState().getIOConfig().getBaseName() + ".INFOSTEP";

View File

@ -69,6 +69,7 @@
#include <cassert>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <memory>
#include <stdexcept>
@ -496,9 +497,9 @@ namespace Opm
return true;
}
filesystem::path simulationCaseName_(const std::string& casename)
std::filesystem::path simulationCaseName_(const std::string& casename)
{
namespace fs = ::Opm::filesystem;
namespace fs = ::std::filesystem;
auto exists = [](const fs::path& f)
{

View File

@ -23,6 +23,8 @@
#include <dune/istl/matrixmarket.hh>
#include <opm/simulators/linalg/MatrixMarketSpecializations.hpp>
#include <filesystem>
namespace Opm
{
@ -40,7 +42,7 @@ namespace Helper
} else if (!dir.empty() && dir.back() != '/') {
dir += "/";
}
namespace fs = ::Opm::filesystem;
namespace fs = ::std::filesystem;
fs::path output_dir(dir);
fs::path subdir("reports");
output_dir = output_dir / subdir;

View File

@ -21,8 +21,7 @@
#include <opm/simulators/linalg/setupPropertyTree.hpp>
#include <opm/common/utility/FileSystem.hpp>
#include <filesystem>
#include <boost/version.hpp>
namespace Opm
@ -43,7 +42,7 @@ setupPropertyTree(FlowLinearSolverParameters p, // Note: copying the parameters
// Get configuration from file.
if (conf.size() > 5 && conf.substr(conf.size() - 5, 5) == ".json") { // the ends_with() method is not available until C++20
#if BOOST_VERSION / 100 % 1000 > 48
if ( !filesystem::exists(conf) ) {
if ( !std::filesystem::exists(conf) ) {
OPM_THROW(std::invalid_argument, "JSON file " << conf << " does not exist.");
}
try {

View File

@ -21,20 +21,19 @@
#ifndef OPM_PARALLELFILEMERGER_HEADER_INCLUDED
#define OPM_PARALLELFILEMERGER_HEADER_INCLUDED
#include <filesystem>
#include <fstream>
#include <memory>
#include <regex>
#include <string>
#include <opm/common/utility/FileSystem.hpp>
namespace Opm
{
namespace detail
{
namespace fs = ::Opm::filesystem;
namespace fs = ::std::filesystem;
/// \brief A functor that merges multiple files of a parallel run to one file.
///

View File

@ -31,7 +31,6 @@
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/OpmLog/EclipsePRTLog.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/utility/FileSystem.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/common/utility/String.hpp>
@ -66,6 +65,7 @@
#include <cstdlib>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <memory>
#include <sstream>
@ -93,7 +93,7 @@ namespace {
void ensureOutputDirExists_(const std::string& cmdline_output_dir)
{
namespace fs = Opm::filesystem;
namespace fs = std::filesystem;
if (! fs::is_directory(cmdline_output_dir)) {
try {
@ -350,7 +350,7 @@ Opm::setupLogging(const int mpi_rank_,
}
// create logFile
using Opm::filesystem::path;
using std::filesystem::path;
path fpath(deck_filename);
std::string baseName;
std::ostringstream debugFileStream;
@ -369,7 +369,7 @@ Opm::setupLogging(const int mpi_rank_,
if (output_dir.empty()) {
output_dir = fpath.has_parent_path()
? absolute(fpath.parent_path()).generic_string()
: Opm::filesystem::current_path().generic_string();
: std::filesystem::current_path().generic_string();
}
logFileStream << output_dir << "/" << baseName;

View File

@ -23,6 +23,7 @@
#define BOOST_TEST_MODULE VFPTest
#include <algorithm>
#include <filesystem>
#include <memory>
#include <map>
#include <sstream>
@ -645,7 +646,7 @@ BOOST_AUTO_TEST_CASE(ParseInterpolateRealisticVFPPROD)
auto units = Opm::UnitSystem::newMETRIC();
Opm::Parser parser;
Opm::filesystem::path file("VFPPROD2");
std::filesystem::path file("VFPPROD2");
auto deck = parser.parseFile(file.string());