Delete all but the last 5 crash dumps on startup (#4392)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2023-02-19 23:20:41 +01:00 committed by GitHub
parent c95a65c153
commit c74b14a93a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View file

@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Minor: Delete all but the last 5 crashdumps on application start. (#4392)
- Dev: Add capability to build Chatterino with Qt6. (#4393) - Dev: Add capability to build Chatterino with Qt6. (#4393)
- Dev: Fix homebrew update action. (#4394) - Dev: Fix homebrew update action. (#4394)

View file

@ -185,6 +185,38 @@ namespace {
} }
qCDebug(chatterinoCache) << "Deleted" << deletedCount << "files"; qCDebug(chatterinoCache) << "Deleted" << deletedCount << "files";
} }
// We delete all but the five most recent crashdumps. This strategy may be
// improved in the future.
void clearCrashes(QDir dir)
{
// crashpad crashdumps are stored inside the Crashes/report directory
if (!dir.cd("reports"))
{
// no reports directory exists = no files to delete
return;
}
dir.setNameFilters({"*.dmp"});
size_t deletedCount = 0;
// TODO: use std::views::drop once supported by all compilers
size_t filesToSkip = 5;
for (auto &&info : dir.entryInfoList(QDir::Files, QDir::Time))
{
if (filesToSkip > 0)
{
filesToSkip--;
continue;
}
if (QFile(info.absoluteFilePath()).remove())
{
deletedCount++;
}
}
qCDebug(chatterinoApp) << "Deleted" << deletedCount << "crashdumps";
}
} // namespace } // namespace
void runGui(QApplication &a, Paths &paths, Settings &settings) void runGui(QApplication &a, Paths &paths, Settings &settings)
@ -215,10 +247,15 @@ void runGui(QApplication &a, Paths &paths, Settings &settings)
}); });
// Clear the cache 1 minute after start. // Clear the cache 1 minute after start.
QTimer::singleShot(60 * 1000, [cachePath = paths.cacheDirectory()] { QTimer::singleShot(60 * 1000, [cachePath = paths.cacheDirectory(),
crashDirectory = paths.crashdumpDirectory] {
QtConcurrent::run([cachePath]() { QtConcurrent::run([cachePath]() {
clearCache(cachePath); clearCache(cachePath);
}); });
QtConcurrent::run([crashDirectory]() {
clearCrashes(crashDirectory);
});
}); });
chatterino::NetworkManager::init(); chatterino::NetworkManager::init();