Skip to content

Commit

Permalink
show or-groups in not-installed recommends and suggests lists
Browse files Browse the repository at this point in the history
Further abstracting our new ShowList allows to use it for containers of
strings as well giving us the option to implement an or-groups display
for the recommends and suggests lists which is a nice trick given that
it also helps with migrating the last remaining other cases of old
ShowList.
  • Loading branch information
DonKult committed Aug 10, 2015
1 parent 6cfadda commit 9112f77
Show file tree
Hide file tree
Showing 18 changed files with 420 additions and 203 deletions.
34 changes: 23 additions & 11 deletions apt-pkg/cachefile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
/*}}}*/
Expand All @@ -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 /*{{{*/
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 14 additions & 13 deletions apt-pkg/cachefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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); };
Expand All @@ -85,6 +85,7 @@ class pkgCacheFile
inline bool IsSrcListBuilt() const { return (SrcList != NULL); };

pkgCacheFile();
explicit pkgCacheFile(pkgDepCache * const Owner);
virtual ~pkgCacheFile();
};

Expand Down
110 changes: 110 additions & 0 deletions apt-pkg/cacheset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions apt-pkg/cacheset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
/*}}}*/
}; /*}}}*/
Expand Down
15 changes: 3 additions & 12 deletions apt-pkg/depcache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions apt-private/private-cachefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class APT_PUBLIC CacheFile : public pkgCacheFile
};
/*}}}*/

class APT_PUBLIC SortedPackageUniverse : public APT::PackageUniverse
class SortedPackageUniverse : public APT::PackageUniverse
{
std::vector<map_pointer_t> &List;
void LazyInit() const;
Expand All @@ -85,12 +85,12 @@ class APT_PUBLIC SortedPackageUniverse : public APT::PackageUniverse
};
typedef const_iterator iterator;

APT_PUBLIC const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); }
APT_PUBLIC const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); }
APT_PUBLIC const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); }
APT_PUBLIC const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); }
APT_PUBLIC iterator begin() { LazyInit(); return iterator(data(), List.begin()); }
APT_PUBLIC iterator end() { LazyInit(); return iterator(data(), List.end()); }
const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); }
const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); }
const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); }
const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); }
iterator begin() { LazyInit(); return iterator(data(), List.begin()); }
iterator end() { LazyInit(); return iterator(data(), List.end()); }
};

#endif
13 changes: 8 additions & 5 deletions apt-private/private-download.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,23 @@ bool CheckDropPrivsMustBeDisabled(pkgAcquire &Fetcher) /*{{{*/
// CheckAuth - check if each download comes form a trusted source /*{{{*/
bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser)
{
std::string UntrustedList;
std::vector<std::string> UntrustedList;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
if (!(*I)->IsTrusted())
UntrustedList += std::string((*I)->ShortDesc()) + " ";
UntrustedList.push_back((*I)->ShortDesc());

if (UntrustedList == "")
if (UntrustedList.empty())
return true;

return AuthPrompt(UntrustedList, PromptUser);
}

bool AuthPrompt(std::string const &UntrustedList, bool const PromptUser)
bool AuthPrompt(std::vector<std::string> const &UntrustedList, bool const PromptUser)
{
ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"), UntrustedList,
[](std::string const&) { return true; },
[](std::string const&str) { return str; },
[](std::string const&) { return ""; });

if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
{
Expand Down
3 changes: 2 additions & 1 deletion apt-private/private-download.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <apt-pkg/macros.h>

#include <string>
#include <vector>

class pkgAcquire;

Expand All @@ -14,7 +15,7 @@ APT_PUBLIC bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser);

// show a authentication warning prompt and return true if the system
// should continue
APT_PUBLIC bool AuthPrompt(std::string const &UntrustedList, bool const PromptUser);
APT_PUBLIC bool AuthPrompt(std::vector<std::string> const &UntrustedList, bool const PromptUser);

APT_PUBLIC bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure);

Expand Down
Loading

0 comments on commit 9112f77

Please sign in to comment.