diff --git a/CHANGELOG.md b/CHANGELOG.md index 82be7d5a..0b4d89d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Delete all but the last 5 crashdumps on application start. (#4392) - Dev: Add capability to build Chatterino with Qt6. (#4393) - Dev: Fix homebrew update action. (#4394) diff --git a/src/RunGui.cpp b/src/RunGui.cpp index fdf557e6..49c800a6 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -185,6 +185,38 @@ namespace { } 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 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. - QTimer::singleShot(60 * 1000, [cachePath = paths.cacheDirectory()] { + QTimer::singleShot(60 * 1000, [cachePath = paths.cacheDirectory(), + crashDirectory = paths.crashdumpDirectory] { QtConcurrent::run([cachePath]() { clearCache(cachePath); }); + + QtConcurrent::run([crashDirectory]() { + clearCrashes(crashDirectory); + }); }); chatterino::NetworkManager::init();