summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-02-22 02:17:11 +0100
committerAdmiral H. Curtiss <pikachu025@gmail.com>2023-02-24 20:32:18 +0100
commit616d57e7fc9fd294f29f9d76874bd2afe745728e (patch)
tree8e08804382a08186ad6da3b0027ec902d60bdd4d /Source/Core/Common/FileUtil.cpp
parent88fc431dce1d422cc02215d62e544b67476504ad (diff)
Common/FileUtil: Add Copy() function as a wrapper around std::filesystem::copy().
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
-rw-r--r--Source/Core/Common/FileUtil.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index 0d4288c609..e7e3e033aa 100644
--- a/Source/Core/Common/FileUtil.cpp
+++ b/Source/Core/Common/FileUtil.cpp
@@ -516,6 +516,31 @@ bool DeleteDirRecursively(const std::string& directory)
return success;
}
+bool Copy(std::string_view source_path, std::string_view dest_path, bool overwrite_existing)
+{
+ DEBUG_LOG_FMT(COMMON, "{}: {} --> {} ({})", __func__, source_path, dest_path,
+ overwrite_existing ? "overwrite" : "preserve");
+
+ auto src_path = StringToPath(source_path);
+ auto dst_path = StringToPath(dest_path);
+ std::error_code error;
+ auto options = fs::copy_options::recursive;
+ if (overwrite_existing)
+ options |= fs::copy_options::overwrite_existing;
+ fs::copy(src_path, dst_path, options, error);
+ if (error)
+ {
+ std::error_code error_ignored;
+ if (fs::equivalent(src_path, dst_path, error_ignored))
+ return true;
+
+ ERROR_LOG_FMT(COMMON, "{}: failed {} --> {} ({}): {}", __func__, source_path, dest_path,
+ overwrite_existing ? "overwrite" : "preserve", error.message());
+ return false;
+ }
+ return true;
+}
+
// Create directory and copy contents (optionally overwrites existing files)
bool CopyDir(const std::string& source_path, const std::string& dest_path, const bool destructive)
{