summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefile.cc34
-rw-r--r--apt-pkg/cachefile.h27
-rw-r--r--apt-pkg/cacheset.cc110
-rw-r--r--apt-pkg/cacheset.h6
-rw-r--r--apt-pkg/depcache.cc15
5 files changed, 153 insertions, 39 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index 690776266..ed3c2dd0a 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -35,10 +35,13 @@
#include <apti18n.h>
/*}}}*/
// CacheFile::CacheFile - Constructor /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-pkgCacheFile::pkgCacheFile() : d(NULL), Map(NULL), Cache(NULL), DCache(NULL),
- SrcList(NULL), Policy(NULL)
+pkgCacheFile::pkgCacheFile() : d(NULL), ExternOwner(false), Map(NULL), Cache(NULL),
+ DCache(NULL), SrcList(NULL), Policy(NULL)
+{
+}
+pkgCacheFile::pkgCacheFile(pkgDepCache * const Owner) : d(NULL), ExternOwner(true),
+ Map(&Owner->GetCache().GetMap()), Cache(&Owner->GetCache()),
+ DCache(Owner), SrcList(NULL), Policy(NULL)
{
}
/*}}}*/
@@ -47,12 +50,16 @@ pkgCacheFile::pkgCacheFile() : d(NULL), Map(NULL), Cache(NULL), DCache(NULL),
/* */
pkgCacheFile::~pkgCacheFile()
{
- delete DCache;
+ if (ExternOwner == false)
+ {
+ delete DCache;
+ delete Cache;
+ delete Map;
+ }
delete Policy;
delete SrcList;
- delete Cache;
- delete Map;
- _system->UnLock(true);
+ if (ExternOwner == false)
+ _system->UnLock(true);
}
/*}}}*/
// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
@@ -229,11 +236,16 @@ void pkgCacheFile::RemoveCaches()
/* */
void pkgCacheFile::Close()
{
- delete DCache;
+ if (ExternOwner == false)
+ {
+ delete DCache;
+ delete Cache;
+ delete Map;
+ }
+ else
+ ExternOwner = false;
delete Policy;
- delete Cache;
delete SrcList;
- delete Map;
_system->UnLock(true);
Map = NULL;
diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h
index 83dd90d36..f4cadf5e6 100644
--- a/apt-pkg/cachefile.h
+++ b/apt-pkg/cachefile.h
@@ -38,9 +38,9 @@ class pkgCacheFile
{
/** \brief dpointer placeholder (for later in case we need it) */
void * const d;
+ bool ExternOwner;
protected:
-
MMap *Map;
pkgCache *Cache;
pkgDepCache *DCache;
@@ -50,18 +50,18 @@ class pkgCacheFile
pkgPolicy *Policy;
// We look pretty much exactly like a pointer to a dep cache
- inline operator pkgCache &() {return *Cache;};
- inline operator pkgCache *() {return Cache;};
- inline operator pkgDepCache &() {return *DCache;};
- inline operator pkgDepCache *() {return DCache;};
- inline operator pkgPolicy &() {return *Policy;};
- inline operator pkgPolicy *() {return Policy;};
- inline operator pkgSourceList &() {return *SrcList;};
- inline operator pkgSourceList *() {return SrcList;};
- inline pkgDepCache *operator ->() {return DCache;};
- inline pkgDepCache &operator *() {return *DCache;};
- inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];};
- inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};
+ inline operator pkgCache &() const {return *Cache;};
+ inline operator pkgCache *() const {return Cache;};
+ inline operator pkgDepCache &() const {return *DCache;};
+ inline operator pkgDepCache *() const {return DCache;};
+ inline operator pkgPolicy &() const {return *Policy;};
+ inline operator pkgPolicy *() const {return Policy;};
+ inline operator pkgSourceList &() const {return *SrcList;};
+ inline operator pkgSourceList *() const {return SrcList;};
+ inline pkgDepCache *operator ->() const {return DCache;};
+ inline pkgDepCache &operator *() const {return *DCache;};
+ inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) const {return (*DCache)[I];};
+ inline unsigned char &operator [](pkgCache::DepIterator const &I) const {return (*DCache)[I];};
bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
APT_DEPRECATED bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
@@ -85,6 +85,7 @@ class pkgCacheFile
inline bool IsSrcListBuilt() const { return (SrcList != NULL); };
pkgCacheFile();
+ explicit pkgCacheFile(pkgDepCache * const Owner);
virtual ~pkgCacheFile();
};
diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc
index a4e330a0a..f5cf52159 100644
--- a/apt-pkg/cacheset.cc
+++ b/apt-pkg/cacheset.cc
@@ -582,6 +582,116 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc
return found;
}
/*}}}*/
+// FromDependency - versions satisfying a given dependency /*{{{*/
+bool VersionContainerInterface::FromDependency(VersionContainerInterface * const vci,
+ pkgCacheFile &Cache,
+ pkgCache::DepIterator const &D,
+ CacheSetHelper::VerSelector const selector,
+ CacheSetHelper &helper)
+{
+ bool found = false;
+ switch(selector) {
+ case CacheSetHelper::ALL:
+ {
+ pkgCache::PkgIterator const T = D.TargetPkg();
+ for (pkgCache::VerIterator Ver = T.VersionList(); Ver.end() == false; ++Ver)
+ {
+ if (D.IsSatisfied(Ver) == true)
+ {
+ vci->insert(Ver);
+ found = true;
+ }
+ for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+ {
+ pkgCache::VerIterator const V = Prv.OwnerVer();
+ if (unlikely(V.end() == true) || D.IsSatisfied(Prv) == false)
+ continue;
+ vci->insert(V);
+ found = true;
+ }
+ }
+ return found;
+ }
+ case CacheSetHelper::CANDANDINST:
+ {
+ found = FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper);
+ found &= FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper);
+ return found;
+ }
+ case CacheSetHelper::CANDIDATE:
+ {
+ pkgCache::PkgIterator const T = D.TargetPkg();
+ pkgCache::VerIterator const Cand = Cache[T].CandidateVerIter(Cache);
+ if (Cand.end() == false && D.IsSatisfied(Cand) == true)
+ {
+ vci->insert(Cand);
+ found = true;
+ }
+ for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+ {
+ pkgCache::VerIterator const V = Prv.OwnerVer();
+ pkgCache::VerIterator const Cand = Cache[Prv.OwnerPkg()].CandidateVerIter(Cache);
+ if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false)
+ continue;
+ vci->insert(Cand);
+ found = true;
+ }
+ return found;
+ }
+ case CacheSetHelper::INSTALLED:
+ {
+ pkgCache::PkgIterator const T = D.TargetPkg();
+ pkgCache::VerIterator const Cand = T.CurrentVer();
+ if (Cand.end() == false && D.IsSatisfied(Cand) == true)
+ {
+ vci->insert(Cand);
+ found = true;
+ }
+ for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+ {
+ pkgCache::VerIterator const V = Prv.OwnerVer();
+ pkgCache::VerIterator const Cand = Prv.OwnerPkg().CurrentVer();
+ if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false)
+ continue;
+ vci->insert(Cand);
+ found = true;
+ }
+ return found;
+ }
+ case CacheSetHelper::CANDINST:
+ return FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper) ||
+ FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper);
+ case CacheSetHelper::INSTCAND:
+ return FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper) ||
+ FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper);
+ case CacheSetHelper::NEWEST:
+ {
+ pkgCache::PkgIterator const T = D.TargetPkg();
+ pkgCache::VerIterator const Cand = T.VersionList();
+ if (Cand.end() == false && D.IsSatisfied(Cand) == true)
+ {
+ vci->insert(Cand);
+ found = true;
+ }
+ for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+ {
+ pkgCache::VerIterator const V = Prv.OwnerVer();
+ pkgCache::VerIterator const Cand = Prv.OwnerPkg().VersionList();
+ if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false)
+ continue;
+ vci->insert(Cand);
+ found = true;
+ }
+ return found;
+ }
+ case CacheSetHelper::RELEASE:
+ case CacheSetHelper::VERSIONNUMBER:
+ // both make no sense here, so always false
+ return false;
+ }
+ return found;
+}
+ /*}}}*/
// getCandidateVer - Returns the candidate version of the given package /*{{{*/
pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h
index 0b9b9441c..5455fe74b 100644
--- a/apt-pkg/cacheset.h
+++ b/apt-pkg/cacheset.h
@@ -1068,7 +1068,7 @@ APT_IGNORE_DEPRECATED_POP
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
CacheSetHelper::VerSelector const selector) {
CacheSetHelper helper;
- return FromPackage(Cache, D, selector, helper);
+ return FromDependency(Cache, D, selector, helper);
}
APT_IGNORE_DEPRECATED_PUSH
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
@@ -1080,11 +1080,11 @@ APT_IGNORE_DEPRECATED_PUSH
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
Version const &selector) {
CacheSetHelper helper;
- return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+ return FromDependency(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
}
APT_IGNORE_DEPRECATED_POP
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
- return FromPackage(Cache, D, CacheSetHelper::CANDIDATE);
+ return FromDependency(Cache, D, CacheSetHelper::CANDIDATE);
}
/*}}}*/
}; /*}}}*/
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index d01c14223..0e972dbad 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -23,6 +23,7 @@
#include <apt-pkg/cacheset.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/cachefile.h>
#include <apt-pkg/macros.h>
#include <stdio.h>
@@ -1189,18 +1190,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
fixing the problem for "positive" dependencies */
if (Start.IsNegative() == false && (DepState[Start->ID] & DepCVer) == DepCVer)
{
- APT::VersionList verlist;
- pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this);
- if (Cand.end() == false && Start.IsSatisfied(Cand) == true)
- verlist.insert(Cand);
- for (PrvIterator Prv = Start.TargetPkg().ProvidesList(); Prv.end() != true; ++Prv)
- {
- pkgCache::VerIterator V = Prv.OwnerVer();
- pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
- if (Cand.end() == true || V != Cand || Start.IsSatisfied(Prv) == false)
- continue;
- verlist.insert(Cand);
- }
+ pkgCacheFile CacheFile(this);
+ APT::VersionList verlist = APT::VersionList::FromDependency(CacheFile, Start, APT::CacheSetHelper::CANDIDATE);
CompareProviders comp(Start);
do {