Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
39 changes: 38 additions & 1 deletion src/RunGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down