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; }