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 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unversioned

- Bugfix: Only store the five most recent crashdumps. (#4392)

## 2.4.1

- Major: Added live emote updates for BTTV. (#4147)
Expand Down
37 changes: 36 additions & 1 deletion src/RunGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,31 @@ 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)
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
{
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 +240,20 @@ 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);
});

auto crashReportsDir = QDir(crashDirectory);
// check if the /reports directory exists
if (crashReportsDir.cd("reports"))
{
QtConcurrent::run([crashReportsDir]() {
clearCrashes(crashReportsDir);
});
}
});

chatterino::NetworkManager::init();
Expand Down