mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-14 03:25:15 +00:00
Merge pull request #45418 from CurtizJ/fix-disk-encrypted
Fix reading from encrypted disk with passed file size
This commit is contained in:
commit
4ca359d57b
@ -289,6 +289,12 @@ std::unique_ptr<ReadBufferFromFileBase> DiskEncrypted::readFile(
|
||||
std::optional<size_t> read_hint,
|
||||
std::optional<size_t> file_size) const
|
||||
{
|
||||
if (read_hint && *read_hint > 0)
|
||||
read_hint = *read_hint + FileEncryption::Header::kSize;
|
||||
|
||||
if (file_size && *file_size > 0)
|
||||
file_size = *file_size + FileEncryption::Header::kSize;
|
||||
|
||||
auto wrapped_path = wrappedPath(path);
|
||||
auto buffer = delegate->readFile(wrapped_path, settings, read_hint, file_size);
|
||||
if (buffer->eof())
|
||||
|
@ -55,9 +55,9 @@ protected:
|
||||
return temp_dir->path() + "/";
|
||||
}
|
||||
|
||||
String getFileContents(const String & file_name)
|
||||
String getFileContents(const String & file_name, std::optional<size_t> file_size = {})
|
||||
{
|
||||
auto buf = encrypted_disk->readFile(file_name, /* settings= */ {}, /* read_hint= */ {}, /* file_size= */ {});
|
||||
auto buf = encrypted_disk->readFile(file_name, /* settings= */ {}, /* read_hint= */ {}, file_size);
|
||||
String str;
|
||||
readStringUntilEOF(str, *buf);
|
||||
return str;
|
||||
@ -108,6 +108,10 @@ TEST_F(DiskEncryptedTest, WriteAndRead)
|
||||
EXPECT_EQ(getFileContents("a.txt"), "Some text");
|
||||
checkBinaryRepresentation(getDirectory() + "a.txt", kHeaderSize + 9);
|
||||
|
||||
/// Read the file with specified file size.
|
||||
EXPECT_EQ(getFileContents("a.txt", 9), "Some text");
|
||||
checkBinaryRepresentation(getDirectory() + "a.txt", kHeaderSize + 9);
|
||||
|
||||
/// Remove the file.
|
||||
encrypted_disk->removeFile("a.txt");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user