summaryrefslogtreecommitdiff
path: root/src/buildtool/file_system/file_system_manager.hpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2022-11-17 15:32:30 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2022-12-21 14:59:04 +0100
commit380e88d8e6863fec8a0209053b529adfb31a9dc0 (patch)
treee9477883d9f67e696cddaf55f3d3bac00774f5bc /src/buildtool/file_system/file_system_manager.hpp
parent49c335ae9ccfdbf8c28cc9b97669ef149801f464 (diff)
downloadjustbuild-380e88d8e6863fec8a0209053b529adfb31a9dc0.tar.gz
FS Manager: Add CopyDirectoryImpl method
Diffstat (limited to 'src/buildtool/file_system/file_system_manager.hpp')
-rw-r--r--src/buildtool/file_system/file_system_manager.hpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp
index c838cd54..9a362474 100644
--- a/src/buildtool/file_system/file_system_manager.hpp
+++ b/src/buildtool/file_system/file_system_manager.hpp
@@ -267,6 +267,42 @@ class FileSystemManager {
return false;
}
+ [[nodiscard]] static auto CopyDirectoryImpl(
+ std::filesystem::path const& src,
+ std::filesystem::path const& dst,
+ bool recursively = false) noexcept -> bool {
+ try {
+ // also checks existence
+ if (not IsDirectory(src)) {
+ Logger::Log(LogLevel::Error,
+ "source {} does not exist or is not a directory",
+ src.string());
+ return false;
+ }
+ // if dst does not exist, it is created, so only check if path
+ // exists but is something else
+ if (Exists(dst) and not IsDirectory(dst)) {
+ Logger::Log(LogLevel::Error,
+ "destination {} exists but it is not a directory",
+ dst.string());
+ return false;
+ }
+ std::filesystem::copy(src,
+ dst,
+ recursively
+ ? std::filesystem::copy_options::recursive
+ : std::filesystem::copy_options::none);
+ return true;
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Error,
+ "copying directory from {} to {}:\n{}",
+ src.string(),
+ dst.string(),
+ e.what());
+ return false;
+ }
+ }
+
[[nodiscard]] static auto RemoveFile(
std::filesystem::path const& file) noexcept -> bool {
try {