diff options
author | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-17 04:32:42 -0300 |
---|---|---|
committer | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-17 04:32:42 -0300 |
commit | aca0b4b143e071f4b4390c89c86d62ba5741d088 (patch) | |
tree | 79b26192cf8aae0157dce2b02a58284208f1f30c | |
parent | 687775d5d4adc777939e5fe87e753a2d61f64faf (diff) |
aptcc: Make direct use of cache->FindPkg
-rw-r--r-- | backends/aptcc/apt-intf.cpp | 43 | ||||
-rw-r--r-- | backends/aptcc/apt-intf.h | 12 | ||||
-rw-r--r-- | backends/aptcc/pk-backend-aptcc.cpp | 18 |
3 files changed, 22 insertions, 51 deletions
diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp index 3bcba8a5..055487b1 100644 --- a/backends/aptcc/apt-intf.cpp +++ b/backends/aptcc/apt-intf.cpp @@ -115,31 +115,13 @@ void AptIntf::cancel() } } -pkgCache::PkgIterator AptIntf::findPackage(const std::string &name) -{ - // This is needed otherwise we get random crashes -// if (!m_cache.open()) { -// return pkgCache::PkgIterator(); -// } - return m_cache->FindPkg(name); -} - -pkgCache::PkgIterator AptIntf::findPackageArch(const std::string &name, const std::string &arch) -{ - // This is needed otherwise we get random crashes -// if (!m_cache.open()) { -// return pkgCache::PkgIterator(); -// } - return m_cache->FindPkg(name, arch); -} - pkgCache::VerIterator AptIntf::findPackageId(const gchar *packageId) { gchar **parts; pkgCache::PkgIterator pkg; parts = pk_package_id_split(packageId); - pkg = findPackageArch(parts[PK_PACKAGE_ID_NAME], parts[PK_PACKAGE_ID_ARCH]); + pkg = m_cache->FindPkg(parts[PK_PACKAGE_ID_NAME], parts[PK_PACKAGE_ID_ARCH]); // Ignore packages that could not be found or that exist only due to dependencies. if (pkg.end() || (pkg.VersionList().end() && pkg.ProvidesList().end())) { @@ -1192,7 +1174,7 @@ PkgList AptIntf::searchPackageFiles(gchar **values) if (m_cancel) { break; } - const pkgCache::PkgIterator &pkg = findPackage(*it); + const pkgCache::PkgIterator &pkg = m_cache->FindPkg(*it); if (pkg.end() == true) { continue; } @@ -1273,7 +1255,7 @@ void AptIntf::providesMimeType(PkgList &output, gchar **values) if (m_cancel) { break; } - const pkgCache::PkgIterator &pkg = findPackage(*it); + const pkgCache::PkgIterator &pkg = m_cache->FindPkg(*it); if (pkg.end() == true) { continue; } @@ -1283,6 +1265,21 @@ void AptIntf::providesMimeType(PkgList &output, gchar **values) } output.push_back(ver); } + + // Check if app-install-data is installed + if (output.empty()) { + // check if app-install-data is installed + pkgCache::PkgIterator pkg; + pkg = m_cache->FindPkg("app-install-data"); + if (pkg->CurrentState != pkgCache::State::Installed) { + pk_backend_error_code(m_backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "You need the app-install-data " + "package to be able to look for " + "applications that can handle " + "this kind of file"); + } + } } // used to emit files it reads the info directly from the files @@ -1619,7 +1616,7 @@ void AptIntf::emitTransactionPackage(string name, PkInfoEnum state) } } - const pkgCache::PkgIterator &pkg = findPackage(name); + const pkgCache::PkgIterator &pkg = m_cache->FindPkg(name); // Ignore packages that could not be found or that exist only due to dependencies. if (pkg.end() == true || (pkg.VersionList().end() && pkg.ProvidesList().end())) { @@ -2020,7 +2017,7 @@ PkgList AptIntf::resolvePackageIds(gchar **package_ids, PkBitfield filters) } } } else { - const pkgCache::PkgIterator &pkg = findPackage(pi); + const pkgCache::PkgIterator &pkg = m_cache->FindPkg(pi); // Ignore packages that could not be found or that exist only due to dependencies. if (pkg.end() == true || (pkg.VersionList().end() && pkg.ProvidesList().end())) { continue; diff --git a/backends/aptcc/apt-intf.h b/backends/aptcc/apt-intf.h index 4da7ba9e..48839982 100644 --- a/backends/aptcc/apt-intf.h +++ b/backends/aptcc/apt-intf.h @@ -51,18 +51,6 @@ public: void cancel(); /** - * Tries to find a package with the given package name - * @returns pkgCache::VerIterator, if .end() is true the package could not be found - */ - pkgCache::PkgIterator findPackage(const std::string &name); - - /** - * Tries to find a package with the given package name and arch - * @returns pkgCache::VerIterator, if .end() is true the package could not be found - */ - pkgCache::PkgIterator findPackageArch(const std::string &name, const std::string &arch = std::string()); - - /** * Tries to find a package with the given packageId * @returns pkgCache::VerIterator, if .end() is true the package could not be found */ diff --git a/backends/aptcc/pk-backend-aptcc.cpp b/backends/aptcc/pk-backend-aptcc.cpp index 4a4b8c38..c43ac887 100644 --- a/backends/aptcc/pk-backend-aptcc.cpp +++ b/backends/aptcc/pk-backend-aptcc.cpp @@ -498,22 +498,8 @@ static gboolean backend_what_provides_thread(PkBackend *backend) m_apt->providesMimeType(output, values); } - if (output.empty() && provides == PK_PROVIDES_ENUM_MIMETYPE) { - // check if app-install-data is installed - pkgCache::PkgIterator pkg; - pkg = m_apt->findPackage("app-install-data"); - if (pkg->CurrentState != pkgCache::State::Installed) { - pk_backend_error_code(backend, - PK_ERROR_ENUM_INTERNAL_ERROR, - "You need the app-install-data " - "package to be able to look for " - "applications that can handle " - "this kind of file"); - } - } else { - // It's faster to emit the packages here rather than in the matching part - m_apt->emitPackages(output, filters); - } + // It's faster to emit the packages here rather than in the matching part + m_apt->emitPackages(output, filters); delete m_apt; } else { |