Handle FileRotatingStreams with long file names
Bug: webrtc:9392 Change-Id: I7b42b1a6ed1b646c244bc64f1bad92a2f38e5539 Reviewed-on: https://webrtc-review.googlesource.com/83162 Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23608}
This commit is contained in:
@ -327,22 +327,15 @@ std::vector<std::string> FileRotatingStream::GetFilesWithPrefix() const {
|
||||
std::string FileRotatingStream::GetFilePath(size_t index,
|
||||
size_t num_files) const {
|
||||
RTC_DCHECK_LT(index, num_files);
|
||||
char buf[1024];
|
||||
rtc::SimpleStringBuilder file_name(buf);
|
||||
// The format will be "_%<num_digits>zu". We want to zero pad the index so
|
||||
// that it will sort nicely.
|
||||
size_t max_digits = ((num_files - 1) / 10) + 1;
|
||||
size_t num_digits = (index / 10) + 1;
|
||||
RTC_DCHECK_LE(num_digits, max_digits);
|
||||
size_t padding = max_digits - num_digits;
|
||||
|
||||
file_name << file_prefix_ << "_";
|
||||
for (size_t i = 0; i < padding; ++i) {
|
||||
file_name << "0";
|
||||
}
|
||||
file_name << index;
|
||||
const size_t buffer_size = 32;
|
||||
char file_postfix[buffer_size];
|
||||
// We want to zero pad the index so that it will sort nicely.
|
||||
const int max_digits = std::snprintf(nullptr, 0, "%zu", num_files - 1);
|
||||
RTC_DCHECK_LT(1 + max_digits, buffer_size);
|
||||
std::snprintf(file_postfix, buffer_size, "_%0*zu", max_digits, index);
|
||||
|
||||
Pathname file_path(dir_path_, file_name.str());
|
||||
Pathname file_path(dir_path_, file_prefix_ + file_postfix);
|
||||
return file_path.pathname();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user