mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-27 15:32:10 +08:00
make PruneCrashReportDatabase return the number of pruned crash reports
Change-Id: I270ea8df5054ede9731c7a0a22439a1409eee6d9 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1808138 Commit-Queue: Francois Rousseau <frousseau@google.com> Reviewed-by: Scott Graham <scottmg@chromium.org>
This commit is contained in:
parent
edbbc4609d
commit
c405d0ea2c
@ -15,6 +15,7 @@
|
||||
#include "client/prune_crash_reports.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
@ -24,7 +25,7 @@
|
||||
|
||||
namespace crashpad {
|
||||
|
||||
void PruneCrashReportDatabase(CrashReportDatabase* database,
|
||||
size_t PruneCrashReportDatabase(CrashReportDatabase* database,
|
||||
PruneCondition* condition) {
|
||||
std::vector<CrashReportDatabase::Report> all_reports;
|
||||
CrashReportDatabase::OperationStatus status;
|
||||
@ -32,14 +33,14 @@ void PruneCrashReportDatabase(CrashReportDatabase* database,
|
||||
status = database->GetPendingReports(&all_reports);
|
||||
if (status != CrashReportDatabase::kNoError) {
|
||||
LOG(ERROR) << "PruneCrashReportDatabase: Failed to get pending reports";
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<CrashReportDatabase::Report> completed_reports;
|
||||
status = database->GetCompletedReports(&completed_reports);
|
||||
if (status != CrashReportDatabase::kNoError) {
|
||||
LOG(ERROR) << "PruneCrashReportDatabase: Failed to get completed reports";
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
all_reports.insert(all_reports.end(), completed_reports.begin(),
|
||||
completed_reports.end());
|
||||
@ -50,16 +51,21 @@ void PruneCrashReportDatabase(CrashReportDatabase* database,
|
||||
return lhs.creation_time > rhs.creation_time;
|
||||
});
|
||||
|
||||
size_t num_pruned = 0;
|
||||
for (const auto& report : all_reports) {
|
||||
if (condition->ShouldPruneReport(report)) {
|
||||
status = database->DeleteReport(report.uuid);
|
||||
if (status != CrashReportDatabase::kNoError) {
|
||||
LOG(ERROR) << "Database Pruning: Failed to remove report "
|
||||
<< report.uuid.ToString();
|
||||
} else {
|
||||
num_pruned++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return num_pruned;
|
||||
|
||||
// TODO(rsesek): For databases that do not use a directory structure, it is
|
||||
// possible for the metadata sidecar to become corrupted and thus leave
|
||||
// orphaned crash report files on-disk. https://crashpad.chromium.org/bug/66
|
||||
|
@ -37,8 +37,10 @@ class PruneCondition;
|
||||
//! \param[in] database The database from which crash reports will be deleted.
|
||||
//! \param[in] condition The condition against which all reports in the database
|
||||
//! will be evaluated.
|
||||
void PruneCrashReportDatabase(CrashReportDatabase* database,
|
||||
PruneCondition* condition);
|
||||
//!
|
||||
//! \return The number of deleted crash reports.
|
||||
size_t PruneCrashReportDatabase(CrashReportDatabase* database,
|
||||
PruneCondition* condition);
|
||||
|
||||
std::unique_ptr<PruneCondition> GetDefaultDatabasePruneCondition();
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "client/prune_crash_reports.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
@ -204,11 +205,12 @@ TEST(PruneCrashReports, PruneOrder) {
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
|
||||
const size_t kNumReports = 10;
|
||||
std::vector<CrashReportDatabase::Report> reports;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
for (size_t i = 0; i < kNumReports; ++i) {
|
||||
CrashReportDatabase::Report temp;
|
||||
temp.uuid.data_1 = i;
|
||||
temp.creation_time = NDaysAgo(i * 10);
|
||||
temp.uuid.data_1 = static_cast<uint32_t>(i);
|
||||
temp.creation_time = NDaysAgo(static_cast<int>(i) * 10);
|
||||
reports.push_back(temp);
|
||||
}
|
||||
std::mt19937 urng(std::random_device{}());
|
||||
@ -231,7 +233,7 @@ TEST(PruneCrashReports, PruneOrder) {
|
||||
}
|
||||
|
||||
StaticCondition delete_all(true);
|
||||
PruneCrashReportDatabase(&db, &delete_all);
|
||||
EXPECT_EQ(PruneCrashReportDatabase(&db, &delete_all), kNumReports);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user