diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2020-12-16 11:50:56 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-01-02 21:31:20 +0100 |
commit | ec01c570229bfe79fa9471fc226fc3c9bb11878e (patch) | |
tree | b517cc7861554861bc233d00d91b4f75d1d63a73 /rbutil | |
parent | 65d0867a25e32915e73cadf4bdc90c58ed11bfc1 (diff) |
rbutil: Fix cache size calculation.
We're using Qt's caching mechanism since long, which uses subfolders, so
we need to recursively traverse that to get the size of the cache
folder.
Change-Id: I8425016f60d0575013110e708b539833a8098246
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/base/utils.cpp | 14 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/utils.h | 1 | ||||
-rw-r--r-- | rbutil/rbutilqt/configure.cpp | 7 |
3 files changed, 16 insertions, 6 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index 3ab8aa6906..f2d3f04887 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp @@ -1046,3 +1046,17 @@ bool Utils::ejectDevice(QString device) return false; } + +qint64 Utils::recursiveFolderSize(QString path) +{ + qint64 size = 0; + QList<QFileInfo> items = QDir(path).entryInfoList(QDir::Files | QDir::NoDotAndDotDot); + for (auto item: items) { + size += item.size(); + } + QList<QString> folders = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot); + for (auto folder: folders) { + size += recursiveFolderSize(path + "/" + folder); + } + return size; +} diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h index f46f713525..7f27c7d321 100644 --- a/rbutil/rbutilqt/base/utils.h +++ b/rbutil/rbutilqt/base/utils.h @@ -57,6 +57,7 @@ public: static QMap<QString, QList<int> > findRunningProcess(QStringList names); static QList<int> suspendProcess(QList<int> pidlist, bool suspend); static bool ejectDevice(QString device); + static qint64 recursiveFolderSize(QString path); }; #endif diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp index c2ab61b36d..507d0bec41 100644 --- a/rbutil/rbutilqt/configure.cpp +++ b/rbutil/rbutilqt/configure.cpp @@ -306,12 +306,7 @@ void Config::setUserSettings() void Config::updateCacheInfo(QString path) { - QList<QFileInfo> fs; - fs = QDir(path + "/rbutil-cache/").entryInfoList(QDir::Files | QDir::NoDotAndDotDot); - qint64 sz = 0; - for(int i = 0; i < fs.size(); i++) { - sz += fs.at(i).size(); - } + qint64 sz = Utils::recursiveFolderSize(path + "/rbutil-cache"); ui.cacheSize->setText(tr("Current cache size is %L1 kiB.") .arg(sz/1024)); } |