From 4e016e5927fbe4c78a9627849d8dcf7b5708d8bb Mon Sep 17 00:00:00 2001 From: Lukasz Machutt Date: Mon, 15 Jan 2024 13:02:33 +0100 Subject: [PATCH] fixed-islogfromcurrentproject func --- src/logging.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/logging.cc b/src/logging.cc index 14385eb0a..a21a53164 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -1416,8 +1416,30 @@ bool LogCleaner::IsLogFromCurrentProject( } } + // As we want to delete old logs despite their severity, + // we need to replace in cleaned_base_file and find matching one. + const string::size_type dot_pos = + cleaned_base_filename.find_last_of('.', cleaned_base_filename.size() - 1); + + const string new_base_filename = cleaned_base_filename.substr(0, dot_pos); + + // Loop through severity names and check whether + // filepath contains cleaned_base_filename_with_severity + bool found_file = false; + for (const auto& severity : LogSeverityNames) { + string cleaned_base_filename_with_severity = new_base_filename + severity; + + if (filepath.find(cleaned_base_filename_with_severity) == 0) { + // Assign cleaned_base_filename to our new base name + // Add trailing dot we deleted earlier + cleaned_base_filename = cleaned_base_filename_with_severity + '.'; + found_file = true; + break; + } + } + // Return early if the filename doesn't start with `cleaned_base_filename`. - if (filepath.find(cleaned_base_filename) != 0) { + if (!found_file) { return false; }