Skip to content
Snippets Groups Projects

Output folder not created when missing

Merged Reinhard Biegel requested to merge 284-output-folder-not-created-when-missing into develop
1 file
+ 42
13
Compare changes
  • Side-by-side
  • Inline
@@ -45,11 +45,19 @@ static void SetupLogging(const std::filesystem::path& executionPath,
LogLevel logLevel,
const std::string& logFileString);
//-----------------------------------------------------------------------------
//! \brief Check several parameters of a directory
//! \param directory
//! \param prefix for readable logging in case of an error
//! \return true, if everything directory exists and really is a directory, false otherwise
//-----------------------------------------------------------------------------
static bool CheckDir(const std::string& directory, const std::string& prefix);
//-----------------------------------------------------------------------------
//! \brief Check several parameters of a readable directory
//! \param directory
//! \param prefix for readable logging in case of an error
//! \return true, if everything is allright
//! \return true, if \c CheckDir returns true and the directory is readable, false otherwise
//-----------------------------------------------------------------------------
static bool CheckReadableDir(const std::string& directory, const std::string& prefix);
@@ -57,7 +65,7 @@ static bool CheckReadableDir(const std::string& directory, const std::string& pr
//! \brief Check several parameters of a writeable directory
//! \param directory
//! \param prefix for readable logging in case of an error
//! \return true, if everything is allright
//! \return true, if \c CheckDir returns true and the directory is writable, false otherwise
//-----------------------------------------------------------------------------
static bool CheckWritableDir(const std::string& directory, const std::string& prefix);
@@ -214,7 +222,6 @@ bool ClearDir(const std::filesystem::path& dir) [[nothrow]]
try
{
fs::create_directory(dir);
for (const auto& entry : fs::directory_iterator(dir))
{
fs::remove_all(entry.path());
@@ -243,6 +250,11 @@ bool PrepareDirectoriesAndLogging(const openpass::core::Directories& directories
// for the case that logFileString is set to the output folder
// itself, preventing proper cleanup of the output folder
if (!std::filesystem::exists(directories.outputDir))
{
std::filesystem::create_directory(directories.outputDir);
}
if (clearResultsPath)
{
if (!ClearDir(directories.outputDir))
@@ -265,32 +277,49 @@ bool PrepareDirectoriesAndLogging(const openpass::core::Directories& directories
return statusConfig && statusLibrary && statusOutput;
}
bool CheckReadableDir(const std::string& directory, const std::string& prefix)
bool CheckDir(const std::string& directory, const std::string& prefix)
{
namespace fs = std::filesystem;
const fs::path dir(directory);
if (!fs::exists(dir) || !fs::is_directory(dir) || access(directory.c_str(), R_OK))
if (!fs::exists(dir))
{
LOG_INTERN(LogLevel::Error) << prefix << " directory " << directory << " does not exist";
return false;
}
if (!fs::is_directory(dir))
{
LOG_INTERN(LogLevel::Error) << prefix << " directory " << directory << " is not a directory";
return false;
}
return true;
}
bool CheckReadableDir(const std::string& directory, const std::string& prefix)
{
CheckDir(directory, prefix);
if (int ret = access(directory.c_str(), R_OK))
{
LOG_INTERN(LogLevel::Error) << prefix << " directory " << directory
<< " does not exist, is not a directory, or is not readable";
LOG_INTERN(LogLevel::Error) << prefix << " directory " << directory << " is not readable (code " << ret << ")";
return false;
}
return true;
}
bool CheckWritableDir(const std::string& directory, const std::string& prefix)
{
namespace fs = std::filesystem;
CheckDir(directory, prefix);
const fs::path dir(directory);
if (!fs::exists(dir) || !fs::is_directory(dir) || access(directory.c_str(), W_OK))
if (int ret = access(directory.c_str(), W_OK))
{
LOG_INTERN(LogLevel::Error) << prefix << " directory " << directory
<< " does not exist, is not a directory, or is not writable";
LOG_INTERN(LogLevel::Error) << prefix << " directory " << directory << " is not writable (code " << ret << ")";
return false;
}
return true;
}
Loading