clears cache files > 14 days 1 min after start
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
|
#include <QtConcurrent>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
@@ -137,6 +138,28 @@ namespace {
|
|||||||
signal(SIGSEGV, handleSignal);
|
signal(SIGSEGV, handleSignal);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We delete cache files that haven't been modified in 14 days. This strategy may be
|
||||||
|
// improved in the future.
|
||||||
|
void clearCache(const QDir &dir)
|
||||||
|
{
|
||||||
|
qDebug() << "[Cache] cleared cache";
|
||||||
|
|
||||||
|
QStringList toBeRemoved;
|
||||||
|
|
||||||
|
for (auto &&info : dir.entryInfoList(QDir::Files))
|
||||||
|
{
|
||||||
|
if (info.lastModified().addDays(14) < QDateTime::currentDateTime())
|
||||||
|
{
|
||||||
|
toBeRemoved << info.absoluteFilePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &&path : toBeRemoved)
|
||||||
|
{
|
||||||
|
qDebug() << path << QFile(path).remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void runGui(QApplication &a, Paths &paths, Settings &settings)
|
void runGui(QApplication &a, Paths &paths, Settings &settings)
|
||||||
@@ -165,6 +188,11 @@ void runGui(QApplication &a, Paths &paths, Settings &settings)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clear the cache 1 minute after start.
|
||||||
|
QTimer::singleShot(60 * 1000, [cachePath = paths.cacheDirectory()] {
|
||||||
|
QtConcurrent::run([cachePath]() { clearCache(cachePath); });
|
||||||
|
});
|
||||||
|
|
||||||
chatterino::NetworkManager::init();
|
chatterino::NetworkManager::init();
|
||||||
chatterino::Updates::getInstance().checkForUpdates();
|
chatterino::Updates::getInstance().checkForUpdates();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user