diff --git a/src/common/appmanagercommon.h b/src/common/appmanagercommon.h index fa4086e95376519ed57a688243c906ef8432ceec..25ecb709926c6a12f36ede9d225e9e2e1fd68387 100644 --- a/src/common/appmanagercommon.h +++ b/src/common/appmanagercommon.h @@ -16,6 +16,9 @@ #define GB_COUNT (1 << 30) #define TB_COUNT (long(1) << 40) +// 时间格式化字符串 +#define DATE_TIME_FORMAT_STR "yyyy-MM-dd HH:mm:ss.zzz" + namespace AM { // 运行状态 enum RunningStatus { diff --git a/src/job/appmanagerjob.cpp b/src/job/appmanagerjob.cpp index b7f1c9b4799cf37faff5b945ecc784765dcb0197..14bab5f99b5a53e6ff93945b8d5d63de628ddc64 100644 --- a/src/job/appmanagerjob.cpp +++ b/src/job/appmanagerjob.cpp @@ -616,7 +616,6 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS continue; } - if (lineText.startsWith("Description: ")) { pkgInfo.description = lineText.split(": ").last(); pkgInfo.description.append("\n"); @@ -636,6 +635,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS if (lineText.isEmpty()) { pkgInfo.infosFilePath = pkgInfosFilePath; pkgInfo.depositoryUrl = depositoryUrlStr; + pkgInfo.updatedTime = getPkgUpdatedTime(pkgInfo.pkgName, pkgInfo.arch); pkgInfoList.append(pkgInfo); pkgInfo = {}; } @@ -739,6 +739,7 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName // 检测到下一包信息 if (lineText.isEmpty()) { pkgInfo.infosFilePath = localPkgInfosFilePath; + pkgInfo.updatedTime = getPkgUpdatedTime(pkgInfo.pkgName, pkgInfo.arch); if (pkgName == pkgInfo.pkgName) { if (pkgInfo.isInstalled) { break; @@ -915,6 +916,21 @@ DesktopInfo AppManagerJob::getDesktopInfo(const QString &desktop) return desktopInfo; } +QString AppManagerJob::getPkgUpdatedTime(const QString &pkgName, const QString &arch) +{ + // 判断文件名中是否有架构名 + QString listFilePath = QString("/var/lib/dpkg/info/%1.list").arg(pkgName); + QString archContent = QFile::exists(listFilePath) ? "" : QString(":%1").arg(arch); + + QFileInfo fInfo(QString("/var/lib/dpkg/info/%1%2.list").arg(pkgName).arg(archContent)); + if (!fInfo.exists()) { + qInfo() << Q_FUNC_INFO << fInfo.fileName() << "not exists!"; + return ""; + } + + return fInfo.lastModified().toString(DATE_TIME_FORMAT_STR); +} + qint64 AppManagerJob::getUrlFileSize(QString &url, int tryTimes) { qint64 size = -1; diff --git a/src/job/appmanagerjob.h b/src/job/appmanagerjob.h index 57e73ef9ada6baa1e43139c179018cebd3802d5f..5b1a67fd960282dcd73a6726f53bfa71ff4c47aa 100644 --- a/src/job/appmanagerjob.h +++ b/src/job/appmanagerjob.h @@ -107,6 +107,7 @@ private: QStringList getAppInstalledFileList(const QString &pkgName, const QString &arch); QStringList getAppDesktopPathList(const QStringList &list, const QString &pkgName); AM::DesktopInfo getDesktopInfo(const QString &desktop); + QString getPkgUpdatedTime(const QString &pkgName, const QString &arch); qint64 getUrlFileSize(QString &url, int tryTimes = 3);