From ec3e7b872960da4415a0db830918e3286550b9d4 Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Fri, 11 Mar 2022 17:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=87=E4=BB=B6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=A4=A7=E5=B0=8F=E9=80=BB=E8=BE=91=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/myprocess/calcbackupsize.cpp | 21 +++++++++++---------- common/utils.cpp | 3 +++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backup-daemon/myprocess/calcbackupsize.cpp b/backup-daemon/myprocess/calcbackupsize.cpp index f737e17..e0a6a9a 100755 --- a/backup-daemon/myprocess/calcbackupsize.cpp +++ b/backup-daemon/myprocess/calcbackupsize.cpp @@ -90,18 +90,19 @@ void CalcBackupSize::parseResult() QString out(m_process->readAll()); QStringList lines = out.split("\n"); qDebug() << out; + m_size = 0; for (QString& line : lines) { // 获取文件夹数目 -// if (line.startsWith("Number of files:")) { -// int indexOfDir = line.indexOf("dir: "); -// indexOfDir += 5; -// int indexOfDirEnd = line.indexOf(QRegularExpression("[ )]"), indexOfDir); -// int numOfDirs = line.mid(indexOfDir, indexOfDirEnd-indexOfDir).replace(",","").trimmed().toInt(); -// // 每个目录下还都有.和..,故总数还要*3 -// numOfDirs *= 3; -// // ext4格式的目录本身要占用4K空间(4096) -// m_size += numOfDirs * 4096; -// } + if (line.startsWith("Number of files:")) { + int indexOfDir = line.indexOf("dir: "); + indexOfDir += 5; + int indexOfDirEnd = line.indexOf(QRegularExpression("[ )]"), indexOfDir); + int numOfDirs = line.mid(indexOfDir, indexOfDirEnd-indexOfDir).replace(",","").trimmed().toInt(); + // 每个目录下还都有.和..,故总数还要*3 + numOfDirs *= 3; + // ext4格式的目录本身要占用4K空间(4096) + m_size += numOfDirs * 4096; + } if (line.startsWith("Total transferred file size: ")) { m_size += line.replace("Total transferred file size: ", "").replace("bytes", "").replace(",","").trimmed().toLongLong(); } diff --git a/common/utils.cpp b/common/utils.cpp index 2258bfb..f55c51e 100755 --- a/common/utils.cpp +++ b/common/utils.cpp @@ -811,6 +811,9 @@ bool Utils::isRunning(const QString &processName) } } + grep.close(); + ps.close(); + return bRet; }