From a2cfbd74ec22cf283c2d392699b877d8cb3d74ac Mon Sep 17 00:00:00 2001 From: kssenii Date: Fri, 7 May 2021 22:00:36 +0300 Subject: [PATCH] Fix fs::copy to work the same as Poco::copy --- src/Disks/DiskLocal.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Disks/DiskLocal.cpp b/src/Disks/DiskLocal.cpp index 85023dba464..7c192f70cd2 100644 --- a/src/Disks/DiskLocal.cpp +++ b/src/Disks/DiskLocal.cpp @@ -309,7 +309,15 @@ bool inline isSameDiskType(const IDisk & one, const IDisk & another) void DiskLocal::copy(const String & from_path, const std::shared_ptr & to_disk, const String & to_path) { if (isSameDiskType(*this, *to_disk)) - fs::copy(fs::path(disk_path) / from_path, fs::path(to_disk->getPath()) / to_path); /// Use more optimal way. + { + fs::path from = fs::path(disk_path) / from_path; + if (from_path.ends_with('/')) + from = (fs::path(disk_path) / from_path.substr(0, from_path.size() - 1)).parent_path(); + else if (fs::is_directory(from)) + from = from.parent_path(); + + fs::copy(from, fs::path(to_disk->getPath()) / to_path, fs::copy_options::recursive | fs::copy_options::overwrite_existing); /// Use more optimal way. + } else IDisk::copy(from_path, to_disk, to_path); /// Copy files through buffers. }