Skip to content

Commit

Permalink
[hotfix] fix log file create failed caused by name too long
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltar9264 committed May 9, 2023
1 parent de2ffe6 commit 94820b9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions file/filename.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ 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 src_len = path.size();

if (path.length() > file_name_length_limit - sizeof(suffix)) {
i = path.length() - (file_name_length_limit - sizeof(suffix));
}

while (i < src_len && write_idx < len - sizeof(suffix)) {
if ((path[i] >= 'a' && path[i] <= 'z') ||
(path[i] >= '0' && path[i] <= '9') ||
Expand Down

0 comments on commit 94820b9

Please sign in to comment.