From 86056ce46f87f6cd3f62fb048ac058a206658885 Mon Sep 17 00:00:00 2001 From: lingbin Date: Tue, 10 Oct 2023 18:23:01 +0800 Subject: [PATCH 1/3] 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 From 111b9082888209b2ad049ed99a78cae365512aca Mon Sep 17 00:00:00 2001 From: "lingbin.lb" Date: Thu, 12 Oct 2023 00:22:05 +0800 Subject: [PATCH 2/3] Address comment --- src/logging.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/logging.cc b/src/logging.cc index ef7fa5a9f..8ba60a26f 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -2397,12 +2397,9 @@ const vector& GetLoggingDirectories() { logging_directories_list = new vector; if ( !FLAGS_log_dir.empty() ) { - // 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) { + // Ensure the specified path ends with a directory delimiter. + if (std::find(std::begin(possible_dir_delim), std::end(possible_dir_delim), + FLAGS_log_dir.back()) == std::end(possible_dir_delim)) { logging_directories_list->push_back(FLAGS_log_dir + "/"); } else { logging_directories_list->push_back(FLAGS_log_dir); From eb229bc59955966dc8cb26b95a7074964fa135a3 Mon Sep 17 00:00:00 2001 From: "lingbin.lb" Date: Thu, 12 Oct 2023 11:39:39 +0800 Subject: [PATCH 3/3] Add --- src/logging.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/logging.cc b/src/logging.cc index 8ba60a26f..a364e4f1b 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -35,6 +35,7 @@ #include #include #include +#include #include #ifdef HAVE_UNISTD_H