mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
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:
parent
c95a65c153
commit
c74b14a93a
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue