From 86056ce46f87f6cd3f62fb048ac058a206658885 Mon Sep 17 00:00:00 2001 From: lingbin Date: Tue, 10 Oct 2023 18:23:01 +0800 Subject: [PATCH] LogCleaner: Fix the scenario when FLAGS_log_dir has no '/' suffix Fixes #971 --- AUTHORS | 1 + CONTRIBUTORS | 1 + src/logging.cc | 12 ++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9d711ec62..4b5ff0201 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,6 +16,7 @@ Brian Silverman Dmitriy Arbitman Google Inc. Guillaume Dumont +LingBin Marco Wang Michael Tanner MiniLight diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 5780377c6..82aead939 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -36,6 +36,7 @@ HÃ¥kan L. S. Younes Ivan Penkov Jacob Trimble Jim Ray +LingBin Marco Wang Michael Darr Michael Tanner diff --git a/src/logging.cc b/src/logging.cc index 23295f57a..ef7fa5a9f 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -2397,8 +2397,16 @@ const vector& GetLoggingDirectories() { logging_directories_list = new vector; if ( !FLAGS_log_dir.empty() ) { - // A dir was specified, we should use it - logging_directories_list->push_back(FLAGS_log_dir); + // A dir was specified, we should use it, and make sure to end with + // a directory delimiter. + const char* const dir_delim_end = + possible_dir_delim + sizeof(possible_dir_delim); + if (std::find(possible_dir_delim, dir_delim_end, + FLAGS_log_dir.back()) == dir_delim_end) { + logging_directories_list->push_back(FLAGS_log_dir + "/"); + } else { + logging_directories_list->push_back(FLAGS_log_dir); + } } else { GetTempDirectories(logging_directories_list); #ifdef GLOG_OS_WINDOWS