From fe4b29675161495b045f67fbc94869e61dab6c82 Mon Sep 17 00:00:00 2001 From: keke <243768648@qq.com> Date: Tue, 7 Jun 2022 22:43:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8D=E8=8E=B7=E5=8F=96=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=8C=85=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appmanagercommon.h | 2 ++ appmanagerjob.cpp | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/appmanagercommon.h b/appmanagercommon.h index d962919..fd5aa1c 100644 --- a/appmanagercommon.h +++ b/appmanagercommon.h @@ -16,6 +16,7 @@ struct PkgInfo { qint64 contentSize; // 内容大小 QString depositoryUrl; // 仓库地址 QString pkgName; + bool isInstalled; int installedSize; QString updatedTime; QString maintainer; @@ -32,6 +33,7 @@ struct PkgInfo { contentOffset = 0; contentSize = 0; installedSize = 0; + isInstalled = false; pkgSize = 0; } }; diff --git a/appmanagerjob.cpp b/appmanagerjob.cpp index c1147c5..ee2efd2 100644 --- a/appmanagerjob.cpp +++ b/appmanagerjob.cpp @@ -527,7 +527,6 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } PkgInfo pkgInfo; - bool isInstalled = false; bool isReadingDescription = false; // 是否获取简洁信息 if (isCompact) { @@ -544,7 +543,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.split(": ").last().startsWith("install"); + pkgInfo.isInstalled = lineText.split(": ").last().startsWith("install"); continue; } @@ -555,9 +554,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS pkgInfo.contentOffset = contentOffset; pkgInfo.contentSize = contentOffset - lastPkgContentOffset; lastPkgContentOffset = contentOffset; - if (isInstalled) { - pkgInfoList.append(pkgInfo); - } + pkgInfoList.append(pkgInfo); pkgInfo = {}; } } @@ -572,7 +569,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.split(": ").last().startsWith("install"); + pkgInfo.isInstalled = lineText.split(": ").last().startsWith("install"); continue; } @@ -631,9 +628,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS if (lineText.isEmpty()) { pkgInfo.infosFilePath = pkgInfosFilePath; pkgInfo.depositoryUrl = depositoryUrlStr; - if (isInstalled) { - pkgInfoList.append(pkgInfo); - } + pkgInfoList.append(pkgInfo); pkgInfo = {}; } } @@ -643,9 +638,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS // 判断循环中最后一个包信息是否没添加到列表 // 防止最后一个包信息的最后一行不是换行符,而忽略了该包信息 if (!pkgInfo.pkgName.isEmpty()) { - if (isInstalled) { - pkgInfoList.append(pkgInfo); - } + pkgInfoList.append(pkgInfo); } qInfo() << Q_FUNC_INFO << "end"; @@ -661,7 +654,6 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName return false; } - bool isInstalled = false; bool isReadingDescription = false; while (!file.atEnd()) { const QByteArray ba = file.readLine(); @@ -681,7 +673,7 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.split(": ").last().startsWith("install"); + pkgInfo.isInstalled = lineText.split(": ").last().startsWith("install"); continue; } @@ -739,7 +731,7 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName if (lineText.isEmpty()) { pkgInfo.infosFilePath = localPkgInfosFilePath; if (pkgName == pkgInfo.pkgName) { - if (isInstalled) { + if (pkgInfo.isInstalled) { break; } } @@ -794,6 +786,9 @@ void AppManagerJob::loadAllPkgInstalledAppInfos() getPkgInfoListFromFile(pkgInfoList, "/var/lib/dpkg/status"); for (const PkgInfo &pkgInfo : pkgInfoList) { + if (!pkgInfo.isInstalled) { + continue; + } loadPkgInstalledAppInfo(pkgInfo); } } -- Gitee