2019-12-12 08:57:25 +00:00
|
|
|
#include "IDisk.h"
|
2020-03-19 16:37:55 +00:00
|
|
|
#include <IO/copyData.h>
|
|
|
|
#include <IO/ReadBufferFromFileBase.h>
|
|
|
|
#include <IO/WriteBufferFromFileBase.h>
|
|
|
|
#include <Poco/Logger.h>
|
|
|
|
#include <common/logger_useful.h>
|
2019-12-12 08:57:25 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-01-18 22:17:48 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
bool IDisk::isDirectoryEmpty(const String & path)
|
|
|
|
{
|
|
|
|
return !iterateDirectory(path)->isValid();
|
|
|
|
}
|
2020-03-19 16:37:55 +00:00
|
|
|
|
|
|
|
void copyFile(IDisk & from_disk, const String & from_path, IDisk & to_disk, const String & to_path)
|
|
|
|
{
|
2020-05-23 17:52:11 +00:00
|
|
|
LOG_DEBUG_FORMATTED(&Poco::Logger::get("IDisk"), "Copying from {} {} to {} {}.", from_disk.getName(), from_path, to_disk.getName(), to_path);
|
2020-03-19 16:37:55 +00:00
|
|
|
|
|
|
|
auto in = from_disk.readFile(from_path);
|
|
|
|
auto out = to_disk.writeFile(to_path);
|
|
|
|
copyData(*in, *out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IDisk::copy(const String & from_path, const std::shared_ptr<IDisk> & to_disk, const String & to_path)
|
|
|
|
{
|
|
|
|
if (isFile(from_path))
|
|
|
|
{
|
|
|
|
DB::copyFile(*this, from_path, *to_disk, to_path + fileName(from_path));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Poco::Path path(from_path);
|
|
|
|
const String & dir_name = path.directory(path.depth() - 1);
|
|
|
|
const String dest = to_path + dir_name + "/";
|
|
|
|
to_disk->createDirectories(dest);
|
|
|
|
|
|
|
|
for (auto it = iterateDirectory(from_path); it->isValid(); it->next())
|
|
|
|
{
|
|
|
|
copy(it->path(), to_disk, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
}
|