diff options
author | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-16 02:26:21 -0300 |
---|---|---|
committer | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-16 02:26:21 -0300 |
commit | 2a5d5124f987281de8ad7bede501175e4ec0b848 (patch) | |
tree | 5607ed8675a469f5c22f242135de8c781fcaa15a | |
parent | 6e57f354aeca30538351acdc2fca7ddd76c0b8ad (diff) |
aptcc: A few more fixes aptcc does not crash anymore but it sort of start failing after a while
-rw-r--r-- | backends/aptcc/AptCacheFile.cpp | 23 | ||||
-rw-r--r-- | backends/aptcc/AptCacheFile.h | 13 | ||||
-rw-r--r-- | backends/aptcc/apt-intf.cpp | 20 | ||||
-rw-r--r-- | backends/aptcc/pk-backend-aptcc.cpp | 4 |
4 files changed, 40 insertions, 20 deletions
diff --git a/backends/aptcc/AptCacheFile.cpp b/backends/aptcc/AptCacheFile.cpp index 2aa66f65..94bff865 100644 --- a/backends/aptcc/AptCacheFile.cpp +++ b/backends/aptcc/AptCacheFile.cpp @@ -26,19 +26,28 @@ AptCacheFile::AptCacheFile() : AptCacheFile::~AptCacheFile() { + delete m_packageRecords; + pkgCacheFile::Close(); +} + +bool AptCacheFile::Open(bool withLock) +{ + return pkgCacheFile::Open(NULL, withLock); +} + +void AptCacheFile::Close() +{ if (m_packageRecords) { delete m_packageRecords; } -} + m_packageRecords = 0; -bool AptCacheFile::open(bool withLock) -{ - return Open(NULL, withLock); + pkgCacheFile::Close(); } -bool AptCacheFile::buildCaches(bool withLock) +bool AptCacheFile::BuildCaches(bool withLock) { - return BuildCaches(NULL, withLock); + return pkgCacheFile::BuildCaches(NULL, withLock); } void AptCacheFile::buildPkgRecords() @@ -50,5 +59,3 @@ void AptCacheFile::buildPkgRecords() // Create the text record parser m_packageRecords = new pkgRecords(*this->GetPkgCache()); } - - diff --git a/backends/aptcc/AptCacheFile.h b/backends/aptcc/AptCacheFile.h index dc884645..bb265be4 100644 --- a/backends/aptcc/AptCacheFile.h +++ b/backends/aptcc/AptCacheFile.h @@ -31,12 +31,17 @@ public: /** * Inits the package cache returning false if it can't open */ - bool open(bool withLock = false); + bool Open(bool withLock = false); + + /** + * Closes the package cache + */ + void Close(); /** * Build caches */ - bool buildCaches(bool withLock = false); + bool BuildCaches(bool withLock = false); inline pkgRecords* GetPkgRecords() { buildPkgRecords(); return m_packageRecords; } @@ -44,13 +49,13 @@ public: * GetPolicy will build the policy object if needed and return it * @note This override if because the cache should be built before the policy */ - inline pkgPolicy* GetPolicy() { BuildCaches(NULL, false); BuildPolicy(); return Policy; } + inline pkgPolicy* GetPolicy() { BuildCaches(); BuildPolicy(); return Policy; } /** * GetDepCache will build the dependency cache if needed and return it * @note This override if because the policy should be built before the dependency cache */ - inline pkgDepCache* GetDepCache() { BuildCaches(NULL, false); BuildPolicy(); BuildDepCache(); return DCache; } + inline pkgDepCache* GetDepCache() { BuildCaches(); BuildPolicy(); BuildDepCache(); return DCache; } private: void buildPkgRecords(); diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp index 2b27262c..11d13af2 100644 --- a/backends/aptcc/apt-intf.cpp +++ b/backends/aptcc/apt-intf.cpp @@ -93,8 +93,7 @@ bool AptIntf::init() setenv("ftp_proxy", ftp_proxy, 1); // Tries to open the cache -// return !m_cache.open(); - return false; // WTF why it was expecting this? + return !m_cache.Open(); } AptIntf::~AptIntf() @@ -115,12 +114,20 @@ void AptIntf::cancel() pkgCache::PkgIterator AptIntf::findPackage(const std::string &name) { - return m_cache.GetDepCache()->FindPkg(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) { - return m_cache.GetDepCache()->FindPkg(name, 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) @@ -1963,8 +1970,9 @@ PkgList AptIntf::resolvePackageIds(gchar **package_ids, PkBitfield filters) pk_backend_set_status (m_backend, PK_STATUS_ENUM_QUERY); // Don't fail if package list is empty - if (package_ids == NULL) + if (package_ids == NULL) { return ret; + } for (uint i = 0; i < g_strv_length(package_ids); ++i) { if (m_cancel) { @@ -2253,7 +2261,7 @@ bool AptIntf::runTransaction(PkgList &install, PkgList &remove, bool simulate, b AptCacheFile cache; int timeout = 10; // TODO test this - while (cache.open(withLock) == false) { + while (cache.Open(withLock) == false) { // failed to open cache, try checkDeps then.. // || cache.CheckDeps(CmdL.FileSize() != 1) == false if (withLock == false || (timeout <= 0)) { diff --git a/backends/aptcc/pk-backend-aptcc.cpp b/backends/aptcc/pk-backend-aptcc.cpp index 99a31ac2..68cee840 100644 --- a/backends/aptcc/pk-backend-aptcc.cpp +++ b/backends/aptcc/pk-backend-aptcc.cpp @@ -379,7 +379,7 @@ static gboolean backend_get_or_update_system_thread (PkBackend *backend) AptCacheFile cache; int timeout = 10; // TODO test this - while (cache.open(!getUpdates) == false) { + while (cache.Open(!getUpdates) == false) { // failed to open cache, try checkDeps then.. // || Cache.CheckDeps(CmdL.FileSize() != 1) == false if (getUpdates == true || (timeout <= 0)) { @@ -688,7 +688,7 @@ static gboolean pk_backend_refresh_cache_thread(PkBackend *backend) // Rebuild the cache. AptCacheFile cache; - if (cache.buildCaches(true) == false) { + if (cache.BuildCaches(true) == false) { if (_error->PendingError() == true) { show_errors(backend, PK_ERROR_ENUM_CANNOT_FETCH_SOURCES, true); } |