summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base
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 /rbutil/rbutilqt/base
parent65d0867a25e32915e73cadf4bdc90c58ed11bfc1 (diff)
downloadrockbox-ec01c570229bfe79fa9471fc226fc3c9bb11878e.tar.gz
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
Diffstat (limited to 'rbutil/rbutilqt/base')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp14
-rw-r--r--rbutil/rbutilqt/base/utils.h1
2 files changed, 15 insertions, 0 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