From 7c34877630a62e8f0e29ae7a623cc74c6995897d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 6 Sep 2019 11:48:07 +0200 Subject: [PATCH] Ensure output dir exists before creating log streams. --- flow/flow.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/flow/flow.cpp b/flow/flow.cpp index b05d069c5..7bb60f638 100644 --- a/flow/flow.cpp +++ b/flow/flow.cpp @@ -53,6 +53,8 @@ #include +#include + #if HAVE_DUNE_FEM #include #else @@ -127,10 +129,26 @@ enum class FileOutputMode { +void ensureOutputDirExists(const std::string& cmdline_output_dir) +{ + if (!boost::filesystem::is_directory(cmdline_output_dir)) { + try { + boost::filesystem::create_directories(cmdline_output_dir); + } + catch (...) { + throw std::runtime_error("Creation of output directory '" + cmdline_output_dir + "' failed\n"); + } + } +} // Setup the OpmLog backends FileOutputMode setupLogging(int mpi_rank_, const std::string& deck_filename, const std::string& cmdline_output_dir, const std::string& cmdline_output, bool output_cout_, const std::string& stdout_log_id) { + + if (!cmdline_output_dir.empty()) { + ensureOutputDirExists(cmdline_output_dir); + } + // create logFile using boost::filesystem::path; path fpath(deck_filename);