同步文件计算大小逻辑修复

This commit is contained in:
zhaominyong 2022-03-11 17:08:43 +08:00
parent 6e90bbffb3
commit ec3e7b8729
2 changed files with 14 additions and 10 deletions

View File

@ -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();
}

View File

@ -811,6 +811,9 @@ bool Utils::isRunning(const QString &processName)
}
}
grep.close();
ps.close();
return bRet;
}