Fix tidy one more time
This commit is contained in:
alesapin 2021-09-05 16:44:14 +03:00
parent 40d4d64a65
commit 73ef1233ef
6 changed files with 35 additions and 27 deletions

View File

@ -203,3 +203,5 @@ CheckOptions:
value: CamelCase value: CamelCase
- key: readability-identifier-naming.UsingCase - key: readability-identifier-naming.UsingCase
value: CamelCase value: CamelCase
- key: modernize-loop-convert.UseCxx20ReverseRanges
value: false

View File

@ -113,7 +113,7 @@ namespace DB
std::string CompressionCodecEncrypted::deriveKey(const std::string_view & master_key) std::string CompressionCodecEncrypted::deriveKey(const std::string_view & master_key)
{ {
std::string_view salt(""); // No salt: derive keys in a deterministic manner. std::string_view salt; // No salt: derive keys in a deterministic manner.
std::string_view info("Codec Encrypted('AES-128-GCM-SIV') key generation key"); std::string_view info("Codec Encrypted('AES-128-GCM-SIV') key generation key");
std::array<char, 32> result; std::array<char, 32> result;

View File

@ -32,7 +32,7 @@ WriteBufferFromFile::WriteBufferFromFile(
mode_t mode, mode_t mode,
char * existing_memory, char * existing_memory,
size_t alignment) size_t alignment)
: WriteBufferFromFileDescriptor(-1, buf_size, existing_memory, alignment), file_name(file_name_) : WriteBufferFromFileDescriptor(-1, buf_size, existing_memory, alignment, file_name_)
{ {
ProfileEvents::increment(ProfileEvents::FileOpen); ProfileEvents::increment(ProfileEvents::FileOpen);
@ -65,9 +65,7 @@ WriteBufferFromFile::WriteBufferFromFile(
size_t buf_size, size_t buf_size,
char * existing_memory, char * existing_memory,
size_t alignment) size_t alignment)
: : WriteBufferFromFileDescriptor(fd_, buf_size, existing_memory, alignment, original_file_name)
WriteBufferFromFileDescriptor(fd_, buf_size, existing_memory, alignment),
file_name(original_file_name.empty() ? "(fd = " + toString(fd_) + ")" : original_file_name)
{ {
fd_ = -1; fd_ = -1;
} }

View File

@ -25,7 +25,6 @@ namespace DB
class WriteBufferFromFile : public WriteBufferFromFileDescriptor class WriteBufferFromFile : public WriteBufferFromFileDescriptor
{ {
protected: protected:
std::string file_name;
CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForWrite}; CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForWrite};
public: public:

View File

@ -61,7 +61,9 @@ void WriteBufferFromFileDescriptor::nextImpl()
if ((-1 == res || 0 == res) && errno != EINTR) if ((-1 == res || 0 == res) && errno != EINTR)
{ {
ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWriteFailed); ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWriteFailed);
throwFromErrnoWithPath("Cannot write to file " + getFileName(), getFileName(),
/// Don't use getFileName() here because this method can be called from destructor
throwFromErrnoWithPath("Cannot write to file " + file_name, file_name,
ErrorCodes::CANNOT_WRITE_TO_FILE_DESCRIPTOR); ErrorCodes::CANNOT_WRITE_TO_FILE_DESCRIPTOR);
} }
@ -74,19 +76,17 @@ void WriteBufferFromFileDescriptor::nextImpl()
} }
/// Name or some description of file.
std::string WriteBufferFromFileDescriptor::getFileName() const
{
return "(fd = " + toString(fd) + ")";
}
WriteBufferFromFileDescriptor::WriteBufferFromFileDescriptor( WriteBufferFromFileDescriptor::WriteBufferFromFileDescriptor(
int fd_, int fd_,
size_t buf_size, size_t buf_size,
char * existing_memory, char * existing_memory,
size_t alignment) size_t alignment,
: WriteBufferFromFileBase(buf_size, existing_memory, alignment), fd(fd_) {} const std::string & file_name_)
: WriteBufferFromFileBase(buf_size, existing_memory, alignment)
, fd(fd_)
, file_name(file_name_.empty() ? "(fd = " + toString(fd) + ")" : file_name_)
{
}
WriteBufferFromFileDescriptor::~WriteBufferFromFileDescriptor() WriteBufferFromFileDescriptor::~WriteBufferFromFileDescriptor()
@ -115,7 +115,7 @@ void WriteBufferFromFileDescriptor::sync()
} }
off_t WriteBufferFromFileDescriptor::seek(off_t offset, int whence) off_t WriteBufferFromFileDescriptor::seek(off_t offset, int whence) // NOLINT
{ {
off_t res = lseek(fd, offset, whence); off_t res = lseek(fd, offset, whence);
if (-1 == res) if (-1 == res)
@ -125,7 +125,7 @@ off_t WriteBufferFromFileDescriptor::seek(off_t offset, int whence)
} }
void WriteBufferFromFileDescriptor::truncate(off_t length) void WriteBufferFromFileDescriptor::truncate(off_t length) // NOLINT
{ {
int res = ftruncate(fd, length); int res = ftruncate(fd, length);
if (-1 == res) if (-1 == res)
@ -133,7 +133,7 @@ void WriteBufferFromFileDescriptor::truncate(off_t length)
} }
off_t WriteBufferFromFileDescriptor::size() off_t WriteBufferFromFileDescriptor::size() const
{ {
struct stat buf; struct stat buf;
int res = fstat(fd, &buf); int res = fstat(fd, &buf);

View File

@ -13,17 +13,17 @@ class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
protected: protected:
int fd; int fd;
/// If file has name contains filename, otherwise contains string "(fd=...)"
std::string file_name;
void nextImpl() override; void nextImpl() override;
/// Name or some description of file.
std::string getFileName() const override;
public: public:
WriteBufferFromFileDescriptor( WriteBufferFromFileDescriptor(
int fd_ = -1, int fd_ = -1,
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
char * existing_memory = nullptr, char * existing_memory = nullptr,
size_t alignment = 0); size_t alignment = 0,
const std::string & file_name_ = "");
/** Could be used before initialization if needed 'fd' was not passed to constructor. /** Could be used before initialization if needed 'fd' was not passed to constructor.
* It's not possible to change 'fd' during work. * It's not possible to change 'fd' during work.
@ -42,10 +42,19 @@ public:
void sync() override; void sync() override;
off_t seek(off_t offset, int whence); /// clang-tidy wants these methods to be const, but
void truncate(off_t length); /// they are not const semantically
off_t seek(off_t offset, int whence); // NOLINT
void truncate(off_t length); // NOLINT
off_t size(); /// Name or some description of file.
std::string getFileName() const override
{
return file_name;
}
off_t size() const;
}; };
} }