mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 01:10:16 +08:00
feat(aptssupdater): 添加包安装状态检查方法并优化更新合并逻辑
添加 isPackageInstalledInAptss 和 isPackageInstalledInApm 方法检查包安装状态 优化 mergeUpdateInfo 逻辑,根据包安装状态判断是否为迁移场景
This commit is contained in:
@@ -647,9 +647,14 @@ QJsonArray aptssUpdater::mergeUpdateInfo()
|
||||
QString aptssVersion = aptssObj["new_version"].toString();
|
||||
QString apmVersion = apmObj["new_version"].toString();
|
||||
|
||||
// 检查是否为迁移场景:APM版本更新,且当前包是通过aptss安装的
|
||||
// 通过检查aptss中是否有当前版本号来判断是否通过aptss安装
|
||||
if (apmVersion > aptssVersion) {
|
||||
// 检查包在两个源中的安装状态
|
||||
bool installedInAptss = isPackageInstalledInAptss(packageName);
|
||||
bool installedInApm = isPackageInstalledInApm(packageName);
|
||||
|
||||
// 判断是否为迁移场景:
|
||||
// 1. 只在 aptss 中安装了包(不在 apm 中安装)
|
||||
// 2. APM 版本更新
|
||||
if (installedInAptss && !installedInApm && apmVersion > aptssVersion) {
|
||||
// 迁移场景:Spark -> APM
|
||||
QJsonObject migrationObj = apmObj;
|
||||
migrationObj["is_migration"] = true;
|
||||
@@ -661,7 +666,11 @@ QJsonArray aptssUpdater::mergeUpdateInfo()
|
||||
// 同时保留aptss的更新项(如果aptss也有更新)
|
||||
mergedArray.append(aptssObj);
|
||||
} else {
|
||||
// 非迁移场景:同时展示两个来源的更新
|
||||
// 非迁移场景(共存场景):同时展示两个来源的更新
|
||||
// 包括以下情况:
|
||||
// 1. 同时在 aptss 和 apm 中都安装了包
|
||||
// 2. 只在 apm 中安装了包
|
||||
// 3. APM 版本不更新
|
||||
mergedArray.append(aptssObj);
|
||||
mergedArray.append(apmObj);
|
||||
}
|
||||
@@ -671,3 +680,30 @@ QJsonArray aptssUpdater::mergeUpdateInfo()
|
||||
qDebug()<<"合并后的更新信息:"<<mergedArray;
|
||||
return mergedArray;
|
||||
}
|
||||
|
||||
bool aptssUpdater::isPackageInstalledInAptss(const QString &packageName)
|
||||
{
|
||||
QProcess process;
|
||||
QString command = QString("dpkg -s '%1' 2>/dev/null | grep -q 'Status: install ok installed'").arg(packageName);
|
||||
process.start("bash", QStringList() << "-c" << command);
|
||||
if (!process.waitForFinished(5000)) {
|
||||
process.kill();
|
||||
return false;
|
||||
}
|
||||
return process.exitCode() == 0;
|
||||
}
|
||||
|
||||
bool aptssUpdater::isPackageInstalledInApm(const QString &packageName)
|
||||
{
|
||||
QProcess process;
|
||||
process.start("apm", QStringList() << "list" << "--installed");
|
||||
if (!process.waitForFinished(30000)) {
|
||||
process.kill();
|
||||
return false;
|
||||
}
|
||||
QString output = process.readAllStandardOutput();
|
||||
// 解析格式: pkgname/repo,section version arch [flags]
|
||||
// 或: pkgname/repo version arch [flags]
|
||||
QRegularExpression regex(QString("^%1/\\S+(?:,\\S+)?\\s+\\S+\\s+\\S+\\s+\\[").arg(QRegularExpression::escape(packageName)));
|
||||
return regex.match(output).hasMatch();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ private:
|
||||
bool checkDesktopFiles(const QStringList &desktopFiles, QString &appName, const QString &lang, const QString &packageName);
|
||||
QStringList packageName;
|
||||
QStringList apmPackageName; // APM 包列表
|
||||
|
||||
// 检查包安装状态的方法
|
||||
bool isPackageInstalledInAptss(const QString &packageName); // 检查包是否在 aptss 中已安装
|
||||
bool isPackageInstalledInApm(const QString &packageName); // 检查包是否在 apm 中已安装
|
||||
};
|
||||
|
||||
#endif // APTSSUPDATER_H
|
||||
@@ -5,7 +5,7 @@ readonly ACE_ENVIRONMENTS=(
|
||||
"deepin23-run:amber-ce-deepin23"
|
||||
"sid-run:amber-ce-sid"
|
||||
)
|
||||
dpkg -s '$1' 2>/dev/null | grep -q 'Status: install ok installed' > /dev/null 2>&1
|
||||
dpkg -s "$1" 2>/dev/null | grep -q 'Status: install ok installed' > /dev/null 2>&1
|
||||
RET="$?"
|
||||
if [[ "$RET" != "0" ]] && [[ "$IS_ACE_ENV" == "" ]];then ## 如果未在ACE环境中
|
||||
|
||||
|
||||
Reference in New Issue
Block a user