This commit is contained in:
kssenii 2022-04-20 10:42:07 +02:00
parent 2fb331bcec
commit 5fc4aaaa2d
2 changed files with 19 additions and 21 deletions

View File

@ -173,8 +173,8 @@ class DiskLocalDirectoryIterator final : public IDiskDirectoryIterator
{
public:
DiskLocalDirectoryIterator() = default;
DiskLocalDirectoryIterator(fs::directory_iterator && entry_, const String & dir_path_)
: dir_path(dir_path_), entry(std::move(entry_))
DiskLocalDirectoryIterator(const String & disk_path_, const String & dir_path_)
: dir_path(dir_path_), entry(fs::path(disk_path_) / dir_path_)
{
}
@ -319,21 +319,9 @@ DiskDirectoryIteratorPtr DiskLocal::iterateDirectory(const String & path)
{
fs::path meta_path = fs::path(disk_path) / path;
if (!broken && fs::exists(meta_path) && fs::is_directory(meta_path))
{
try
{
fs::directory_iterator entry(fs::path(disk_path) / path);
return std::make_unique<DiskLocalDirectoryIterator>(std::move(entry), path);
}
catch (const fs::filesystem_error & e)
{
if (e.code() == std::errc::no_such_file_or_directory)
return std::make_unique<DiskLocalDirectoryIterator>();
throw;
}
}
return std::make_unique<DiskLocalDirectoryIterator>();
return std::make_unique<DiskLocalDirectoryIterator>(disk_path, path);
else
return std::make_unique<DiskLocalDirectoryIterator>();
}
void DiskLocal::moveFile(const String & from_path, const String & to_path)

View File

@ -357,9 +357,9 @@ std::vector<String> IDiskRemote::getRemotePaths(const String & local_path) const
void IDiskRemote::getRemotePathsRecursive(const String & local_path, std::vector<LocalPathWithRemotePaths> & paths_map)
{
/// Protect against concurrent delition of files (for example because of a merge).
if (metadata_disk->isFile(local_path))
{
/// File could be concurrently deleted (for example because of a merge).
try
{
paths_map.emplace_back(local_path, getRemotePaths(local_path));
@ -373,9 +373,19 @@ void IDiskRemote::getRemotePathsRecursive(const String & local_path, std::vector
}
else
{
/// Metadata disk is currently only DislLocal. DiskLocal::iterateDirectory will return empty directory iterator
/// if file does not exist (even on cocnurrent file delition),
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);
}
}