From bcec2ebbf2a109958e278e7bb01a2edca37535fd Mon Sep 17 00:00:00 2001 From: wangfeifan Date: Tue, 9 May 2023 11:56:10 +0800 Subject: [PATCH] [hotfix] fix log file create failed caused by name too long --- file/filename.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/file/filename.cc b/file/filename.cc index 0496596c6..a428b01d3 100644 --- a/file/filename.cc +++ b/file/filename.cc @@ -26,12 +26,14 @@ static const std::string kRocksDBBlobFileExt = "blob"; // Given a path, flatten the path name by replacing all chars not in // {[0-9,a-z,A-Z,-,_,.]} with _. And append '_LOG\0' at the end. +// If the given path append the '_LOG\0' longer then 255, only the last 255 characters will be kept. // Return the number of chars stored in dest not including the trailing '\0'. static size_t GetInfoLogPrefix(const std::string& path, char* dest, int len) { const char suffix[] = "_LOG"; + const size_t file_name_length_limit = 255; size_t write_idx = 0; - size_t i = 0; + size_t i = std::max(0L, (long)path.length() - (long)(file_name_length_limit - sizeof(suffix))); size_t src_len = path.size(); while (i < src_len && write_idx < len - sizeof(suffix)) {