summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-12-16 11:50:56 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2021-01-02 21:31:20 +0100
commitec01c570229bfe79fa9471fc226fc3c9bb11878e (patch)
treeb517cc7861554861bc233d00d91b4f75d1d63a73
parent65d0867a25e32915e73cadf4bdc90c58ed11bfc1 (diff)
downloadrockbox-ec01c570229bfe79fa9471fc226fc3c9bb11878e.tar.gz
rockbox-ec01c570229bfe79fa9471fc226fc3c9bb11878e.tar.bz2
rockbox-ec01c570229bfe79fa9471fc226fc3c9bb11878e.zip
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
-rw-r--r--rbutil/rbutilqt/base/utils.cpp14
-rw-r--r--rbutil/rbutilqt/base/utils.h1
-rw-r--r--rbutil/rbutilqt/configure.cpp7
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));
}