File indexing completed on 2024-04-28 13:41:41

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2017-2020 Harald Sitter <sitter@kde.org>
0003 
0004 #include "DebugResolver.h"
0005 
0006 #include <QDebug>
0007 
0008 #include <PackageKit/Daemon>
0009 
0010 #include "Debug.h"
0011 #include "DebugPackage.h"
0012 
0013 DebugResolver::DebugResolver(std::shared_ptr<File> file, QObject *parent)
0014     : QObject(parent)
0015     , m_file(std::move(file))
0016 {
0017 }
0018 
0019 void DebugResolver::resolve()
0020 {
0021     const QStringList candidates = m_file->potentialDebugPackageCandidateNames();
0022     qCDebug(INSTALLER) << "candidates" << candidates;
0023     for (const auto &candidate : candidates) {
0024         #warning this is incredibly slow because aptcc is sequential we should instead grab all packages in a single transaction and then filter client side
0025         // NB: https://github.com/hughsie/PackageKit/issues/441
0026         auto *transaction = PackageKit::Daemon::searchNames(candidate);
0027         m_transactions << transaction;
0028         connect(transaction, &PackageKit::Transaction::finished,
0029                 this, &DebugResolver::transactionFinished);
0030         connect(transaction, &PackageKit::Transaction::package,
0031                 this, &DebugResolver::packageFound);
0032     }
0033 }
0034 
0035 void DebugResolver::transactionFinished()
0036 {
0037     m_transactions.remove(sender());
0038     if (m_transactions.isEmpty()) {
0039         emit finished();
0040     }
0041 }
0042 
0043 void DebugResolver::packageFound(PackageKit::Transaction::Info info, const QString &packageID, const QString &)
0044 {
0045     // searchNames matches the search string anywhere in the name so we need
0046     // to further filter the list to exact matches.
0047     // Otherwise foo-dbgsym will have libfoo-dbgsym as candidate even though
0048     // it may be entirely unrelated to the crash.
0049     const auto packageName = PackageKit::Daemon::packageName(packageID);
0050     if (!m_file->potentialDebugPackageCandidateNames().contains(packageName)) {
0051         return;
0052     }
0053     if (!DebugPackage(packageID).isCompatibleWith(m_file->packageID())) {
0054         qCDebug(INSTALLER) << "  -- ignoring incompatible candidate" << packageID << m_file->packageID();
0055         return;
0056     }
0057     m_file->setDebugPackageIDAndStatus(packageID, info == PackageKit::Transaction::InfoInstalled);
0058 }