Common/FileUtil: Use non-throwing overload of is_directory() in CreateDir() and CreateFullPath().

This commit is contained in:
Admiral H. Curtiss 2023-02-22 21:03:23 +01:00
parent e479f92418
commit 884917a6d5
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
1 changed files with 4 additions and 2 deletions

View File

@ -201,7 +201,8 @@ bool CreateDir(const std::string& path)
auto native_path = StringToPath(path); auto native_path = StringToPath(path);
bool success = fs::create_directory(native_path, error); bool success = fs::create_directory(native_path, error);
// If the path was not created, check if it was a pre-existing directory // If the path was not created, check if it was a pre-existing directory
if (!success && fs::is_directory(native_path)) std::error_code error_ignored;
if (!success && fs::is_directory(native_path, error_ignored))
success = true; success = true;
if (!success) if (!success)
ERROR_LOG_FMT(COMMON, "{}: failed on {}: {}", __func__, path, error.message()); ERROR_LOG_FMT(COMMON, "{}: failed on {}: {}", __func__, path, error.message());
@ -232,7 +233,8 @@ bool CreateFullPath(std::string_view fullPath)
auto native_path = StringToPath(fullPath).parent_path(); auto native_path = StringToPath(fullPath).parent_path();
bool success = fs::create_directories(native_path, error); bool success = fs::create_directories(native_path, error);
// If the path was not created, check if it was a pre-existing directory // If the path was not created, check if it was a pre-existing directory
if (!success && fs::is_directory(native_path)) std::error_code error_ignored;
if (!success && fs::is_directory(native_path, error_ignored))
success = true; success = true;
if (!success) if (!success)
ERROR_LOG_FMT(COMMON, "{}: failed on {}: {}", __func__, fullPath, error.message()); ERROR_LOG_FMT(COMMON, "{}: failed on {}: {}", __func__, fullPath, error.message());