diff --git a/src/Disks/IDiskRemote.cpp b/src/Disks/IDiskRemote.cpp index 8a9f5944dfe..6a2f0383f9d 100644 --- a/src/Disks/IDiskRemote.cpp +++ b/src/Disks/IDiskRemote.cpp @@ -357,13 +357,35 @@ std::vector IDiskRemote::getRemotePaths(const String & local_path) const void IDiskRemote::getRemotePathsRecursive(const String & local_path, std::vector & paths_map) { + /// Protect against concurrent delition of files (for example because of a merge). if (metadata_disk->isFile(local_path)) { - paths_map.emplace_back(local_path, getRemotePaths(local_path)); + try + { + paths_map.emplace_back(local_path, getRemotePaths(local_path)); + } + catch (const Exception & e) + { + if (e.code() == ErrorCodes::FILE_DOESNT_EXIST) + return; + throw; + } } else { - for (auto it = iterateDirectory(local_path); it->isValid(); it->next()) + DiskDirectoryIteratorPtr it; + try + { + it = iterateDirectory(local_path); + } + catch (const fs::filesystem_error & e) + { + if (e.code() == std::errc::no_such_file_or_directory) + return; + throw; + } + + for (; it->isValid(); it->next()) IDiskRemote::getRemotePathsRecursive(fs::path(local_path) / it->name(), paths_map); } }