From 4366fcbc83ee3d6536148aed2cdccc8eac4c8004 Mon Sep 17 00:00:00 2001 From: LiuYangkuan Date: Fri, 12 Nov 2021 19:42:25 +0800 Subject: [PATCH] fix build check and make rename robust in DiskS3::restoreFileOperations --- src/Disks/DiskLocal.cpp | 6 +++--- src/Disks/S3/DiskS3.cpp | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Disks/DiskLocal.cpp b/src/Disks/DiskLocal.cpp index bde884f2146..a190fd47892 100644 --- a/src/Disks/DiskLocal.cpp +++ b/src/Disks/DiskLocal.cpp @@ -106,11 +106,11 @@ private: }; -class DiskLocalDirectoryIterator : public IDiskDirectoryIterator +class DiskLocalDirectoryIterator final : public IDiskDirectoryIterator { public: - DiskLocalDirectoryIterator() {} - explicit DiskLocalDirectoryIterator(const String & disk_path_, const String & dir_path_) + DiskLocalDirectoryIterator() { } + DiskLocalDirectoryIterator(const String & disk_path_, const String & dir_path_) : dir_path(dir_path_), entry(fs::path(disk_path_) / dir_path_) { } diff --git a/src/Disks/S3/DiskS3.cpp b/src/Disks/S3/DiskS3.cpp index 7105aa689eb..6a42a741b62 100644 --- a/src/Disks/S3/DiskS3.cpp +++ b/src/Disks/S3/DiskS3.cpp @@ -1002,6 +1002,10 @@ void DiskS3::restoreFileOperations(const RestoreInformation & restore_informatio else to_path /= from_path.filename(); + /// to_path may exist and non-empty in case for example abrupt restart, so remove it before rename + if (metadata_disk->exists(to_path)) + metadata_disk->removeRecursive(to_path); + metadata_disk->moveDirectory(from_path, to_path); } }