summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-02-22 02:31:06 +0100
committerAdmiral H. Curtiss <pikachu025@gmail.com>2023-02-24 20:32:18 +0100
commite479f9241829130d9a23b12eea2b1142b6e2f282 (patch)
treea42d6737a6366d26168c80b09583d82fd03bb000 /Source/Core/Common/FileUtil.cpp
parent616d57e7fc9fd294f29f9d76874bd2afe745728e (diff)
Common/FileUtil: Add CreateDirs() function as a wrapper around std::filesystem::create_directories().
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
-rw-r--r--Source/Core/Common/FileUtil.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index e7e3e033aa..454277f55a 100644
--- a/Source/Core/Common/FileUtil.cpp
+++ b/Source/Core/Common/FileUtil.cpp
@@ -193,7 +193,6 @@ bool Delete(const std::string& filename, IfAbsentBehavior behavior)
return true;
}
-// Returns true if successful, or path already exists.
bool CreateDir(const std::string& path)
{
DEBUG_LOG_FMT(COMMON, "{}: directory {}", __func__, path);
@@ -209,6 +208,22 @@ bool CreateDir(const std::string& path)
return success;
}
+bool CreateDirs(std::string_view path)
+{
+ DEBUG_LOG_FMT(COMMON, "{}: directory {}", __func__, path);
+
+ std::error_code error;
+ auto native_path = StringToPath(path);
+ bool success = fs::create_directories(native_path, error);
+ // If the path was not created, check if it was a pre-existing directory
+ std::error_code error_ignored;
+ if (!success && fs::is_directory(native_path, error_ignored))
+ success = true;
+ if (!success)
+ ERROR_LOG_FMT(COMMON, "{}: failed on {}: {}", __func__, path, error.message());
+ return success;
+}
+
bool CreateFullPath(std::string_view fullPath)
{
DEBUG_LOG_FMT(COMMON, "{}: path {}", __func__, fullPath);