Source: libqapt
Severity: serious
User: de...@lists.debian.org
Usertags: apt-1.9.11 apt-1.9.0

The attached patch series has been applied in Ubuntu to make libqapt work with
recent APT. Except for apt-1.9.11.patch, all patches are upstream:

0001-Fix-Package-supportedUntil-never-getting-the-date.patch
apt-1.9.0.patch
apt-1.9.11.patch

These patches require a Build-Depends on apt (>= 1.9.11~).

-- System Information:
Debian Release: bullseye/sid
  APT prefers focal
  APT policy: (991, 'focal'), (500, 'focal')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.4.0-17-generic (SMP w/8 CPU cores)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- 
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en
From: Julian Andres Klode <julian.kl...@canonical.com>
Date: Wed Jun 19 12:01:15 2019 +0200
Forwarded: https://phabricator.kde.org/D21896
Subject: Port to APT 1.9.0

commit ed4f360b7f2488b6712291699e5cf70c8b0207e4

    Use APT::Progress::PackageManager for install progress

commit 926793a426611a1d044f8dd8bdb6e764a1cf8f7d

    Use ActiveSubprocess instead of Mode

commit 27f72cae73434a1da70a7f0b68f34795a6396816

    Read CurrentSize from CurrentItem rather than worker
    
    APT 1.9.0 moves CurrentSize to items, so we use CurrentItem
    for now - but that should go away so we can have multiple
    current items for http/2 later.

commit 2e7d9dff47c95f7890fbb6cad497593ce9071b4a

    worker: Include unistd.h for usleep()
    
    usleep() is defined in that header, but the header is not
    included.

commit 2cec444890da35646252f57dd425e979cc542cc9

    Use all hashes in aptWorker when acquiring files
    
    Seriously

commit cb19796f31c98be4c2e827da4850a0b0dec99afd

    Port pkgAcquire setup to use constructor
    
    The Setup() method went away, use the constructor instead.

commit b8d623587ec1707ac0f827788826e84c982ffab9

    Port Package::md5Sum()
    
    Probably want to export HashStringList instead

commit d0ec0481bb134dba3d04df63a2506a977dac63a1

    src/package.cpp: Use candidate version's section
    
    Packages do not really have a section, this moved to Version a few
    years ago (they can differ between versions). Let's just use the
    candidate's section, if there is one.

commit 912f2e7bc51208eabc1997d147bf514ab6894107

    Use GetCandidateVersion() instead of GetCandidateVer()
    
    GetCandidateVer() never actually returned the correct candidate,
    so this probably also fixes something.

commit 9253eb628a9f32e3c510c243ad1c9aa67ab6a69b

    Port pin writing to pkgTagSection::Write()

commit 46c91979a06f4a2977b220f939997dd946cc2040

    Port to APT::Upgrade

commit 674e4e541e0ce673dcf4152f2e16af738955fedf

    Use std::string instead of string
    
    APT 1.9 drops a few "using" uses in headers, so we have to use
    the namespaced name now.

commit 417dd6b4102f55a8f4c05293ee7918ec6d54503a

    Include additional headers needed in apt 1.9
    
    APT 1.9 dropped some includes from headers, so we actually
    need to include the headers we're using.

commit 2a2901a66ba37b540d40804f22c103a9abd31f55

    Ignore missing apt-inst library, merged into apt-pkg in apt 1.9
--- a/autotests/sourceslisttest.cpp
+++ b/autotests/sourceslisttest.cpp
@@ -24,6 +24,7 @@
 #include <QtTest/QtTest>
 
 #include <apt-pkg/init.h>
+#include <apt-pkg/configuration.h>
 
 QTEST_MAIN(SourcesListTest);
 
--- a/cmake/modules/FindAptPkg.cmake
+++ b/cmake/modules/FindAptPkg.cmake
@@ -23,6 +23,11 @@ FIND_PATH( APTPKG_INCLUDE_DIR apt-pkg/in
 FIND_LIBRARY(APTPKG_LIBRARY_RELEASE NAMES apt-pkg )
 FIND_LIBRARY(APTINST_LIBRARY NAMES apt-inst )
 
+# apt-inst is optional these days!
+IF ( NOT APTINST_LIBRARY )
+    SET( APTINST_LIBRARY "" )
+ENDIF( )
+
 FIND_LIBRARY(APTPKG_LIBRARY_DEBUG NAMES apt-pkg apt-pkgd  HINTS /usr/lib/debug/usr/lib/ )
 
 IF( APTPKG_LIBRARY_RELEASE OR APTPKG_LIBRARY_DEBUG AND APTPKG_INCLUDE_DIR )
--- a/src/backend.cpp
+++ b/src/backend.cpp
@@ -26,6 +26,7 @@
 #include <QtDBus/QDBusConnection>
 
 // Apt includes
+#include <apt-pkg/acquire.h>
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/depcache.h>
@@ -33,10 +34,13 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/gpgv.h>
 #include <apt-pkg/init.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/tagfile.h>
+#include <apt-pkg/upgrade.h>
 
 // Xapian includes
 #undef slots
@@ -324,7 +328,7 @@ void Backend::setInitError()
 {
     Q_D(Backend);
 
-    string message;
+    std::string message;
     if (_error->PopMessage(message))
         d->initErrorMessage = QString::fromStdString(message);
 }
@@ -356,7 +360,7 @@ void Backend::loadPackagePins()
 
         pkgTagSection tags;
         while (tagFile.Step(tags)) {
-            string name = tags.FindS("Package");
+            std::string name = tags.FindS("Package");
             Package *pkg = package(QLatin1String(name.c_str()));
             if (pkg)
                 pkg->setPinned(true);
@@ -635,7 +639,7 @@ PackageList Backend::search(const QStrin
         return QApt::PackageList();
     }
 
-    string unsplitSearchString = searchString.toStdString();
+    std::string unsplitSearchString = searchString.toStdString();
     static int qualityCutoff = 15;
     PackageList searchResult;
 
@@ -660,8 +664,8 @@ PackageList Backend::search(const QStrin
         * index is built with the full package name
         */
         // Always search for the package name
-        string xpString = "name:";
-        string::size_type pos = unsplitSearchString.find_first_of(" ,;");
+        std::string xpString = "name:";
+        std::string::size_type pos = unsplitSearchString.find_first_of(" ,;");
         if (pos > 0) {
             xpString += unsplitSearchString.substr(0,pos);
         } else {
@@ -670,7 +674,7 @@ PackageList Backend::search(const QStrin
         Xapian::Query xpQuery = parser.parse_query(xpString);
 
         pos = 0;
-        while ( (pos = unsplitSearchString.find("-", pos)) != string::npos ) {
+        while ( (pos = unsplitSearchString.find("-", pos)) != std::string::npos ) {
             unsplitSearchString.replace(pos, 1, " ");
             pos+=1;
         }
@@ -1022,7 +1026,7 @@ void Backend::markPackagesForUpgrade()
 {
     Q_D(Backend);
 
-    pkgAllUpgrade(*d->cache->depCache());
+    APT::Upgrade::Upgrade(*d->cache->depCache(), APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
     emit packageChanged();
 }
 
@@ -1030,7 +1034,7 @@ void Backend::markPackagesForDistUpgrade
 {
     Q_D(Backend);
 
-    pkgDistUpgrade(*d->cache->depCache());
+    APT::Upgrade::Upgrade(*d->cache->depCache(), APT::Upgrade::ALLOW_EVERYTHING);
     emit packageChanged();
 }
 
@@ -1513,8 +1517,8 @@ bool Backend::setPackagePinned(Package *
             tempFile.close();
 
             QString tempFileName = tempFile.fileName();
-            FILE *out = fopen(tempFileName.toUtf8(), "w");
-            if (!out) {
+            FileFd out(tempFileName.toUtf8().toStdString(), FileFd::WriteOnly|FileFd::Create|FileFd::Empty);
+            if (!out.IsOpen()) {
                 return false;
             }
 
@@ -1522,7 +1526,6 @@ bool Backend::setPackagePinned(Package *
 
             pkgTagFile tagFile(&Fd);
             if (_error->PendingError()) {
-                fclose(out);
                 return false;
             }
 
@@ -1536,15 +1539,11 @@ bool Backend::setPackagePinned(Package *
 
                 // Include all but the matching name in the new pinfile
                 if (name != package->name()) {
-                    TFRewriteData tfrd;
-                    tfrd.Tag = 0;
-                    tfrd.Rewrite = 0;
-                    tfrd.NewTag = 0;
-                    TFRewrite(out, tags, TFRewritePackageOrder, &tfrd);
-                    fprintf(out, "\n");
+                    tags.Write(out, TFRewritePackageOrder, {});
+                    out.Write("\n", 1);
                 }
             }
-            fclose(out);
+            out.Close();
 
             if (!tempFile.open()) {
                 return false;
--- a/src/dependencyinfo.cpp
+++ b/src/dependencyinfo.cpp
@@ -102,11 +102,11 @@ DependencyInfo &DependencyInfo::operator
 
 QList<DependencyItem> DependencyInfo::parseDepends(const QString &field, DependencyType type)
 {
-    string package;
-    string version;
+    std::string package;
+    std::string version;
     unsigned int op;
 
-    string fieldStr = field.toStdString();
+    std::string fieldStr = field.toStdString();
 
     const char *start = fieldStr.c_str();
     const char *stop = start + strlen(start);
--- a/src/package.cpp
+++ b/src/package.cpp
@@ -41,6 +41,7 @@
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/init.h>
 #include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/tagfile.h>
@@ -212,7 +213,10 @@ int Package::id() const
 
 QLatin1String Package::section() const
 {
-    return QLatin1String(d->packageIter.Section());
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
+    if (!ver.end())
+        return QLatin1String(ver.Section());
+    return QLatin1String("");
 }
 
 QString Package::sourcePackage() const
@@ -222,7 +226,7 @@ QString Package::sourcePackage() const
     // In the APT package record format, the only time when a "Source:" field
     // is present is when the binary package name doesn't match the source
     // name
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (!ver.end()) {
         pkgRecords::Parser &rec = d->backend->records()->Lookup(ver.FileList());
         sourcePackage = QString::fromStdString(rec.SourcePkg());
@@ -240,7 +244,7 @@ QString Package::sourcePackage() const
 QString Package::shortDescription() const
 {
     QString shortDescription;
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (!ver.end()) {
         pkgCache::DescIterator Desc = ver.TranslatedDescription();
         pkgRecords::Parser & parser = d->backend->records()->Lookup(Desc.FileList());
@@ -253,7 +257,7 @@ QString Package::shortDescription() cons
 
 QString Package::longDescription() const
 {
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if (!ver.end()) {
         QString rawDescription;
@@ -298,7 +302,7 @@ QString Package::longDescription() const
 QString Package::maintainer() const
 {
     QString maintainer;
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (!ver.end()) {
         pkgRecords::Parser &parser = d->backend->records()->Lookup(ver.FileList());
         maintainer = QString::fromUtf8(parser.Maintainer().data());
@@ -312,7 +316,7 @@ QString Package::maintainer() const
 QString Package::homepage() const
 {
     QString homepage;
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (!ver.end()) {
         pkgRecords::Parser &parser = d->backend->records()->Lookup(ver.FileList());
         homepage = QString::fromUtf8(parser.Homepage().data());
@@ -416,7 +420,7 @@ QString Package::availableVersion() cons
 
 QString Package::priority() const
 {
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (ver.end())
         return QString();
 
@@ -468,7 +472,7 @@ QStringList Package::installedFilesList(
 
 QString Package::origin() const
 {
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if(Ver.end())
         return QString();
@@ -479,7 +483,7 @@ QString Package::origin() const
 
 QString Package::site() const
 {
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if(Ver.end())
         return QString();
@@ -490,7 +494,7 @@ QString Package::site() const
 
 QStringList Package::archives() const
 {
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if(Ver.end())
         return QStringList();
@@ -518,20 +522,22 @@ QString Package::component() const
 
 QByteArray Package::md5Sum() const
 {
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if(ver.end())
         return QByteArray();
 
     pkgRecords::Parser &rec = d->backend->records()->Lookup(ver.FileList());
 
-    return rec.MD5Hash().c_str();
+    auto MD5HashString = rec.Hashes().find("MD5Sum");
+
+    return MD5HashString ? QByteArray::fromStdString(MD5HashString->HashValue()) : "";
 
 }
 
 QUrl Package::changelogUrl() const
 {
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (ver.end())
         return QUrl();
 
@@ -603,7 +609,7 @@ QDateTime Package::supportedUntil() cons
 
 QString Package::controlField(QLatin1String name) const
 {
-    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     if (ver.end()) {
         return QString();
     }
@@ -705,8 +711,8 @@ int Package::compareVersion(const QStrin
 {
     // Make deep copies of toStdString(), since otherwise they would
     // go out of scope when we call c_str()
-    string s1 = v1.toStdString();
-    string s2 = v2.toStdString();
+    std::string s1 = v1.toStdString();
+    std::string s2 = v2.toStdString();
 
     const char *a = s1.c_str();
     const char *b = s2.c_str();
@@ -995,7 +1001,7 @@ QStringList Package::recommendsList() co
 {
     QStringList recommends;
 
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if (Ver.end()) {
         return recommends;
@@ -1021,7 +1027,7 @@ QStringList Package::suggestsList() cons
 {
     QStringList suggests;
 
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if (Ver.end()) {
         return suggests;
@@ -1047,7 +1053,7 @@ QStringList Package::enhancesList() cons
 {
     QStringList enhances;
 
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if (Ver.end()) {
         return enhances;
@@ -1085,7 +1091,7 @@ QStringList Package::enhancedByList() co
 
 QList<QApt::MarkingErrorInfo> Package::brokenReason() const
 {
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
     QList<MarkingErrorInfo> reasons;
 
     // check if there is actually something to install
@@ -1160,7 +1166,7 @@ QList<QApt::MarkingErrorInfo> Package::b
 
 bool Package::isTrusted() const
 {
-    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVer(d->packageIter);
+    const pkgCache::VerIterator &Ver = (*d->backend->cache()->depCache()).GetCandidateVersion(d->packageIter);
 
     if (!Ver)
         return false;
--- a/src/worker/aptworker.cpp
+++ b/src/worker/aptworker.cpp
@@ -37,6 +37,11 @@
 #include <apt-pkg/init.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/update.h>
+#include <apt-pkg/upgrade.h>
+#include <apt-pkg/versionmatch.h>
 #include <string>
 
 // System includes
@@ -299,15 +304,14 @@ void AptWorker::updateCache()
     acquire->setTransaction(m_trans);
 
     // Initialize fetcher with our progress watcher
-    pkgAcquire fetcher;
-    fetcher.Setup(acquire);
+    pkgAcquire fetcher(acquire);
 
     // Fetch the lists.
     if (!ListUpdate(*acquire, *m_cache->GetSourceList())) {
         if (!m_trans->isCancelled()) {
             m_trans->setError(QApt::FetchError);
 
-            string message;
+            std::string message;
             while(_error->PopMessage(message))
                 m_trans->setErrorDetails(m_trans->errorDetails() +
                                          QString::fromStdString(message));
@@ -417,7 +421,7 @@ bool AptWorker::markChanges()
     {
         // We've failed to mark the packages
         m_trans->setError(QApt::MarkingError);
-        string message;
+        std::string message;
         if (_error->PopMessage(message))
             m_trans->setErrorDetails(QString::fromStdString(message));
 
@@ -430,9 +434,9 @@ bool AptWorker::markChanges()
 void AptWorker::upgradeSystem()
 {
     if (m_trans->safeUpgrade())
-        pkgAllUpgrade(*m_cache);
+        APT::Upgrade::Upgrade(*m_cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
     else
-        pkgDistUpgrade(*m_cache);
+        APT::Upgrade::Upgrade(*m_cache, APT::Upgrade::ALLOW_EVERYTHING);
 
     commitChanges();
 }
@@ -443,8 +447,7 @@ void AptWorker::commitChanges()
     WorkerAcquire *acquire = new WorkerAcquire(this, 15, 50);
     acquire->setTransaction(m_trans);
 
-    pkgAcquire fetcher;
-    fetcher.Setup(acquire);
+    pkgAcquire fetcher(acquire);
 
     pkgPackageManager *packageManager;
     packageManager = _system->CreatePM(*m_cache);
@@ -462,7 +465,7 @@ void AptWorker::commitChanges()
     double FetchPBytes = fetcher.PartialPresent();
 
     struct statvfs Buf;
-    string OutputDir = _config->FindDir("Dir::Cache::Archives");
+    std::string OutputDir = _config->FindDir("Dir::Cache::Archives");
     if (statvfs(OutputDir.c_str(),&Buf) != 0) {
         m_trans->setError(QApt::DiskSpaceError);
         delete acquire;
@@ -570,8 +573,7 @@ void AptWorker::downloadArchives()
     WorkerAcquire *acquire = new WorkerAcquire(this, 15, 100);
     acquire->setTransaction(m_trans);
 
-    pkgAcquire fetcher;
-    fetcher.Setup(acquire);
+    pkgAcquire fetcher(acquire);
 
     pkgIndexFile *index;
 
@@ -581,7 +583,7 @@ void AptWorker::downloadArchives()
         if (!iter)
             continue; // Package not found
 
-        pkgCache::VerIterator ver = (*m_cache)->GetCandidateVer(iter);
+        pkgCache::VerIterator ver = (*m_cache)->GetCandidateVersion(iter);
 
         if (!ver || !ver.Downloadable() || !ver.Arch())
             continue; // Virtual package or not downloadable or broken
@@ -594,8 +596,8 @@ void AptWorker::downloadArchives()
         if (!m_cache->GetSourceList()->FindIndex(vf.File(), index))
             continue;
 
-        string fileName = rec.FileName();
-        string MD5sum = rec.MD5Hash();
+        std::string fileName = rec.FileName();
+        auto hashes = rec.Hashes();
 
         if (fileName.empty()) {
             m_trans->setError(QApt::NotFoundError);
@@ -606,7 +608,7 @@ void AptWorker::downloadArchives()
 
         new pkgAcqFile(&fetcher,
                        index->ArchiveURI(fileName),
-                       MD5sum,
+                       hashes,
                        ver->Size,
                        index->ArchiveInfo(ver),
                        ver.ParentPkg().Name(),
--- a/src/worker/workeracquire.cpp
+++ b/src/worker/workeracquire.cpp
@@ -35,6 +35,8 @@
 #include "aptworker.h"
 #include "transaction.h"
 
+#include <unistd.h>
+
 using namespace std;
 
 WorkerAcquire::WorkerAcquire(QObject *parent, int begin, int end)
@@ -151,7 +153,11 @@ bool WorkerAcquire::Pulse(pkgAcquire *Ow
             continue;
         }
 
+#if APT_PKG_ABI >= 590
+        (*iter->CurrentItem).Owner->PartialSize = iter->CurrentItem->CurrentSize;
+#else
         (*iter->CurrentItem).Owner->PartialSize = iter->CurrentSize;
+#endif
 
         updateStatus(*iter->CurrentItem);
     }
@@ -227,8 +233,8 @@ void WorkerAcquire::updateStatus(const p
 
     if (downloadStatus == QApt::DoneState && errorMsg.size())
         message = errorMsg;
-    else if (Itm.Owner->Mode)
-        message = QString::fromUtf8(Itm.Owner->Mode);
+    else if (!Itm.Owner->ActiveSubprocess.empty())
+        message = QString::fromStdString(Itm.Owner->ActiveSubprocess);
 
     QApt::DownloadProgress dp(URI, downloadStatus, shortDesc,
                               fileSize, fetchedSize, message);
--- a/src/worker/workeracquire.h
+++ b/src/worker/workeracquire.h
@@ -41,7 +41,7 @@ public:
     void Done(pkgAcquire::ItemDesc &Itm);
     void Fail(pkgAcquire::ItemDesc &Itm);
     void Stop();
-    bool MediaChange(string Media, string Drive);
+    bool MediaChange(std::string Media, std::string Drive);
 
     bool Pulse(pkgAcquire *Owner);
 
--- a/src/worker/workerinstallprogress.cpp
+++ b/src/worker/workerinstallprogress.cpp
@@ -27,6 +27,7 @@
 #include <QDebug>
 
 #include <apt-pkg/error.h>
+#include <apt-pkg/install-progress.h>
 
 #include <errno.h>
 #include <sys/statvfs.h>
@@ -34,6 +35,7 @@
 #include <sys/wait.h>
 #include <sys/fcntl.h>
 #include <pty.h>
+#include <unistd.h>
 
 #include <iostream>
 #include <stdlib.h>
@@ -107,7 +109,8 @@ pkgPackageManager::OrderResult WorkerIns
         // close pipe we don't need
         close(readFromChildFD[0]);
 
-        res = pm->DoInstallPostFork(readFromChildFD[1]);
+        APT::Progress::PackageManagerProgressFd progress(readFromChildFD[1]);
+        res = pm->DoInstallPostFork(&progress);
 
         // dump errors into cerr (pass it to the parent process)
         _error->DumpErrors();
--- a/utils/qapt-deb-installer/DebInstaller.cpp
+++ b/utils/qapt-deb-installer/DebInstaller.cpp
@@ -335,8 +335,8 @@ QApt::PackageList DebInstaller::checkCon
                 continue;
             }
 
-            string pkgVer = pkg->version().toStdString();
-            string depVer = info.packageVersion().toStdString();
+            std::string pkgVer = pkg->version().toStdString();
+            std::string depVer = info.packageVersion().toStdString();
 
             ok = _system->VS->CheckDep(pkgVer.c_str(),
                                        info.relationType(),
@@ -359,7 +359,7 @@ QApt::PackageList DebInstaller::checkCon
 QApt::Package *DebInstaller::checkBreaksSystem()
 {
     QApt::PackageList systemPackages = m_backend->availablePackages();
-    string debVer = m_debFile->version().toStdString();
+    std::string debVer = m_debFile->version().toStdString();
 
     foreach (QApt::Package *pkg, systemPackages) {
         if (!pkg->isInstalled()) {
@@ -373,7 +373,7 @@ QApt::Package *DebInstaller::checkBreaks
                     continue;
                 }
 
-                string depVer = dep.packageVersion().toStdString();
+                std::string depVer = dep.packageVersion().toStdString();
 
                 if (!_system->VS->CheckDep(debVer.c_str(), dep.relationType(),
                                            depVer.c_str())) {
@@ -390,7 +390,7 @@ QApt::Package *DebInstaller::checkBreaks
                     continue;
                 }
 
-                string conflictVer = conflict.packageVersion().toStdString();
+                std::string conflictVer = conflict.packageVersion().toStdString();
 
                 if (_system->VS->CheckDep(debVer.c_str(),
                                           conflict.relationType(),
@@ -419,11 +419,11 @@ bool DebInstaller::satisfyDepends()
                 continue;
             }
 
-            string debVersion = dep.packageVersion().toStdString();
+            std::string debVersion = dep.packageVersion().toStdString();
 
             // If we're installed, see if we already satisfy the dependency
             if (pkg->isInstalled()) {
-                string pkgVersion = pkg->installedVersion().toStdString();
+                std::string pkgVersion = pkg->installedVersion().toStdString();
 
                 if (_system->VS->CheckDep(pkgVersion.c_str(),
                                           dep.relationType(),
@@ -434,7 +434,7 @@ bool DebInstaller::satisfyDepends()
             }
 
             // else check if cand ver will satisfy, then mark
-            string candVersion = pkg->availableVersion().toStdString();
+            std::string candVersion = pkg->availableVersion().toStdString();
 
             if (!_system->VS->CheckDep(candVersion.c_str(),
                                        dep.relationType(),
Description: Adapt to apt 1.9.11
 The individual hash classes are gone, replaced with Hashes
 class.
Author: Julian Andres Klode <juli...@ubuntu.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2020-02-27

--- libqapt-3.0.4.orig/src/debfile.cpp
+++ libqapt-3.0.4/src/debfile.cpp
@@ -27,7 +27,7 @@
 
 #include <apt-pkg/debfile.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/md5.h>
+#include <apt-pkg/hashes.h>
 #include <apt-pkg/tagfile.h>
 
 #include <QDebug>
@@ -193,13 +193,13 @@ QByteArray DebFile::md5Sum() const
 {
     FileFd in(d->filePath.toStdString(), FileFd::ReadOnly);
     debDebFile deb(in);
-    MD5Summation debMD5;
+    Hashes debMD5(Hashes::MD5SUM);
 
     in.Seek(0);
 
     debMD5.AddFD(in.Fd(), in.Size());
 
-    return QByteArray(debMD5.Result().Value().c_str());
+    return QByteArray(debMD5.GetHashString(Hashes::MD5SUM).HashValue().c_str());
 }
 
 QStringList DebFile::fileList() const
>From 82d06c9da5952f40a07dfbbc4257fd35837b288c Mon Sep 17 00:00:00 2001
From: Carlo Vanini <silh...@gmail.com>
Date: Fri, 21 Dec 2018 21:18:31 +0100
Origin: https://cgit.kde.org/libqapt.git/commit/?id=82d06c9da5952f40a07dfbbc4257fd35837b288c
Subject: [PATCH] Fix Package::supportedUntil never getting the date

Summary:
We were expecting to find a Release file, but package archives have
moved from Release files to InRelease files, which have inlined GPG
signature.

Moreover, we try to get the release date from `distro-info/ubuntu.csv` and prefer it over the [In]Release file.
We get the release Id and Codename from `/etc/os-release`, which is more modern than `lsb-release`.

Reviewers: sitter

Reviewed By: sitter

Differential Revision: https://phabricator.kde.org/D13662
---
 CMakeLists.txt  |   2 +-
 src/backend.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/backend.h   |  13 ++++++
 src/package.cpp |  80 ++-------------------------------
 src/package.h   |   3 +-
 5 files changed, 135 insertions(+), 79 deletions(-)

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,7 +26,7 @@ include(ECMGeneratePriFile) # This needs
 # Turn exceptions on
 kde_enable_exceptions()
 
-set(REQUIRED_QT_VERSION 5.2.0) # Used in QAptConfig
+set(REQUIRED_QT_VERSION 5.8.0) # Used in QAptConfig
 find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED DBus Widgets)
 
 find_package(Xapian REQUIRED)
--- a/src/backend.cpp
+++ b/src/backend.cpp
@@ -31,6 +31,7 @@
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/gpgv.h>
 #include <apt-pkg/init.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/sourcelist.h>
@@ -85,6 +86,11 @@ public:
     // Relation of an origin and its hostname
     QHash<QString, QString> siteMap;
 
+    // Date when the distribution's release was issued. See Backend::releaseDate()
+    QDateTime releaseDate;
+    QDateTime getReleaseDateFromDistroInfo(const QString &releaseId, const QString &releaseCodename) const;
+    QDateTime getReleaseDateFromArchive(const QString &releaseId, const QString &releaseCodename) const;
+
     // Counts
     int installedCount;
 
@@ -121,6 +127,68 @@ public:
     QApt::FrontendCaps frontendCaps;
 };
 
+QDateTime BackendPrivate::getReleaseDateFromDistroInfo(const QString &releaseId, const QString &releaseCodename) const
+{
+    QDateTime releaseDate;
+    QString line;
+    QStringList split;
+
+    QFile distro_info(QStringLiteral("/usr/share/distro-info/%1.csv").arg(releaseId.toLower()));
+    if (distro_info.open(QFile::ReadOnly)) {
+        QTextStream info_stream(&distro_info);
+        line = info_stream.readLine();
+        split = line.split(QLatin1Char(','));
+        const int codenameColumn = split.indexOf(QStringLiteral("series"));
+        const int releaseColumn = split.indexOf(QStringLiteral("release"));
+        if (codenameColumn == -1 || releaseColumn == -1) {
+            return QDateTime();
+        }
+        do {
+            line = info_stream.readLine();
+            split = line.split(QLatin1Char(','));
+            if (split.value(codenameColumn) == releaseCodename) {
+                releaseDate = QDateTime::fromString(split.value(releaseColumn), Qt::ISODate);
+                releaseDate.setTimeSpec(Qt::UTC);;
+                break;
+            }
+        } while (!line.isNull());
+    }
+    return releaseDate;
+}
+
+QDateTime BackendPrivate::getReleaseDateFromArchive(const QString &releaseId, const QString &releaseCodename) const
+{
+    pkgDepCache *depCache = cache->depCache();
+
+    // We are only interested in `*ubuntu_dists_<codename>_[In]Release`
+    // in order to get the release date. In `<codename>-updates` and
+    // `-security` the Date gets updated throughout the life of the release.
+    pkgCache::RlsFileIterator rls;
+    for (rls = depCache->GetCache().RlsFileBegin(); !rls.end(); ++rls) {
+        if (rls.Origin() == releaseId
+                && rls.Label() == releaseId
+                && rls.Archive() == releaseCodename) {
+
+            FileFd fd;
+            if (!OpenMaybeClearSignedFile(rls.FileName(), fd)) {
+                continue;
+            }
+
+            time_t releaseDate = -1;
+            pkgTagSection sec;
+            pkgTagFile tag(&fd);
+            tag.Step(sec);
+
+            if(!RFC1123StrToTime(sec.FindS("Date").data(), releaseDate)) {
+                continue;
+            }
+
+            return QDateTime::fromSecsSinceEpoch(releaseDate);
+        }
+    }
+    return QDateTime();
+}
+
 bool BackendPrivate::writeSelectionFile(const QString &selectionDocument, const QString &path) const
 {
     QFile file(path);
@@ -245,6 +313,8 @@ bool Backend::reloadCache()
     // Determine which packages are pinned for display purposes
     loadPackagePins();
 
+    loadReleaseDate();
+
     emit cacheReloadFinished();
 
     return true;
@@ -294,6 +364,45 @@ void Backend::loadPackagePins()
     }
 }
 
+void Backend::loadReleaseDate()
+{
+    Q_D(Backend);
+
+    // Reset value in case we are re-loading cache
+    d->releaseDate = QDateTime();
+
+    QString releaseId;
+    QString releaseCodename;
+
+    QFile lsb_release(QLatin1String("/etc/os-release"));
+    if (!lsb_release.open(QFile::ReadOnly)) {
+        // Though really, your system is screwed if this happens...
+        return;
+    }
+
+    QTextStream stream(&lsb_release);
+    QString line;
+    do {
+        line = stream.readLine();
+        QStringList split = line.split(QLatin1Char('='));
+        if (split.size() != 2) {
+            continue;
+        }
+
+        if (split.at(0) == QLatin1String("VERSION_CODENAME")) {
+            releaseCodename = split.at(1);
+        } else if (split.at(0) == QLatin1String("ID")) {
+            releaseId = split.at(1);
+        }
+    } while (!line.isNull());
+
+    d->releaseDate = d->getReleaseDateFromDistroInfo(releaseId, releaseCodename);
+    if (!d->releaseDate.isValid()) {
+        // If we could not find the date in the csv file, we fallback to Apt archive.
+        d->releaseDate = d->getReleaseDateFromArchive(releaseId, releaseCodename);
+    }
+}
+
 QString Backend::initErrorMessage() const
 {
     Q_D(const Backend);
@@ -638,6 +747,13 @@ QString Backend::nativeArchitecture() co
     return d->nativeArch;
 }
 
+QDateTime Backend::releaseDate() const
+{
+    Q_D(const Backend);
+
+    return d->releaseDate;
+}
+
 bool Backend::areChangesMarked() const
 {
     return (toInstallCount() + toRemoveCount());
--- a/src/backend.h
+++ b/src/backend.h
@@ -111,6 +111,18 @@ public:
     QString nativeArchitecture() const;
 
     /**
+     * Returns the date when the distribution release was issued.
+     *
+     * E.g. for Ubuntu 18.04.1 it returns Thu, 26 Apr 2018 23:37:48 UTC.
+     *
+     * @return Distribution release date or invalid QDateTime if could not
+     * be determined.
+     *
+     * @since 3.1
+     */
+    QDateTime releaseDate() const;
+
+    /**
      * Returns whether the undo stack is empty
      */
     bool isUndoStackEmpty() const;
@@ -452,6 +464,7 @@ private:
 
     void setInitError();
     void loadPackagePins();
+    void loadReleaseDate();
 
 Q_SIGNALS:
     /**
--- a/src/package.cpp
+++ b/src/package.cpp
@@ -85,7 +85,6 @@ class PackagePrivate
         bool inUpdatePhaseCalculated;
 
         pkgCache::PkgFileIterator searchPkgFileIter(QLatin1String label, const QString &release) const;
-        QString getReleaseFileForOrigin(QLatin1String label, const QString &release) const;
 
         // Calculate state flags that cannot change
         void initStaticState(const pkgCache::VerIterator &ver, pkgDepCache::StateCache &stateCache);
@@ -119,40 +118,6 @@ pkgCache::PkgFileIterator PackagePrivate
     return found;
 }
 
-QString PackagePrivate::getReleaseFileForOrigin(QLatin1String label, const QString &release) const
-{
-    pkgCache::PkgFileIterator pkg = searchPkgFileIter(label, release);
-
-    // Return empty if no package matches the given label and release
-    if (pkg.end())
-        return QString();
-
-    // Search for the matching meta-index
-    pkgSourceList *list = backend->packageSourceList();
-    pkgIndexFile *index;
-
-    // Return empty if the source list doesn't contain an index for the package
-    if (!list->FindIndex(pkg, index))
-        return QString();
-
-    for (auto I = list->begin(); I != list->end(); ++I) {
-        vector<pkgIndexFile *> *ifv = (*I)->GetIndexFiles();
-        if (find(ifv->begin(), ifv->end(), index) == ifv->end())
-            continue;
-
-        // Construct release file path
-        QString uri = backend->config()->findDirectory("Dir::State::lists")
-                % QString::fromStdString(URItoFileName((*I)->GetURI()))
-                % QLatin1String("dists_")
-                % QString::fromStdString((*I)->GetDist())
-                % QLatin1String("_Release");
-
-        return uri;
-    }
-
-    return QString();
-}
-
 void PackagePrivate::initStaticState(const pkgCache::VerIterator &ver, pkgDepCache::StateCache &stateCache)
 {
     int packageState = 0;
@@ -608,45 +573,8 @@ QDateTime Package::supportedUntil() cons
         return QDateTime();
     }
 
-    QFile lsb_release(QLatin1String("/etc/lsb-release"));
-    if (!lsb_release.open(QFile::ReadOnly)) {
-        // Though really, your system is screwed if this happens...
-        return QDateTime();
-    }
-
-    pkgTagSection sec;
-    time_t releaseDate = -1;
-    QString release;
-
-    QTextStream stream(&lsb_release);
-    QString line;
-    do {
-        line = stream.readLine();
-        QStringList split = line.split(QLatin1Char('='));
-        if (split.size() != 2) {
-            continue;
-        }
-
-        if (split.at(0) == QLatin1String("DISTRIB_CODENAME")) {
-            release = split.at(1);
-        }
-    } while (!line.isNull());
-
-    // Canonical only provides support for Ubuntu, but we don't have to worry
-    // about Debian systems as long as we assume that this function can fail.
-    QString releaseFile = d->getReleaseFileForOrigin(QLatin1String("Ubuntu"), release);
-
-    if(!FileExists(releaseFile.toStdString())) {
-        // happens e.g. when there is no release file and is harmless
-        return QDateTime();
-    }
-
-    // read the relase file
-    FileFd fd(releaseFile.toStdString(), FileFd::ReadOnly);
-    pkgTagFile tag(&fd);
-    tag.Step(sec);
-
-    if(!RFC1123StrToTime(sec.FindS("Date").data(), releaseDate)) {
+    QDateTime releaseDate = d->backend->releaseDate();
+    if (!releaseDate.isValid()) {
         return QDateTime();
     }
 
@@ -665,9 +593,9 @@ QDateTime Package::supportedUntil() cons
     QDateTime supportEnd;
 
     if (unit == QLatin1Char('m')) {
-        supportEnd = QDateTime::fromTime_t(releaseDate).addMonths(supportTime);
+        supportEnd = releaseDate.addMonths(supportTime);
     } else if (unit == QLatin1Char('y')) {
-        supportEnd = QDateTime::fromTime_t(releaseDate).addYears(supportTime);
+        supportEnd = releaseDate.addYears(supportTime);
     }
 
     return supportEnd;
--- a/src/package.h
+++ b/src/package.h
@@ -257,8 +257,7 @@ public:
     * Returns the date when Canonical's support of the package ends.
     *
     * \return The date that the package is supported until. If it is not
-    *         supported now, then it will return an empty QString. The date
-    *         will be localized in the "month year" format.
+    *         supported now, then it will return an invalid date.
     */
     QDateTime supportedUntil() const;
 

Reply via email to