Group-level logs#2529
Conversation
Bug: b/509586405
Bug: b/509586405
| return {}; | ||
| } | ||
|
|
||
| Result<std::vector<std::string>> Filter( |
There was a problem hiding this comment.
Please choose a less generic name, one that more clearly conveys what this function does. Consider RemoveInaccessibleFiles.
| } | ||
|
|
||
| Result<std::vector<std::string>> Filter( | ||
| const std::vector<std::string>& filenames) { |
There was a problem hiding this comment.
Consider accepting the input by value instead of reference. Then you can implement the function such that it modifies and returns the parameter. Something like this:
std::vector<std::string> Filter(std::vector<std::string> files) {
auto removed_begin = std::remove_if(files.begin(), files.end(), [](const std::string& file){ return !IsAccessible(file);});
files.erase(removed_begin, files.end());
return files;
}
That implementation can avoid all copies of the vector if the parameter is moved into it (which is the case where this function is called as it's given a temporary object), otherwise it makes a single copy (at the call site) just like the original. See go/totw/117 for details.
| const std::vector<std::string>& filenames) { | ||
| std::vector<std::string> result = {}; | ||
| for (auto& filename : filenames) { | ||
| if (access(filename.data(), F_OK) == 0) { |
There was a problem hiding this comment.
nit: Consider using c_str() instead of data(). While data and c_str do the same thing since C++11, using c_str makes it clear that a null terminated string is required. data is more appropriate when you need to modify the contents of the string or don't care about the null character at the end.
| return {}; | ||
| } | ||
|
|
||
| Result<std::vector<std::string>> Filter( |
There was a problem hiding this comment.
Don't return Result if the function can't fail
| if (opts.print_target.empty()) { | ||
| CF_EXPECT(PrintLogsList(logs_dir)); | ||
| if (logs_filenames.empty()) { | ||
| LOG(INFO) << "There are no logs files available"; |
| instance_dir() + "/logs/" + "build_info.log", | ||
| instance_dir() + "/logs/" + "crosvm_openwrt_boot.log", | ||
| instance_dir() + "/logs/" + "crosvm_openwrt.log", | ||
| instance_dir() + "/logs/" + "kernel.log", | ||
| instance_dir() + "/logs/" + "launcher.log", | ||
| instance_dir() + "/logs/" + "logcat", | ||
| instance_dir() + "/logs/" + "modem_simulator.log", |
There was a problem hiding this comment.
Don't hardcode this list. Use every file from the directory that is not a group log file, otherwise this code will miss any new file added. It's OK to hardcode the group log list though.
No description provided.