2021-08-18 22:19:14 +00:00
|
|
|
#include <Backups/BackupEntryFromSmallFile.h>
|
2023-04-25 17:44:03 +00:00
|
|
|
#include <Common/filesystemHelpers.h>
|
|
|
|
#include <Disks/DiskLocal.h>
|
2021-08-18 22:19:14 +00:00
|
|
|
#include <Disks/IDisk.h>
|
2022-03-08 17:05:55 +00:00
|
|
|
#include <Disks/IO/createReadBufferFromFileBase.h>
|
2023-04-25 17:44:03 +00:00
|
|
|
#include <IO/ReadBufferFromString.h>
|
2021-08-18 22:19:14 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2023-07-23 09:23:36 +00:00
|
|
|
String readFile(const String & file_path, const ReadSettings & read_settings)
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
2023-07-23 09:23:36 +00:00
|
|
|
auto buf = createReadBufferFromFileBase(file_path, read_settings);
|
2021-08-18 22:19:14 +00:00
|
|
|
String s;
|
|
|
|
readStringUntilEOF(s, *buf);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2023-07-23 09:23:36 +00:00
|
|
|
String readFile(const DiskPtr & disk, const String & file_path, const ReadSettings & read_settings, bool copy_encrypted)
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
2023-07-23 09:23:36 +00:00
|
|
|
auto buf = copy_encrypted ? disk->readEncryptedFile(file_path, read_settings) : disk->readFile(file_path, read_settings);
|
2021-08-18 22:19:14 +00:00
|
|
|
String s;
|
|
|
|
readStringUntilEOF(s, *buf);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-23 09:23:36 +00:00
|
|
|
BackupEntryFromSmallFile::BackupEntryFromSmallFile(const String & file_path_, const ReadSettings & read_settings_)
|
2023-04-25 17:44:03 +00:00
|
|
|
: file_path(file_path_)
|
|
|
|
, data_source_description(DiskLocal::getLocalDataSourceDescription(file_path_))
|
2023-07-23 09:23:36 +00:00
|
|
|
, data(readFile(file_path_, read_settings_))
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
|
|
|
}
|
2023-05-01 12:23:59 +00:00
|
|
|
|
2023-07-23 09:23:36 +00:00
|
|
|
BackupEntryFromSmallFile::BackupEntryFromSmallFile(const DiskPtr & disk_, const String & file_path_, const ReadSettings & read_settings_, bool copy_encrypted_)
|
2023-04-25 17:44:03 +00:00
|
|
|
: disk(disk_)
|
|
|
|
, file_path(file_path_)
|
|
|
|
, data_source_description(disk_->getDataSourceDescription())
|
2023-05-03 23:27:16 +00:00
|
|
|
, copy_encrypted(copy_encrypted_ && data_source_description.is_encrypted)
|
2023-07-23 09:23:36 +00:00
|
|
|
, data(readFile(disk_, file_path, read_settings_, copy_encrypted))
|
2023-04-25 17:44:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:51:36 +00:00
|
|
|
std::unique_ptr<SeekableReadBuffer> BackupEntryFromSmallFile::getReadBuffer(const ReadSettings &) const
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
2023-04-25 17:44:03 +00:00
|
|
|
return std::make_unique<ReadBufferFromString>(data);
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|
2022-08-19 14:58:30 +00:00
|
|
|
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|