Optimize logs folder size calculation (#3427)

This commit is contained in:
Paweł 2022-01-05 22:17:35 +01:00 committed by GitHub
parent 4f01ea4ab6
commit 34203dfa7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 20 deletions

View file

@ -2,6 +2,7 @@
#include "providers/twitch/TwitchCommon.hpp"
#include <QDirIterator>
#include <QLocale>
#include <QUuid>

View file

@ -23,22 +23,17 @@
namespace chatterino {
qint64 dirSize(QString dirPath)
qint64 dirSize(QString &dirPath)
{
QDirIterator it(dirPath, QDirIterator::Subdirectories);
qint64 size = 0;
QDir dir(dirPath);
// calculate total size of current directories' files
QDir::Filters fileFilters = QDir::Files | QDir::System | QDir::Hidden;
for (QString filePath : dir.entryList(fileFilters))
while (it.hasNext())
{
QFileInfo fi(dir, filePath);
size += fi.size();
size += it.fileInfo().size();
it.next();
}
// add size of child directories recursively
QDir::Filters dirFilters =
QDir::Dirs | QDir::NoDotAndDotDot | QDir::System | QDir::Hidden;
for (QString childDirPath : dir.entryList(dirFilters))
size += dirSize(dirPath + QDir::separator() + childDirPath);
return size;
}
@ -58,15 +53,14 @@ QString formatSize(qint64 size)
QString fetchLogDirectorySize()
{
QString logPathDirectory = getSettings()->logPath.getValue().isEmpty()
? getPaths()->messageLogDirectory
: getSettings()->logPath;
QString logsDirectoryPath = getSettings()->logPath.getValue().isEmpty()
? getPaths()->messageLogDirectory
: getSettings()->logPath;
qint64 logsSize = dirSize(logPathDirectory);
QString logsSizeLabel = "Your logs currently take up ";
logsSizeLabel += formatSize(logsSize);
logsSizeLabel += " of space";
return logsSizeLabel;
auto logsSize = dirSize(logsDirectoryPath);
return QString("Your logs currently take up %1 of space")
.arg(formatSize(logsSize));
}
ModerationPage::ModerationPage()