Use ensureDirectoryExists() instead of boost::filesystem directly.

Motivated by
 - proliferation of identical code
 - need to avoid strange behaviour with "." directory on some boost versions
 - potenial for further refactoring to avoid boost entirely
This commit is contained in:
Atgeirr Flø Rasmussen
2017-04-06 12:14:54 +02:00
parent d267c1a77d
commit 85e1544553
15 changed files with 53 additions and 216 deletions

View File

@@ -53,6 +53,8 @@
#include <opm/polymer/PolymerProperties.hpp>
#include <opm/polymer/polymerUtilities.hpp>
#include <opm/simulators/ensureDirectoryExists.hpp>
#include <boost/filesystem.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/lexical_cast.hpp>
@@ -200,13 +202,7 @@ namespace Opm
output_vtk_ = param.getDefault("output_vtk", true);
output_dir_ = param.getDefault("output_dir", std::string("output"));
// Ensure that output dir exists
boost::filesystem::path fpath(output_dir_);
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
ensureDirectoryExists(output_dir_);
output_interval_ = param.getDefault("output_interval", 1);
}
@@ -525,13 +521,7 @@ namespace Opm
// Write data in VTK format.
std::ostringstream vtkfilename;
vtkfilename << output_dir << "/vtk_files";
boost::filesystem::path fpath(vtkfilename.str());
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
ensureDirectoryExists(vtkfilename.str());
vtkfilename << "/output-" << std::setw(5) << std::setfill('0') << step << ".vtu";
std::ofstream vtkfile(vtkfilename.str().c_str());
if (!vtkfile) {
@@ -568,13 +558,7 @@ namespace Opm
for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) {
std::ostringstream fname;
fname << output_dir << "/" << it->first;
boost::filesystem::path fpath = fname.str();
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
ensureDirectoryExists(fname.str());
fname << "/" << std::setw(5) << std::setfill('0') << step << ".txt";
std::ofstream file(fname.str().c_str());
if (!file) {

View File

@@ -55,6 +55,8 @@
#include <opm/polymer/PolymerProperties.hpp>
#include <opm/polymer/polymerUtilities.hpp>
#include <opm/simulators/ensureDirectoryExists.hpp>
#include <boost/filesystem.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/lexical_cast.hpp>
@@ -211,13 +213,7 @@ namespace Opm
output_vtk_ = param.getDefault("output_vtk", true);
output_dir_ = param.getDefault("output_dir", std::string("output"));
// Ensure that output dir exists
boost::filesystem::path fpath(output_dir_);
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
ensureDirectoryExists(output_dir_);
output_interval_ = param.getDefault("output_interval", 1);
}
@@ -525,13 +521,7 @@ namespace Opm
// Write data in VTK format.
std::ostringstream vtkfilename;
vtkfilename << output_dir << "/vtk_files";
boost::filesystem::path fpath(vtkfilename.str());
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
ensureDirectoryExists(vtkfilename.str());
vtkfilename << "/output-" << std::setw(5) << std::setfill('0') << step << ".vtu";
std::ofstream vtkfile(vtkfilename.str().c_str());
if (!vtkfile) {
@@ -566,13 +556,7 @@ namespace Opm
for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) {
std::ostringstream fname;
fname << output_dir << "/" << it->first;
boost::filesystem::path fpath = fname.str();
try {
create_directories(fpath);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
}
ensureDirectoryExists(fname.str());
fname << "/" << std::setw(5) << std::setfill('0') << step << ".txt";
std::ofstream file(fname.str().c_str());
if (!file) {