Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogCleaner: Fix the scenario when FLAGS_log_dir has no '/' suffix #972

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Brian Silverman <bsilver16384@gmail.com>
Dmitriy Arbitman <d.arbitman@gmail.com>
Google Inc.
Guillaume Dumont <dumont.guillaume@gmail.com>
LingBin <lingbinlb@gmail.com>
Marco Wang <m.aesophor@gmail.com>
Michael Tanner <michael@tannertaxpro.com>
MiniLight <MiniLightAR@Gmail.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Håkan L. S. Younes <hyounes@google.com>
Ivan Penkov <ivanpe@google.com>
Jacob Trimble <modmaker@google.com>
Jim Ray <jimray@google.com>
LingBin <lingbinlb@gmail.com>
Marco Wang <m.aesophor@gmail.com>
Michael Darr <mdarr@matician.com>
Michael Tanner <michael@tannertaxpro.com>
Expand Down
12 changes: 10 additions & 2 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,16 @@ const vector<string>& GetLoggingDirectories() {
logging_directories_list = new vector<string>;

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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)) {

You may need to include <iterator>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review, already addressed comment.

After testing <iterator> is not needed. My guess is that it is already included in an existing header file.
From https://en.cppreference.com/w/cpp/iterator/begin
It can be seen that std::begin and std::end are defined in many header files.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how it works. You do need <iterator> which defines std::begin and std::end for statically sized arrays (see IWYU why relying on indirection is a bad style). By 'may' I meant to say that I did not check whether <iterator> is already included in the touched translation unit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked logging.cc. <iterator> must definitely be included since it is not present there yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your further explanation. <iterator> has been added.

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
Expand Down