summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc83
-rw-r--r--apt-pkg/acquire-item.h30
-rw-r--r--apt-pkg/acquire.cc51
-rw-r--r--apt-pkg/acquire.h7
-rw-r--r--apt-pkg/algorithms.cc16
-rw-r--r--apt-pkg/algorithms.h10
-rw-r--r--apt-pkg/cachefilter.cc144
-rw-r--r--apt-pkg/cachefilter.h117
-rw-r--r--apt-pkg/cacheiterators.h10
-rw-r--r--apt-pkg/cacheset.cc374
-rw-r--r--apt-pkg/cacheset.h567
-rw-r--r--apt-pkg/cdrom.cc10
-rw-r--r--apt-pkg/contrib/cmndline.cc19
-rw-r--r--apt-pkg/contrib/fileutl.cc6
-rw-r--r--apt-pkg/contrib/gpgv.cc63
-rw-r--r--apt-pkg/deb/debindexfile.cc62
-rw-r--r--apt-pkg/deb/deblistparser.cc96
-rw-r--r--apt-pkg/deb/deblistparser.h1
-rw-r--r--apt-pkg/deb/dpkgpm.cc7
-rw-r--r--apt-pkg/edsp.cc6
-rw-r--r--apt-pkg/edsp/edspindexfile.cc2
-rw-r--r--apt-pkg/install-progress.cc2
-rw-r--r--apt-pkg/install-progress.h5
-rw-r--r--apt-pkg/metaindex.h2
-rw-r--r--apt-pkg/packagemanager.cc2
-rw-r--r--apt-pkg/packagemanager.h4
-rw-r--r--apt-pkg/pkgcache.cc25
-rw-r--r--apt-pkg/pkgcache.h43
-rw-r--r--apt-pkg/pkgcachegen.cc98
-rw-r--r--apt-pkg/pkgcachegen.h20
-rw-r--r--apt-pkg/sourcelist.cc8
-rw-r--r--apt-pkg/sourcelist.h4
-rw-r--r--apt-pkg/tagfile.h4
-rw-r--r--apt-pkg/upgrade.cc113
-rw-r--r--apt-pkg/upgrade.h14
35 files changed, 1383 insertions, 642 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index b8317b13d..923a153a7 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -64,6 +64,10 @@ static void printHashSumComparision(std::string const &URI, HashStringList const
/*}}}*/
// Acquire::Item::Item - Constructor /*{{{*/
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
pkgAcquire::Item::Item(pkgAcquire *Owner,
HashStringList const &ExpectedHashes,
pkgAcqMetaBase *TransactionManager)
@@ -76,6 +80,9 @@ pkgAcquire::Item::Item(pkgAcquire *Owner,
if(TransactionManager != NULL)
TransactionManager->Add(this);
}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
/*}}}*/
// Acquire::Item::~Item - Destructor /*{{{*/
// ---------------------------------------------------------------------
@@ -723,7 +730,15 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size, HashStringLi
Local = true;
Desc.URI = "rred:" + FinalFile;
QueueURI(Desc);
+ ActiveSubprocess = "rred";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
Mode = "rred";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
return;
}
@@ -846,7 +861,15 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri
Local = true;
Desc.URI = "rred:" + FinalFile;
QueueURI(Desc);
+ ActiveSubprocess = "rred";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
Mode = "rred";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
return;
}
// success in download/apply all diffs, clean up
@@ -967,6 +990,7 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
else
{
Desc.URI = URI + '.' + comprExt;
+ DestFile = DestFile + '.' + comprExt;
if(Target)
MetaKey = string(Target->MetaKey) + '.' + comprExt;
}
@@ -1069,8 +1093,8 @@ std::string pkgAcqIndex::GetFinalFilename() const
std::string const compExt = CompressionExtension.substr(0, CompressionExtension.find(' '));
std::string FinalFile = _config->FindDir("Dir::State::lists");
FinalFile += URItoFileName(RealURI);
- if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz")
- FinalFile += ".gz";
+ if (_config->FindB("Acquire::GzipIndexes",false) == true)
+ FinalFile += '.' + compExt;
return FinalFile;
}
/*}}}*/
@@ -1080,8 +1104,8 @@ std::string pkgAcqIndex::GetFinalFilename() const
void pkgAcqIndex::ReverifyAfterIMS()
{
std::string const compExt = CompressionExtension.substr(0, CompressionExtension.find(' '));
- if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz")
- DestFile += ".gz";
+ if (_config->FindB("Acquire::GzipIndexes",false) == true)
+ DestFile += compExt;
// copy FinalFile into partial/ so that we check the hash again
string FinalFile = GetFinalFilename();
@@ -1179,7 +1203,15 @@ void pkgAcqIndex::Done(string Message, unsigned long long Size,
DestFile += ".decomp";
Desc.URI = "copy:" + FileName;
QueueURI(Desc);
+ ActiveSubprocess = "copy";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
Mode = "copy";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
return;
}
@@ -1206,15 +1238,25 @@ void pkgAcqIndex::Done(string Message, unsigned long long Size,
{
Erase = false;
ReverifyAfterIMS();
+#if 0 // ???
+ // set destfile to the final destfile
+ if(_config->FindB("Acquire::GzipIndexes",false) == false)
+ {
+ DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+ DestFile += URItoFileName(RealURI);
+ }
+
+ ReverifyAfterIMS(FileName);
+#endif
return;
}
string decompProg;
// If we enable compressed indexes, queue for hash verification
- if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz")
+ if (_config->FindB("Acquire::GzipIndexes",false))
{
DestFile = _config->FindDir("Dir::State::lists");
- DestFile += URItoFileName(RealURI) + ".gz";
+ DestFile += URItoFileName(RealURI) + '.' + compExt;
Decompression = true;
Desc.URI = "copy:" + FileName;
@@ -1238,8 +1280,15 @@ void pkgAcqIndex::Done(string Message, unsigned long long Size,
Desc.URI = decompProg + ":" + FileName;
QueueURI(Desc);
- // FIXME: this points to a c++ string that goes out of scope
- Mode = decompProg.c_str();
+ ActiveSubprocess = decompProg;
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ Mode = ActiveSubprocess.c_str();
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
}
/*}}}*/
// AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
@@ -1676,7 +1725,15 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,HashStringList
AuthPass = true;
Desc.URI = "gpgv:" + SigFile;
QueueURI(Desc);
- Mode = "gpgv";
+ ActiveSubprocess = "gpgv";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ Mode = "gpgv";
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
return;
}
}
@@ -1785,8 +1842,12 @@ void pkgAcqMetaIndex::AuthDone(string Message) /*{{{*/
URItoFileName((*Target)->URI);
unlink(index.c_str());
// and also old gzipindexes
- index += ".gz";
- unlink(index.c_str());
+ std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+ for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+ {
+ index += '.' + (*t);
+ unlink(index.c_str());
+ }
}
}
#endif
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index cc156cf17..e6a22ce7b 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -136,7 +136,12 @@ class pkgAcquire::Item : public WeakPointable
/** \brief If not \b NULL, contains the name of a subprocess that
* is operating on this object (for instance, "gzip" or "gpgv").
*/
- const char *Mode;
+ APT_DEPRECATED const char *Mode;
+
+ /** \brief contains the name of the subprocess that is operating on this object
+ * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
+ * as it can manage the lifetime of included string properly. */
+ std::string ActiveSubprocess;
/** \brief A client-supplied unique identifier.
*
@@ -254,12 +259,12 @@ class pkgAcquire::Item : public WeakPointable
*
* \return a URI that should be used to describe what is being fetched.
*/
- virtual std::string DescURI() const = 0;
+ virtual std::string DescURI() = 0;
/** \brief Short item description.
*
* \return a brief description of the object being fetched.
*/
- virtual std::string ShortDesc() const {return DescURI();}
+ virtual std::string ShortDesc() {return DescURI();}
/** \brief Invoked by the worker when the download is completely done. */
virtual void Finished() {};
@@ -418,7 +423,7 @@ class pkgAcqMetaSig : public pkgAcqMetaBase
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
virtual std::string Custom600Headers() const;
- virtual std::string DescURI() const {return RealURI; };
+ virtual std::string DescURI() {return RealURI; };
/** \brief Create a new pkgAcqMetaSig. */
pkgAcqMetaSig(pkgAcquire *Owner,
@@ -531,7 +536,7 @@ class pkgAcqMetaIndex : public pkgAcqMetaBase
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
virtual std::string Custom600Headers() const;
- virtual std::string DescURI() const {return RealURI; };
+ virtual std::string DescURI() {return RealURI; };
virtual void Finished();
/** \brief Create a new pkgAcqMetaIndex. */
@@ -649,7 +654,7 @@ class pkgAcqDiffIndex : public pkgAcqBaseIndex
virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
- virtual std::string DescURI() const {return RealURI + "Index";};
+ virtual std::string DescURI() {return RealURI + "Index";};
virtual std::string Custom600Headers() const;
/** \brief Parse the Index file for a set of Packages diffs.
@@ -745,7 +750,7 @@ class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
- virtual std::string DescURI() const {return RealURI + "Index";};
+ virtual std::string DescURI() {return RealURI + "Index";};
/** \brief Create an index merge-diff item.
*
@@ -873,7 +878,7 @@ class pkgAcqIndexDiffs : public pkgAcqBaseIndex
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
- virtual std::string DescURI() const {return RealURI + "IndexDiffs";};
+ virtual std::string DescURI() {return RealURI + "IndexDiffs";};
/** \brief Create an index diff item.
*
@@ -960,7 +965,7 @@ class pkgAcqIndex : public pkgAcqBaseIndex
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
virtual std::string Custom600Headers() const;
- virtual std::string DescURI() const {return Desc.URI;};
+ virtual std::string DescURI() {return Desc.URI;};
/** \brief Create a pkgAcqIndex.
*
@@ -1064,7 +1069,6 @@ class OptionalIndexTarget : public IndexTarget
}
};
/*}}}*/
-
/** \brief An item that is responsible for fetching a package file. {{{
*
* If the package file already exists in the cache, nothing will be
@@ -1116,8 +1120,8 @@ class pkgAcqArchive : public pkgAcquire::Item
virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
- virtual std::string DescURI() const {return Desc.URI;};
- virtual std::string ShortDesc() const {return Desc.ShortDesc;};
+ virtual std::string DescURI() {return Desc.URI;};
+ virtual std::string ShortDesc() {return Desc.ShortDesc;};
virtual void Finished();
virtual bool IsTrusted() const;
@@ -1168,7 +1172,7 @@ class pkgAcqFile : public pkgAcquire::Item
virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
virtual void Done(std::string Message,unsigned long long Size, HashStringList const &CalcHashes,
pkgAcquire::MethodConfig *Cnf);
- virtual std::string DescURI() const {return Desc.URI;};
+ virtual std::string DescURI() {return Desc.URI;};
virtual std::string Custom600Headers() const;
/** \brief Create a new pkgAcqFile object.
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 9060d492b..ec565fcfa 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -74,23 +74,27 @@ pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Wor
// ---------------------------------------------------------------------
/* Do everything needed to be a complete Acquire object and report the
success (or failure) back so the user knows that something is wrong… */
-bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock)
+bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock,
+ bool const createDirectories)
{
Log = Progress;
// check for existence and possibly create auxiliary directories
- string const listDir = _config->FindDir("Dir::State::lists");
- string const partialListDir = listDir + "partial/";
- string const archivesDir = _config->FindDir("Dir::Cache::Archives");
- string const partialArchivesDir = archivesDir + "partial/";
-
- if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
- CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false)
- return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str());
-
- if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false &&
- CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false)
- return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str());
+ if (createDirectories == true)
+ {
+ string const listDir = _config->FindDir("Dir::State::lists");
+ string const partialListDir = listDir + "partial/";
+ string const archivesDir = _config->FindDir("Dir::Cache::Archives");
+ string const partialArchivesDir = archivesDir + "partial/";
+
+ if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
+ CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false)
+ return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str());
+
+ if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false &&
+ CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false)
+ return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str());
+ }
if (Lock.empty() == true || _config->FindB("Debug::NoLocking", false) == true)
return true;
@@ -582,27 +586,18 @@ pkgAcquire::UriIterator pkgAcquire::UriEnd()
// Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-pkgAcquire::MethodConfig::MethodConfig()
+pkgAcquire::MethodConfig::MethodConfig() : d(NULL), Next(0), SingleInstance(false),
+ Pipeline(false), SendConfig(false), LocalOnly(false), NeedsCleanup(false),
+ Removable(false)
{
- SingleInstance = false;
- Pipeline = false;
- SendConfig = false;
- LocalOnly = false;
- Removable = false;
- Next = 0;
}
/*}}}*/
// Queue::Queue - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name),
- Owner(Owner)
+pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : d(NULL), Next(0),
+ Name(Name), Items(0), Workers(0), Owner(Owner), PipeDepth(0), MaxPipeDepth(1)
{
- Items = 0;
- Next = 0;
- Workers = 0;
- MaxPipeDepth = 1;
- PipeDepth = 0;
}
/*}}}*/
// Queue::~Queue - Destructor /*{{{*/
@@ -806,7 +801,7 @@ void pkgAcquire::Queue::Bump()
// AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Update(true), MorePulses(false)
+pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false)
{
Start();
}
diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h
index 0113021b2..7bceb4323 100644
--- a/apt-pkg/acquire.h
+++ b/apt-pkg/acquire.h
@@ -352,8 +352,11 @@ class pkgAcquire
* \param Lock defines a lock file that should be acquired to ensure
* only one Acquire class is in action at the time or an empty string
* if no lock file should be used.
+ * \param createDirectories can be used to disable the creation of directories,
+ * e.g. if the fetcher is used with different directories later on
*/
- bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = "");
+ bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = "",
+ bool const createDirectories = true);
void SetLog(pkgAcquireStatus *Progress) { Log = Progress; }
@@ -585,7 +588,7 @@ class pkgAcquire::UriIterator
*
* \param Q The queue over which this UriIterator should iterate.
*/
- UriIterator(pkgAcquire::Queue *Q) : CurQ(Q), CurItem(0)
+ UriIterator(pkgAcquire::Queue *Q) : d(NULL), CurQ(Q), CurItem(0)
{
while (CurItem == 0 && CurQ != 0)
{
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index 608ec7fce..71b5ac2c1 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -640,13 +640,11 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
// ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool pkgProblemResolver::Resolve(bool BrokenFix)
+bool pkgProblemResolver::Resolve(bool BrokenFix, OpProgress * const Progress)
{
std::string const solver = _config->Find("APT::Solver", "internal");
- if (solver != "internal") {
- OpTextProgress Prog(*_config);
- return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, &Prog);
- }
+ if (solver != "internal")
+ return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, Progress);
return ResolveInternal(BrokenFix);
}
/*}}}*/
@@ -1140,13 +1138,11 @@ bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I)
/* This is the work horse of the soft upgrade routine. It is very gental
in that it does not install or remove any packages. It is assumed that the
system was non-broken previously. */
-bool pkgProblemResolver::ResolveByKeep()
+bool pkgProblemResolver::ResolveByKeep(OpProgress * const Progress)
{
std::string const solver = _config->Find("APT::Solver", "internal");
- if (solver != "internal") {
- OpTextProgress Prog(*_config);
- return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog);
- }
+ if (solver != "internal")
+ return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress);
return ResolveByKeepInternal();
}
/*}}}*/
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index f35bd9a13..4d3bfa81f 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -136,12 +136,12 @@ class pkgProblemResolver /*{{{*/
inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
-
- // Try to intelligently resolve problems by installing and removing packages
- bool Resolve(bool BrokenFix = false);
-
+
+ // Try to intelligently resolve problems by installing and removing packages
+ bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL);
+
// Try to resolve problems only by using keep
- bool ResolveByKeep();
+ bool ResolveByKeep(OpProgress * const Progress = NULL);
APT_DEPRECATED void InstallProtect();
diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc
index e388f2450..4362f43e3 100644
--- a/apt-pkg/cachefilter.cc
+++ b/apt-pkg/cachefilter.cc
@@ -6,6 +6,7 @@
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/cachefile.h>
#include <apt-pkg/cachefilter.h>
#include <apt-pkg/error.h>
#include <apt-pkg/pkgcache.h>
@@ -22,7 +23,11 @@
/*}}}*/
namespace APT {
namespace CacheFilter {
-PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) : d(NULL) {/*{{{*/
+APT_CONST Matcher::~Matcher() {}
+APT_CONST PackageMatcher::~PackageMatcher() {}
+
+// Name matches RegEx /*{{{*/
+PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {
pattern = new regex_t;
int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (Res == 0)
@@ -34,41 +39,36 @@ PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) : d
regerror(Res, pattern, Error, sizeof(Error));
_error->Error(_("Regex compilation error - %s"), Error);
}
- /*}}}*/
-bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
+bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {
if (unlikely(pattern == NULL))
return false;
else
return regexec(pattern, Pkg.Name(), 0, 0, 0) == 0;
}
- /*}}}*/
-bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/
+bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {
if (unlikely(pattern == NULL))
return false;
else
return regexec(pattern, Grp.Name(), 0, 0, 0) == 0;
}
- /*}}}*/
-PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/
+PackageNameMatchesRegEx::~PackageNameMatchesRegEx() {
if (pattern == NULL)
return;
regfree(pattern);
delete pattern;
}
/*}}}*/
-
-// Fnmatch support /*{{{*/
-//----------------------------------------------------------------------
-bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
+// Name matches Fnmatch /*{{{*/
+PackageNameMatchesFnmatch::PackageNameMatchesFnmatch(std::string const &Pattern) :
+ Pattern(Pattern) {}
+bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator const &Pkg) {
return fnmatch(Pattern.c_str(), Pkg.Name(), FNM_CASEFOLD) == 0;
}
- /*}}}*/
-bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/
+bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator const &Grp) {
return fnmatch(Pattern.c_str(), Grp.Name(), FNM_CASEFOLD) == 0;
}
/*}}}*/
-
-// CompleteArch to <kernel>-<cpu> tuple /*{{{*/
+// Architecture matches <kernel>-<cpu> specification /*{{{*/
//----------------------------------------------------------------------
/* The complete architecture, consisting of <kernel>-<cpu>. */
static std::string CompleteArch(std::string const &arch) {
@@ -82,12 +82,10 @@ static std::string CompleteArch(std::string const &arch) {
else if (arch == "any") return "*-*";
else return "linux-" + arch;
}
- /*}}}*/
-PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/
- literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern), d(NULL) {
+PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :
+ literal(pattern), complete(CompleteArch(pattern)), isPattern(isPattern) {
}
- /*}}}*/
-bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/
+bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {
if (strcmp(literal.c_str(), arch) == 0 ||
strcmp(complete.c_str(), arch) == 0)
return true;
@@ -96,16 +94,112 @@ bool PackageArchitectureMatchesSpecification::operator() (char const * const &ar
return fnmatch(complete.c_str(), pkgarch.c_str(), 0) == 0;
return fnmatch(pkgarch.c_str(), complete.c_str(), 0) == 0;
}
- /*}}}*/
-bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
+bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {
return (*this)(Pkg.Arch());
}
+PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() {
+}
/*}}}*/
-bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator const &Ver) {/*{{{*/
- return (*this)(Ver.ParentPkg());
+// Package is new install /*{{{*/
+PackageIsNewInstall::PackageIsNewInstall(pkgCacheFile * const Cache) : Cache(Cache) {}
+APT_PURE bool PackageIsNewInstall::operator() (pkgCache::PkgIterator const &Pkg) {
+ return (*Cache)[Pkg].NewInstall();
}
+PackageIsNewInstall::~PackageIsNewInstall() {}
/*}}}*/
-PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { /*{{{*/
+// Generica like True, False, NOT, AND, OR /*{{{*/
+APT_CONST bool TrueMatcher::operator() (pkgCache::PkgIterator const &) { return true; }
+APT_CONST bool TrueMatcher::operator() (pkgCache::GrpIterator const &) { return true; }
+APT_CONST bool TrueMatcher::operator() (pkgCache::VerIterator const &) { return true; }
+
+APT_CONST bool FalseMatcher::operator() (pkgCache::PkgIterator const &) { return false; }
+APT_CONST bool FalseMatcher::operator() (pkgCache::GrpIterator const &) { return false; }
+APT_CONST bool FalseMatcher::operator() (pkgCache::VerIterator const &) { return false; }
+
+NOTMatcher::NOTMatcher(Matcher * const matcher) : matcher(matcher) {}
+bool NOTMatcher::operator() (pkgCache::PkgIterator const &Pkg) { return ! (*matcher)(Pkg); }
+bool NOTMatcher::operator() (pkgCache::GrpIterator const &Grp) { return ! (*matcher)(Grp); }
+bool NOTMatcher::operator() (pkgCache::VerIterator const &Ver) { return ! (*matcher)(Ver); }
+NOTMatcher::~NOTMatcher() { delete matcher; }
+
+ANDMatcher::ANDMatcher() {}
+ANDMatcher::ANDMatcher(Matcher * const matcher1) {
+ AND(matcher1);
+}
+ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2) {
+ AND(matcher1).AND(matcher2);
+}
+ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3) {
+ AND(matcher1).AND(matcher2).AND(matcher3);
+}
+ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4) {
+ AND(matcher1).AND(matcher2).AND(matcher3).AND(matcher4);
+}
+ANDMatcher::ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5) {
+ AND(matcher1).AND(matcher2).AND(matcher3).AND(matcher4).AND(matcher5);
+}
+ANDMatcher& ANDMatcher::AND(Matcher * const matcher) { matchers.push_back(matcher); return *this; }
+bool ANDMatcher::operator() (pkgCache::PkgIterator const &Pkg) {
+ for (std::vector<Matcher *>::const_iterator M = matchers.begin(); M != matchers.end(); ++M)
+ if ((**M)(Pkg) == false)
+ return false;
+ return true;
+}
+bool ANDMatcher::operator() (pkgCache::GrpIterator const &Grp) {
+ for (std::vector<Matcher *>::const_iterator M = matchers.begin(); M != matchers.end(); ++M)
+ if ((**M)(Grp) == false)
+ return false;
+ return true;
+}
+bool ANDMatcher::operator() (pkgCache::VerIterator const &Ver) {
+ for (std::vector<Matcher *>::const_iterator M = matchers.begin(); M != matchers.end(); ++M)
+ if ((**M)(Ver) == false)
+ return false;
+ return true;
+}
+ANDMatcher::~ANDMatcher() {
+ for (std::vector<Matcher *>::iterator M = matchers.begin(); M != matchers.end(); ++M)
+ delete *M;
+}
+
+ORMatcher::ORMatcher() {}
+ORMatcher::ORMatcher(Matcher * const matcher1) {
+ OR(matcher1);
+}
+ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2) {
+ OR(matcher1).OR(matcher2);
+}
+ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3) {
+ OR(matcher1).OR(matcher2).OR(matcher3);
+}
+ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4) {
+ OR(matcher1).OR(matcher2).OR(matcher3).OR(matcher4);
+}
+ORMatcher::ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5) {
+ OR(matcher1).OR(matcher2).OR(matcher3).OR(matcher4).OR(matcher5);
+}
+ORMatcher& ORMatcher::OR(Matcher * const matcher) { matchers.push_back(matcher); return *this; }
+bool ORMatcher::operator() (pkgCache::PkgIterator const &Pkg) {
+ for (std::vector<Matcher *>::const_iterator M = matchers.begin(); M != matchers.end(); ++M)
+ if ((**M)(Pkg) == true)
+ return true;
+ return false;
+}
+bool ORMatcher::operator() (pkgCache::GrpIterator const &Grp) {
+ for (std::vector<Matcher *>::const_iterator M = matchers.begin(); M != matchers.end(); ++M)
+ if ((**M)(Grp) == true)
+ return true;
+ return false;
+}
+bool ORMatcher::operator() (pkgCache::VerIterator const &Ver) {
+ for (std::vector<Matcher *>::const_iterator M = matchers.begin(); M != matchers.end(); ++M)
+ if ((**M)(Ver) == true)
+ return true;
+ return false;
+}
+ORMatcher::~ORMatcher() {
+ for (std::vector<Matcher *>::iterator M = matchers.begin(); M != matchers.end(); ++M)
+ delete *M;
}
/*}}}*/
diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h
index d9b957c67..b4697b773 100644
--- a/apt-pkg/cachefilter.h
+++ b/apt-pkg/cachefilter.h
@@ -10,28 +10,90 @@
#include <apt-pkg/cacheiterators.h>
#include <string>
+#include <vector>
#include <regex.h>
+
+class pkgCacheFile;
/*}}}*/
namespace APT {
namespace CacheFilter {
-class PackageMatcher {
- public:
- virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) {
- return false; };
- virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) {
- return false; };
- virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) {
- return false; };
-
- virtual ~PackageMatcher() {};
+class Matcher {
+public:
+ virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) = 0;
+ virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) = 0;
+ virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) = 0;
+ virtual ~Matcher();
};
-// PackageNameMatchesRegEx /*{{{*/
-class PackageNameMatchesRegEx : public PackageMatcher {
- /** \brief dpointer placeholder (for later in case we need it) */
- void *d;
+class PackageMatcher : public Matcher {
+public:
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg) = 0;
+ virtual bool operator() (pkgCache::VerIterator const &Ver) { return (*this)(Ver.ParentPkg()); }
+ virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) { return false; }
+ virtual ~PackageMatcher();
+};
+
+// Generica like True, False, NOT, AND, OR /*{{{*/
+class TrueMatcher : public Matcher {
+public:
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ virtual bool operator() (pkgCache::GrpIterator const &Grp);
+ virtual bool operator() (pkgCache::VerIterator const &Ver);
+};
+
+class FalseMatcher : public Matcher {
+public:
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ virtual bool operator() (pkgCache::GrpIterator const &Grp);
+ virtual bool operator() (pkgCache::VerIterator const &Ver);
+};
+
+class NOTMatcher : public Matcher {
+ Matcher * const matcher;
+public:
+ NOTMatcher(Matcher * const matcher);
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ virtual bool operator() (pkgCache::GrpIterator const &Grp);
+ virtual bool operator() (pkgCache::VerIterator const &Ver);
+ virtual ~NOTMatcher();
+};
+
+class ANDMatcher : public Matcher {
+ std::vector<Matcher *> matchers;
+public:
+ // 5 ought to be enough for everybody… c++11 variadic templates would be nice
+ ANDMatcher();
+ ANDMatcher(Matcher * const matcher1);
+ ANDMatcher(Matcher * const matcher1, Matcher * const matcher2);
+ ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3);
+ ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4);
+ ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5);
+ ANDMatcher& AND(Matcher * const matcher);
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ virtual bool operator() (pkgCache::GrpIterator const &Grp);
+ virtual bool operator() (pkgCache::VerIterator const &Ver);
+ virtual ~ANDMatcher();
+};
+class ORMatcher : public Matcher {
+ std::vector<Matcher *> matchers;
+public:
+ // 5 ought to be enough for everybody… c++11 variadic templates would be nice
+ ORMatcher();
+ ORMatcher(Matcher * const matcher1);
+ ORMatcher(Matcher * const matcher1, Matcher * const matcher2);
+ ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3);
+ ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4);
+ ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5);
+ ORMatcher& OR(Matcher * const matcher);
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ virtual bool operator() (pkgCache::GrpIterator const &Grp);
+ virtual bool operator() (pkgCache::VerIterator const &Ver);
+ virtual ~ORMatcher();
+};
+ /*}}}*/
+class PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/
regex_t* pattern;
public:
PackageNameMatchesRegEx(std::string const &Pattern);
@@ -40,20 +102,16 @@ public:
virtual ~PackageNameMatchesRegEx();
};
/*}}}*/
-// PackageNameMatchesFnmatch /*{{{*/
- class PackageNameMatchesFnmatch : public PackageMatcher{
- /** \brief dpointer placeholder (for later in case we need it) */
- void *d;
- const std::string Pattern;
+class PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/
+ const std::string Pattern;
public:
- PackageNameMatchesFnmatch(std::string const &Pattern)
- : Pattern(Pattern) {};
- virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ PackageNameMatchesFnmatch(std::string const &Pattern);
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
virtual bool operator() (pkgCache::GrpIterator const &Grp);
virtual ~PackageNameMatchesFnmatch() {};
};
/*}}}*/
-// PackageArchitectureMatchesSpecification /*{{{*/
+class PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/
/** \class PackageArchitectureMatchesSpecification
\brief matching against architecture specification strings
@@ -62,12 +120,9 @@ public:
debian-policy §11.1 "Architecture specification strings".
Examples: i386, mipsel, linux-any, any-amd64, any */
-class PackageArchitectureMatchesSpecification : public PackageMatcher {
std::string literal;
std::string complete;
bool isPattern;
- /** \brief dpointer placeholder (for later in case we need it) */
- void *d;
public:
/** \brief matching against architecture specification strings
*
@@ -79,10 +134,18 @@ public:
PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
bool operator() (char const * const &arch);
virtual bool operator() (pkgCache::PkgIterator const &Pkg);
- virtual bool operator() (pkgCache::VerIterator const &Ver);
virtual ~PackageArchitectureMatchesSpecification();
};
/*}}}*/
+class PackageIsNewInstall : public PackageMatcher { /*{{{*/
+ pkgCacheFile * const Cache;
+public:
+ PackageIsNewInstall(pkgCacheFile * const Cache);
+ virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+ virtual ~PackageIsNewInstall();
+};
+ /*}}}*/
+
}
}
#endif
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index f2aae7272..b0c02d4a2 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -159,7 +159,7 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
// Accessors
- inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;}
+ inline const char *Name() const { return Group().Name(); }
// Versions have sections - and packages can have different versions with different sections
// so this interface is broken by design. It used to return the section of the "first parsed
// package stanza", but as this can potentially be anything it now returns the section of the
@@ -215,6 +215,12 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
// Accessors
inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;}
inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;}
+ /** \brief source package name this version comes from
+ Always contains the name, even if it is the same as the binary name */
+ inline const char *SourcePkgName() const {return Owner->StrP + S->SourcePkgName;}
+ /** \brief source version this version comes from
+ Always contains the version string, even if it is the same as the binary version */
+ inline const char *SourceVerStr() const {return Owner->StrP + S->SourceVerStr;}
inline const char *Arch() const {
if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All)
return "all";
@@ -336,7 +342,7 @@ class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> {
inline void operator ++() {operator ++(0);}
// Accessors
- inline const char *Name() const {return Owner->StrP + Owner->PkgP[S->ParentPkg].Name;}
+ inline const char *Name() const {return ParentPkg().Name();}
inline const char *ProvideVersion() const {return S->ProvideVersion == 0?0:Owner->StrP + S->ProvideVersion;}
inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);}
inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);}
diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc
index d95a32aff..76a7e717e 100644
--- a/apt-pkg/cacheset.cc
+++ b/apt-pkg/cacheset.cc
@@ -37,8 +37,23 @@
#include <apti18n.h>
/*}}}*/
namespace APT {
-// FromTask - Return all packages in the cache from a specific task /*{{{*/
-bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+
+// PackageFrom - selecting the appropriate method for package selection /*{{{*/
+bool CacheSetHelper::PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci,
+ pkgCacheFile &Cache, std::string const &pattern) {
+ switch (select) {
+ case UNKNOWN: return false;
+ case REGEX: return PackageFromRegEx(pci, Cache, pattern);
+ case TASK: return PackageFromTask(pci, Cache, pattern);
+ case FNMATCH: return PackageFromFnmatch(pci, Cache, pattern);
+ case PACKAGENAME: return PackageFromPackageName(pci, Cache, pattern);
+ case STRING: return PackageFromString(pci, Cache, pattern);
+ }
+ return false;
+}
+ /*}}}*/
+// PackageFromTask - Return all packages in the cache from a specific task /*{{{*/
+bool CacheSetHelper::PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
size_t const archfound = pattern.find_last_of(':');
std::string arch = "native";
if (archfound != std::string::npos) {
@@ -55,7 +70,7 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci,
bool const wasEmpty = pci->empty();
if (wasEmpty == true)
- pci->setConstructor(TASK);
+ pci->setConstructor(CacheSetHelper::TASK);
// get the records
pkgRecords Recs(Cache);
@@ -91,32 +106,32 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci,
continue;
pci->insert(Pkg);
- helper.showTaskSelection(Pkg, pattern);
+ showPackageSelection(Pkg, CacheSetHelper::TASK, pattern);
found = true;
}
regfree(&Pattern);
if (found == false) {
- helper.canNotFindTask(pci, Cache, pattern);
- pci->setConstructor(UNKNOWN);
+ canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern);
+ pci->setConstructor(CacheSetHelper::UNKNOWN);
return false;
}
- if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
- pci->setConstructor(UNKNOWN);
+ if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
+ pci->setConstructor(CacheSetHelper::UNKNOWN);
return true;
}
/*}}}*/
-// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/
-bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+// PackageFromRegEx - Return all packages in the cache matching a pattern /*{{{*/
+bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
static const char * const isregex = ".?+*|[^$";
if (pattern.find_first_of(isregex) == std::string::npos)
return false;
bool const wasEmpty = pci->empty();
if (wasEmpty == true)
- pci->setConstructor(REGEX);
+ pci->setConstructor(CacheSetHelper::REGEX);
size_t archfound = pattern.find_last_of(':');
std::string arch = "native";
@@ -150,28 +165,25 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci,
}
pci->insert(Pkg);
- helper.showRegExSelection(Pkg, pattern);
+ showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern);
found = true;
}
if (found == false) {
- helper.canNotFindRegEx(pci, Cache, pattern);
- pci->setConstructor(UNKNOWN);
+ canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern);
+ pci->setConstructor(CacheSetHelper::UNKNOWN);
return false;
}
- if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
- pci->setConstructor(UNKNOWN);
+ if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
+ pci->setConstructor(CacheSetHelper::UNKNOWN);
return true;
}
/*}}}*/
-// FromFnmatch - Returns the package defined by this fnmatch /*{{{*/
-bool
-PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
- pkgCacheFile &Cache,
- std::string pattern,
- CacheSetHelper &helper)
+// PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/
+bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface * const pci,
+ pkgCacheFile &Cache, std::string pattern)
{
static const char * const isfnmatch = ".?*[]!";
if (pattern.find_first_of(isfnmatch) == std::string::npos)
@@ -179,7 +191,7 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
bool const wasEmpty = pci->empty();
if (wasEmpty == true)
- pci->setConstructor(FNMATCH);
+ pci->setConstructor(CacheSetHelper::FNMATCH);
size_t archfound = pattern.find_last_of(':');
std::string arch = "native";
@@ -213,33 +225,25 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
}
pci->insert(Pkg);
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- helper.showFnmatchSelection(Pkg, pattern);
-#else
- helper.showRegExSelection(Pkg, pattern);
-#endif
+ showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern);
found = true;
}
if (found == false) {
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- helper.canNotFindFnmatch(pci, Cache, pattern);
-#else
- helper.canNotFindRegEx(pci, Cache, pattern);
-#endif
- pci->setConstructor(UNKNOWN);
+ canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern);
+ pci->setConstructor(CacheSetHelper::UNKNOWN);
return false;
}
- if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
- pci->setConstructor(UNKNOWN);
+ if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
+ pci->setConstructor(CacheSetHelper::UNKNOWN);
return true;
}
/*}}}*/
-// FromName - Returns the package defined by this string /*{{{*/
-pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache,
- std::string const &str, CacheSetHelper &helper) {
+// PackageFromName - Returns the package defined by this string /*{{{*/
+pkgCache::PkgIterator CacheSetHelper::PackageFromName(pkgCacheFile &Cache,
+ std::string const &str) {
std::string pkg = str;
size_t archfound = pkg.find_last_of(':');
std::string arch;
@@ -260,13 +264,13 @@ pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache,
Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch);
if (Pkg.end() == true)
- return helper.canNotFindPkgName(Cache, str);
+ return canNotFindPkgName(Cache, str);
return Pkg;
}
/*}}}*/
-// FromGroup - Returns the package defined by this string /*{{{*/
-bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache,
- std::string pkg, CacheSetHelper &helper) {
+// PackageFromPackageName - Returns the package defined by this string /*{{{*/
+bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache,
+ std::string pkg) {
if (unlikely(Cache.GetPkgCache() == 0))
return false;
@@ -306,7 +310,7 @@ bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci,
}
}
- pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg);
+ pkgCache::PkgIterator Pkg = canNotFindPkgName(Cache, pkg);
if (Pkg.end() == true)
return false;
@@ -314,20 +318,18 @@ bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci,
return true;
}
/*}}}*/
-// FromString - Return all packages matching a specific string /*{{{*/
-bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) {
+// PackageFromString - Return all packages matching a specific string /*{{{*/
+bool CacheSetHelper::PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) {
bool found = true;
_error->PushToStack();
- if (FromGroup(pci, Cache, str, helper) == false &&
- FromTask(pci, Cache, str, helper) == false &&
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- // FIXME: hm, hm, regexp/fnmatch incompatible?
- FromFnmatch(pci, Cache, str, helper) == false &&
-#endif
- FromRegEx(pci, Cache, str, helper) == false)
+ if (PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str) == false &&
+ PackageFrom(CacheSetHelper::TASK, pci, Cache, str) == false &&
+ // FIXME: hm, hm, regexp/fnmatch incompatible?
+ PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, str) == false &&
+ PackageFrom(CacheSetHelper::REGEX, pci, Cache, str) == false)
{
- helper.canNotFindPackage(pci, Cache, str);
+ canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str);
found = false;
}
@@ -338,51 +340,50 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci
return found;
}
/*}}}*/
-// FromCommandLine - Return all packages specified on commandline /*{{{*/
-bool PackageContainerInterface::FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
+// PackageFromCommandLine - Return all packages specified on commandline /*{{{*/
+bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline) {
bool found = false;
for (const char **I = cmdline; *I != 0; ++I)
- found |= PackageContainerInterface::FromString(pci, Cache, *I, helper);
+ found |= PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, *I);
return found;
}
/*}}}*/
// FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
-bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
+bool CacheSetHelper::PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
pkgCacheFile &Cache, const char * cmdline,
- std::list<Modifier> const &mods, CacheSetHelper &helper) {
+ std::list<PkgModifier> const &mods) {
std::string str = cmdline;
unsigned short fallback = modID;
bool modifierPresent = false;
- for (std::list<Modifier>::const_iterator mod = mods.begin();
+ for (std::list<PkgModifier>::const_iterator mod = mods.begin();
mod != mods.end(); ++mod) {
size_t const alength = strlen(mod->Alias);
switch(mod->Pos) {
- case Modifier::POSTFIX:
+ case PkgModifier::POSTFIX:
if (str.compare(str.length() - alength, alength,
mod->Alias, 0, alength) != 0)
continue;
str.erase(str.length() - alength);
modID = mod->ID;
break;
- case Modifier::PREFIX:
+ case PkgModifier::PREFIX:
continue;
- case Modifier::NONE:
+ case PkgModifier::NONE:
continue;
}
modifierPresent = true;
break;
}
if (modifierPresent == true) {
- bool const errors = helper.showErrors(false);
- pkgCache::PkgIterator Pkg = FromName(Cache, cmdline, helper);
- helper.showErrors(errors);
- if (Pkg.end() == false) {
- pci->insert(Pkg);
+ bool const errors = showErrors(false);
+ bool const found = PackageFrom(PACKAGENAME, pci, Cache, cmdline);
+ showErrors(errors);
+ if (found == true) {
modID = fallback;
return true;
}
}
- return FromString(pci, Cache, str, helper);
+ return PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str);
}
/*}}}*/
// FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
@@ -391,7 +392,7 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
pkgCacheFile &Cache, const char * cmdline,
std::list<Modifier> const &mods,
CacheSetHelper &helper) {
- Version select = NEWEST;
+ CacheSetHelper::VerSelector select = CacheSetHelper::NEWEST;
std::string str = cmdline;
if (unlikely(str.empty() == true))
return false;
@@ -434,7 +435,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
// FromCommandLine - Return all versions specified on commandline /*{{{*/
bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci,
pkgCacheFile &Cache, const char **cmdline,
- Version const &fallback, CacheSetHelper &helper) {
+ CacheSetHelper::VerSelector const fallback,
+ CacheSetHelper &helper) {
bool found = false;
for (const char **I = cmdline; *I != 0; ++I)
found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper);
@@ -444,16 +446,16 @@ bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * cons
// FromString - Returns all versions spedcified by a string /*{{{*/
bool VersionContainerInterface::FromString(VersionContainerInterface * const vci,
pkgCacheFile &Cache, std::string pkg,
- Version const &fallback, CacheSetHelper &helper,
+ CacheSetHelper::VerSelector const fallback,
+ CacheSetHelper &helper,
bool const onlyFromName) {
- PackageSet pkgset;
- if(FileExists(pkg))
- {
- PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
- if(pkgset.size() == 0)
- return false;
- return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper);
- }
+ PackageSet pkgset;
+ if(FileExists(pkg)) {
+ helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg);
+ if(pkgset.empty() == true)
+ return false;
+ return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper);
+ }
std::string ver;
bool verIsRel = false;
@@ -464,13 +466,13 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
pkg.erase(vertag);
}
if (onlyFromName == false)
- PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
+ helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg);
else {
- pkgset.insert(PackageContainerInterface::FromName(Cache, pkg, helper));
+ helper.PackageFrom(CacheSetHelper::PACKAGENAME, &pkgset, Cache, pkg);
}
bool errors = true;
- if (pkgset.getConstructor() != PackageSet::UNKNOWN)
+ if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN)
errors = helper.showErrors(false);
bool found = false;
@@ -489,7 +491,7 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
if (P->VersionList != 0)
V = P.VersionList();
else
- V = helper.canNotFindNewestVer(Cache, P);
+ V = helper.canNotGetVersion(CacheSetHelper::NEWEST, Cache, P);
} else {
pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release :
pkgVersionMatch::Version));
@@ -506,11 +508,14 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
}
if (V.end() == true)
continue;
- helper.showSelectedVersion(P, V, ver, verIsRel);
+ if (verIsRel == true)
+ helper.showVersionSelection(P, V, CacheSetHelper::RELEASE, ver);
+ else
+ helper.showVersionSelection(P, V, CacheSetHelper::VERSIONNUMBER, ver);
vci->insert(V);
found = true;
}
- if (pkgset.getConstructor() != PackageSet::UNKNOWN)
+ if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN)
helper.showErrors(errors);
return found;
}
@@ -519,30 +524,30 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci,
pkgCacheFile &Cache,
pkgCache::PkgIterator const &P,
- Version const &fallback,
+ CacheSetHelper::VerSelector const fallback,
CacheSetHelper &helper) {
pkgCache::VerIterator V;
bool showErrors;
bool found = false;
switch(fallback) {
- case ALL:
+ case CacheSetHelper::ALL:
if (P->VersionList != 0)
for (V = P.VersionList(); V.end() != true; ++V)
found |= vci->insert(V);
else
- helper.canNotFindAllVer(vci, Cache, P);
+ helper.canNotFindVersion(CacheSetHelper::ALL, vci, Cache, P);
break;
- case CANDANDINST:
+ case CacheSetHelper::CANDANDINST:
found |= vci->insert(getInstalledVer(Cache, P, helper));
found |= vci->insert(getCandidateVer(Cache, P, helper));
break;
- case CANDIDATE:
+ case CacheSetHelper::CANDIDATE:
found |= vci->insert(getCandidateVer(Cache, P, helper));
break;
- case INSTALLED:
+ case CacheSetHelper::INSTALLED:
found |= vci->insert(getInstalledVer(Cache, P, helper));
break;
- case CANDINST:
+ case CacheSetHelper::CANDINST:
showErrors = helper.showErrors(false);
V = getCandidateVer(Cache, P, helper);
if (V.end() == true)
@@ -551,9 +556,9 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc
if (V.end() == false)
found |= vci->insert(V);
else
- helper.canNotFindInstCandVer(vci, Cache, P);
+ helper.canNotFindVersion(CacheSetHelper::CANDINST, vci, Cache, P);
break;
- case INSTCAND:
+ case CacheSetHelper::INSTCAND:
showErrors = helper.showErrors(false);
V = getInstalledVer(Cache, P, helper);
if (V.end() == true)
@@ -562,14 +567,18 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc
if (V.end() == false)
found |= vci->insert(V);
else
- helper.canNotFindInstCandVer(vci, Cache, P);
+ helper.canNotFindVersion(CacheSetHelper::INSTCAND, vci, Cache, P);
break;
- case NEWEST:
+ case CacheSetHelper::NEWEST:
if (P->VersionList != 0)
found |= vci->insert(P.VersionList());
else
- helper.canNotFindNewestVer(Cache, P);
+ helper.canNotFindVersion(CacheSetHelper::NEWEST, vci, Cache, P);
break;
+ case CacheSetHelper::RELEASE:
+ case CacheSetHelper::VERSIONNUMBER:
+ // both make no sense here, so always false
+ return false;
}
return found;
}
@@ -586,7 +595,7 @@ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &C
Cand = Cache[Pkg].CandidateVerIter(Cache);
}
if (Cand.end() == true)
- return helper.canNotFindCandidateVer(Cache, Pkg);
+ return helper.canNotGetVersion(CacheSetHelper::CANDIDATE, Cache, Pkg);
return Cand;
}
/*}}}*/
@@ -594,19 +603,31 @@ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &C
pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
if (Pkg->CurrentVer == 0)
- return helper.canNotFindInstalledVer(Cache, Pkg);
+ return helper.canNotGetVersion(CacheSetHelper::INSTALLED, Cache, Pkg);
return Pkg.CurrentVer();
}
/*}}}*/
-// canNotFindPkgName - handle the case no package has this name /*{{{*/
-pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
- std::string const &str) {
- if (ShowError == true)
- _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
- return pkgCache::PkgIterator(Cache, 0);
+// canNotFindPackage - with the given selector and pattern /*{{{*/
+void CacheSetHelper::canNotFindPackage(enum PkgSelector const select,
+ PackageContainerInterface * const pci, pkgCacheFile &Cache,
+ std::string const &pattern) {
+ switch (select) {
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ case REGEX: canNotFindRegEx(pci, Cache, pattern); break;
+ case TASK: canNotFindTask(pci, Cache, pattern); break;
+ case FNMATCH: canNotFindFnmatch(pci, Cache, pattern); break;
+ case PACKAGENAME: canNotFindPackage(pci, Cache, pattern); break;
+ case STRING: canNotFindPackage(pci, Cache, pattern); break;
+ case UNKNOWN: break;
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
+ }
}
- /*}}}*/
// canNotFindTask - handle the case no package is found for a task /*{{{*/
void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
if (ShowError == true)
@@ -618,17 +639,50 @@ void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/,
if (ShowError == true)
_error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
}
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+ /*}}}*/
// canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
if (ShowError == true)
_error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
}
-#endif /*}}}*/
+ /*}}}*/
// canNotFindPackage - handle the case no package is found from a string/*{{{*/
APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
}
/*}}}*/
+ /*}}}*/
+// canNotFindPkgName - handle the case no package has this name /*{{{*/
+pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
+ std::string const &str) {
+ if (ShowError == true)
+ _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
+ return pkgCache::PkgIterator(Cache, 0);
+}
+ /*}}}*/
+// canNotFindVersion - for package by selector /*{{{*/
+void CacheSetHelper::canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg)
+{
+ switch (select) {
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ case ALL: canNotFindAllVer(vci, Cache, Pkg); break;
+ case INSTCAND: canNotFindInstCandVer(vci, Cache, Pkg); break;
+ case CANDINST: canNotFindCandInstVer(vci, Cache, Pkg); break;
+ case NEWEST: canNotFindNewestVer(Cache, Pkg); break;
+ case CANDIDATE: canNotFindCandidateVer(Cache, Pkg); break;
+ case INSTALLED: canNotFindInstalledVer(Cache, Pkg); break;
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
+ case CANDANDINST: canNotGetCandInstVer(Cache, Pkg); break;
+ case RELEASE:
+ case VERSIONNUMBER:
+ // invalid in this branch
+ break;
+ }
+}
// canNotFindAllVer /*{{{*/
void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
pkgCache::PkgIterator const &Pkg) {
@@ -637,19 +691,42 @@ void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/,
}
/*}}}*/
// canNotFindInstCandVer /*{{{*/
-void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
+void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg) {
- if (ShowError == true)
- _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+ canNotGetInstCandVer(Cache, Pkg);
}
/*}}}*/
// canNotFindInstCandVer /*{{{*/
-void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
+void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg) {
- if (ShowError == true)
- _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+ canNotGetCandInstVer(Cache, Pkg);
}
/*}}}*/
+ /*}}}*/
+// canNotGetVersion - for package by selector /*{{{*/
+pkgCache::VerIterator CacheSetHelper::canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
+ switch (select) {
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ case NEWEST: return canNotFindNewestVer(Cache, Pkg);
+ case CANDIDATE: return canNotFindCandidateVer(Cache, Pkg);
+ case INSTALLED: return canNotFindInstalledVer(Cache, Pkg);
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
+ case CANDINST: return canNotGetCandInstVer(Cache, Pkg);
+ case INSTCAND: return canNotGetInstCandVer(Cache, Pkg);
+ case ALL:
+ case CANDANDINST:
+ case RELEASE:
+ case VERSIONNUMBER:
+ // invalid in this branch
+ return pkgCache::VerIterator(Cache, 0);
+ }
+ return pkgCache::VerIterator(Cache, 0);
+}
// canNotFindNewestVer /*{{{*/
pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg) {
@@ -674,6 +751,42 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache
return pkgCache::VerIterator(Cache, 0);
}
/*}}}*/
+// canNotFindInstCandVer /*{{{*/
+pkgCache::VerIterator CacheSetHelper::canNotGetInstCandVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg) {
+ if (ShowError == true)
+ _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+ return pkgCache::VerIterator(Cache, 0);
+}
+ /*}}}*/
+// canNotFindInstCandVer /*{{{*/
+pkgCache::VerIterator CacheSetHelper::canNotGetCandInstVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg) {
+ if (ShowError == true)
+ _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+ return pkgCache::VerIterator(Cache, 0);
+}
+ /*}}}*/
+ /*}}}*/
+// showPackageSelection - by selector and given pattern /*{{{*/
+APT_CONST void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator const &pkg, enum PkgSelector const select,
+ std::string const &pattern) {
+ switch (select) {
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ case REGEX: showRegExSelection(pkg, pattern); break;
+ case TASK: showTaskSelection(pkg, pattern); break;
+ case FNMATCH: showFnmatchSelection(pkg, pattern); break;
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
+ case PACKAGENAME: /* no suprises here */ break;
+ case STRING: /* handled by the special cases */ break;
+ case UNKNOWN: break;
+ }
+}
// showTaskSelection /*{{{*/
APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
std::string const &/*pattern*/) {
@@ -684,14 +797,41 @@ APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/
std::string const &/*pattern*/) {
}
/*}}}*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
// showFnmatchSelection /*{{{*/
APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
std::string const &/*pattern*/) {
}
/*}}}*/
+ /*}}}*/
+// showVersionSelection /*{{{*/
+APT_CONST void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver, enum VerSelector const select, std::string const &pattern) {
+ switch (select) {
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ case RELEASE:
+ showSelectedVersion(Pkg, Ver, pattern, true);
+ break;
+ case VERSIONNUMBER:
+ showSelectedVersion(Pkg, Ver, pattern, false);
+ break;
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
-// showSelectedVersion /*{{{*/
+ case NEWEST:
+ case CANDIDATE:
+ case INSTALLED:
+ case CANDINST:
+ case INSTCAND:
+ case ALL:
+ case CANDANDINST:
+ // not really suprises, but in fact: just not implemented
+ break;
+ }
+}
APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
pkgCache::VerIterator const /*Ver*/,
std::string const &/*ver*/,
diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h
index 36f41c34d..892ad2dfc 100644
--- a/apt-pkg/cacheset.h
+++ b/apt-pkg/cacheset.h
@@ -13,8 +13,10 @@
#include <map>
#include <set>
#include <list>
+#include <vector>
#include <string>
#include <iterator>
+#include <algorithm>
#include <stddef.h>
@@ -51,36 +53,127 @@ public: /*{{{*/
ShowError(ShowError), ErrorType(ErrorType) {}
virtual ~CacheSetHelper() {}
- virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
- virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
-#endif
- virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
- std::string const &ver, bool const verIsRel);
+ enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING };
- virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
- virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
-#endif
- virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
+ virtual bool PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
+
+ virtual bool PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline);
+
+ struct PkgModifier {
+ enum Position { NONE, PREFIX, POSTFIX };
+ unsigned short ID;
+ const char * const Alias;
+ Position Pos;
+ PkgModifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
+ };
+ virtual bool PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
+ pkgCacheFile &Cache, const char * cmdline,
+ std::list<PkgModifier> const &mods);
+
+ // use PackageFrom(PACKAGENAME, …) instead
+ APT_DEPRECATED pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern);
+
+ /** \brief be notified about the package being selected via pattern
+ *
+ * Main use is probably to show a message to the user what happened
+ *
+ * \param pkg is the package which was selected
+ * \param select is the selection method which choose the package
+ * \param pattern is the string used by the selection method to pick the package
+ */
+ virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern);
+ // use the method above instead, react only on the type you need and let the base handle the rest if need be
+ // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods
+ APT_DEPRECATED virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+ APT_DEPRECATED virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+ APT_DEPRECATED virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+
+ /** \brief be notified if a package can't be found via pattern
+ *
+ * Can be used to show a message as well as to try something else to make it match
+ *
+ * \param select is the method tried for selection
+ * \param pci is the container the package should be inserted in
+ * \param Cache is the package universe available
+ * \param pattern is the string not matching anything
+ */
+ virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
+ // same as above for showPackageSelection
+ APT_DEPRECATED virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ APT_DEPRECATED virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ APT_DEPRECATED virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ APT_DEPRECATED virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
+
+ /** \brief specifies which version(s) we want to refer to */
+ enum VerSelector {
+ /** by release string */
+ RELEASE,
+ /** by version number string */
+ VERSIONNUMBER,
+ /** All versions */
+ ALL,
+ /** Candidate and installed version */
+ CANDANDINST,
+ /** Candidate version */
+ CANDIDATE,
+ /** Installed version */
+ INSTALLED,
+ /** Candidate or if non installed version */
+ CANDINST,
+ /** Installed or if non candidate version */
+ INSTCAND,
+ /** Newest version */
+ NEWEST
+ };
+
+ /** \brief be notified about the version being selected via pattern
+ *
+ * Main use is probably to show a message to the user what happened
+ * Note that at the moment this method is only called for RELEASE
+ * and VERSION selections, not for the others.
+ *
+ * \param Pkg is the package which was selected for
+ * \param Ver is the version selected
+ * \param select is the selection method which choose the version
+ * \param pattern is the string used by the selection method to pick the version
+ */
+ virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver,
+ enum VerSelector const select, std::string const &pattern);
+ // renamed to have a similar interface to showPackageSelection
+ APT_DEPRECATED virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
+ std::string const &ver, bool const verIsRel);
- virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
- virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ /** \brief be notified if a version can't be found for a package
+ *
+ * Main use is probably to show a message to the user what happened
+ *
+ * \param select is the method tried for selection
+ * \param vci is the container the version should be inserted in
+ * \param Cache is the package universe available
+ * \param Pkg is the package we wanted a version from
+ */
+ virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+ // same as above for showPackageSelection
+ APT_DEPRECATED virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+ APT_DEPRECATED virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg);
- virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
+ APT_DEPRECATED virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg);
- virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
- virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
+ // the difference between canNotFind and canNotGet is that the later is more low-level
+ // and called from other places: In this case looking into the code is the only real answer…
+ virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+ // same as above for showPackageSelection
+ APT_DEPRECATED virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg);
- virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
+ APT_DEPRECATED virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg);
- virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
+ APT_DEPRECATED virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
pkgCache::PkgIterator const &Pkg);
+ virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
+
bool showErrors() const { return ShowError; }
bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
GlobalError::MsgType errorType() const { return ErrorType; }
@@ -98,7 +191,19 @@ public: /*{{{*/
protected:
bool ShowError;
GlobalError::MsgType ErrorType;
+
+ pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+ pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+
+ bool PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ bool PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+ bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
}; /*}}}*/
+
class PackageContainerInterface { /*{{{*/
/** \class PackageContainerInterface
@@ -151,29 +256,56 @@ public:
virtual bool empty() const = 0;
virtual void clear() = 0;
- enum Constructor { UNKNOWN, REGEX, TASK, FNMATCH };
- virtual void setConstructor(Constructor const &con) = 0;
- virtual Constructor getConstructor() const = 0;
+ // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
+ enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN,
+ REGEX = CacheSetHelper::REGEX,
+ TASK = CacheSetHelper::TASK,
+ FNMATCH = CacheSetHelper::FNMATCH };
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
- static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
- static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
- static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
- static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
- static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
- static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
- static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper);
+ void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
+ CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
+ PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN) {}
+ PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by) {}
+
+ APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+ return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
+ APT_DEPRECATED static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+ return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); }
+ APT_DEPRECATED static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+ return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); }
+ APT_DEPRECATED static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+ return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); }
+ APT_DEPRECATED static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+ return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); }
+ APT_DEPRECATED static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
+ return helper.PackageFromCommandLine(pci, Cache, cmdline); }
+
+ APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier;
- struct Modifier {
- enum Position { NONE, PREFIX, POSTFIX };
- unsigned short ID;
- const char * const Alias;
- Position Pos;
- Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
- };
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+ return helper.PackageFromName(Cache, pattern); }
+ APT_DEPRECATED static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
+ pkgCacheFile &Cache, const char * cmdline,
+ std::list<Modifier> const &mods, CacheSetHelper &helper) {
+ return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
- static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
- pkgCacheFile &Cache, const char * cmdline,
- std::list<Modifier> const &mods, CacheSetHelper &helper);
+private:
+ CacheSetHelper::PkgSelector ConstructedBy;
};
/*}}}*/
template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
@@ -237,11 +369,28 @@ public: /*{{{*/
iterator end() { return iterator(_cont.end()); }
const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
- void setConstructor(Constructor const &by) { ConstructedBy = by; }
- Constructor getConstructor() const { return ConstructedBy; }
+ PackageContainer() : PackageContainerInterface() {}
+ PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
+
+ /** \brief sort all included versions with given comparer
+
+ Some containers are sorted by default, some are not and can't be,
+ but a few like std::vector can be sorted if need be, so this can be
+ specialized in later on. The default is that this will fail though.
+ Specifically, already sorted containers like std::set will return
+ false as well as there is no easy way to check that the given comparer
+ would sort in the same way the set is currently sorted
- PackageContainer() : ConstructedBy(UNKNOWN) {}
- PackageContainer(Constructor const &by) : ConstructedBy(by) {}
+ \return \b true if the set was sorted, \b false if not. */
+ template<class Compare> bool sort(Compare /*Comp*/) { return false; }
/** \brief returns all packages in the cache who belong to the given task
@@ -252,8 +401,8 @@ public: /*{{{*/
\param pattern name of the task
\param helper responsible for error and message handling */
static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
- PackageContainer cont(TASK);
- PackageContainerInterface::FromTask(&cont, Cache, pattern, helper);
+ PackageContainer cont(CacheSetHelper::TASK);
+ helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern);
return cont;
}
static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) {
@@ -269,9 +418,9 @@ public: /*{{{*/
\param Cache the packages are in
\param pattern regular expression for package names
\param helper responsible for error and message handling */
- static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
- PackageContainer cont(REGEX);
- PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper);
+ static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+ PackageContainer cont(CacheSetHelper::REGEX);
+ helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern);
return cont;
}
@@ -280,9 +429,9 @@ public: /*{{{*/
return FromRegEx(Cache, pattern, helper);
}
- static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
- PackageContainer cont(FNMATCH);
- PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper);
+ static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+ PackageContainer cont(CacheSetHelper::FNMATCH);
+ helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern);
return cont;
}
static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) {
@@ -290,18 +439,25 @@ public: /*{{{*/
return FromFnmatch(Cache, pattern, helper);
}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
/** \brief returns a package specified by a string
\param Cache the package is in
\param pattern String the package name should be extracted from
\param helper responsible for error and message handling */
- static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
- return PackageContainerInterface::FromName(Cache, pattern, helper);
+ APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+ return helper.PackageFromName(Cache, pattern);
}
- static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
+ APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
CacheSetHelper helper;
- return PackageContainerInterface::FromName(Cache, pattern, helper);
+ return FromName(Cache, pattern, helper);
}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
/** \brief returns all packages specified by a string
@@ -310,7 +466,7 @@ public: /*{{{*/
\param helper responsible for error and message handling */
static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
PackageContainer cont;
- PackageContainerInterface::FromString(&cont, Cache, pattern, helper);
+ helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern);
return cont;
}
static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) {
@@ -327,7 +483,7 @@ public: /*{{{*/
\param helper responsible for error and message handling */
static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
PackageContainer cont;
- PackageContainerInterface::FromCommandLine(&cont, Cache, cmdline, helper);
+ helper.PackageFromCommandLine(&cont, Cache, cmdline);
return cont;
}
static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
@@ -349,14 +505,14 @@ public: /*{{{*/
static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
pkgCacheFile &Cache,
const char **cmdline,
- std::list<Modifier> const &mods,
+ std::list<CacheSetHelper::PkgModifier> const &mods,
unsigned short const &fallback,
CacheSetHelper &helper) {
std::map<unsigned short, PackageContainer> pkgsets;
for (const char **I = cmdline; *I != 0; ++I) {
unsigned short modID = fallback;
PackageContainer pkgset;
- PackageContainerInterface::FromModifierCommandLine(modID, &pkgset, Cache, *I, mods, helper);
+ helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods);
pkgsets[modID].insert(pkgset);
}
return pkgsets;
@@ -364,22 +520,23 @@ public: /*{{{*/
static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
pkgCacheFile &Cache,
const char **cmdline,
- std::list<Modifier> const &mods,
+ std::list<CacheSetHelper::PkgModifier> const &mods,
unsigned short const &fallback) {
CacheSetHelper helper;
return GroupedFromCommandLine(Cache, cmdline,
mods, fallback, helper);
}
/*}}}*/
-private: /*{{{*/
- Constructor ConstructedBy;
- /*}}}*/
}; /*}}}*/
-
+// specialisations for push_back containers: std::list & std::vector /*{{{*/
template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
_cont.push_back(*p);
}
+template<> template<class Cont> void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
+ for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
+ _cont.push_back(*p);
+}
// these two are 'inline' as otherwise the linker has problems with seeing these untemplated
// specializations again and again - but we need to see them, so that library users can use them
template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
@@ -388,12 +545,65 @@ template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::inse
_cont.push_back(P);
return true;
}
+template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
+ if (P.end() == true)
+ return false;
+ _cont.push_back(P);
+ return true;
+}
template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
for (const_iterator p = begin; p != end; ++p)
_cont.push_back(*p);
}
+template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
+ for (const_iterator p = begin; p != end; ++p)
+ _cont.push_back(*p);
+}
+ /*}}}*/
+
+template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) {
+ std::sort(_cont.begin(), _cont.end(), Comp);
+ return true;
+}
+
+// class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/
+/** \class PackageUniverse
+
+ Wraps around our usual pkgCache, so that it can be stuffed into methods
+ expecting a PackageContainer.
+
+ The wrapping is read-only in practice modeled by making erase and co
+ private methods. */
+class PackageUniverse : public PackageContainerInterface {
+ pkgCache * const _cont;
+public:
+ typedef pkgCache::PkgIterator iterator;
+ typedef pkgCache::PkgIterator const_iterator;
+
+ bool empty() const { return false; }
+ size_t size() const { return _cont->Head().PackageCount; }
+
+ const_iterator begin() const { return _cont->PkgBegin(); }
+ const_iterator end() const { return _cont->PkgEnd(); }
+ iterator begin() { return _cont->PkgBegin(); }
+ iterator end() { return _cont->PkgEnd(); }
+
+ PackageUniverse(pkgCache * const Owner) : _cont(Owner) { }
+
+private:
+ bool insert(pkgCache::PkgIterator const &) { return true; }
+ template<class Cont> void insert(PackageContainer<Cont> const &) { }
+ void insert(const_iterator, const_iterator) { }
+
+ void clear() { }
+ iterator& erase(iterator &iter) { return iter; }
+ size_t erase(const pkgCache::PkgIterator) { return 0; }
+ void erase(iterator, iterator) { }
+};
+ /*}}}*/
typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
+typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector;
class VersionContainerInterface { /*{{{*/
/** \class APT::VersionContainerInterface
@@ -435,45 +645,83 @@ public:
virtual void clear() = 0;
/** \brief specifies which version(s) will be returned if non is given */
- enum Version {
- /** All versions */
- ALL,
- /** Candidate and installed version */
- CANDANDINST,
- /** Candidate version */
- CANDIDATE,
- /** Installed version */
- INSTALLED,
- /** Candidate or if non installed version */
- CANDINST,
- /** Installed or if non candidate version */
- INSTCAND,
- /** Newest version */
- NEWEST
+ enum APT_DEPRECATED Version {
+ ALL = CacheSetHelper::ALL,
+ CANDANDINST = CacheSetHelper::CANDANDINST,
+ CANDIDATE = CacheSetHelper::CANDIDATE,
+ INSTALLED = CacheSetHelper::INSTALLED,
+ CANDINST = CacheSetHelper::CANDINST,
+ INSTCAND = CacheSetHelper::INSTCAND,
+ NEWEST = CacheSetHelper::NEWEST
};
struct Modifier {
- enum Position { NONE, PREFIX, POSTFIX };
- unsigned short ID;
+ unsigned short const ID;
const char * const Alias;
- Position Pos;
- Version SelectVersion;
+ enum Position { NONE, PREFIX, POSTFIX } const Pos;
+ enum CacheSetHelper::VerSelector const SelectVersion;
Modifier (unsigned short const &id, const char * const alias, Position const &pos,
- Version const &select) : ID(id), Alias(alias), Pos(pos),
+ enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
SelectVersion(select) {}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED Modifier(unsigned short const &id, const char * const alias, Position const &pos,
+ Version const &select) : ID(id), Alias(alias), Pos(pos),
+ SelectVersion((CacheSetHelper::VerSelector)select) {}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
};
static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
- const char **cmdline, Version const &fallback,
+ const char **cmdline, CacheSetHelper::VerSelector const fallback,
CacheSetHelper &helper);
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ const char **cmdline, Version const &fallback,
+ CacheSetHelper &helper) {
+ return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
- std::string pkg, Version const &fallback, CacheSetHelper &helper,
+ std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
bool const onlyFromName = false);
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ std::string pkg, Version const &fallback, CacheSetHelper &helper,
+ bool const onlyFromName = false) {
+ return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
- pkgCache::PkgIterator const &P, Version const &fallback,
+ pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
CacheSetHelper &helper);
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &P, Version const &fallback,
+ CacheSetHelper &helper) {
+ return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
static bool FromModifierCommandLine(unsigned short &modID,
VersionContainerInterface * const vci,
@@ -485,8 +733,22 @@ public:
static bool FromDependency(VersionContainerInterface * const vci,
pkgCacheFile &Cache,
pkgCache::DepIterator const &D,
- Version const &selector,
+ CacheSetHelper::VerSelector const selector,
CacheSetHelper &helper);
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci,
+ pkgCacheFile &Cache,
+ pkgCache::DepIterator const &D,
+ Version const &selector,
+ CacheSetHelper &helper) {
+ return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
protected: /*{{{*/
@@ -568,6 +830,18 @@ public: /*{{{*/
iterator end() { return iterator(_cont.end()); }
const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }
+ /** \brief sort all included versions with given comparer
+
+ Some containers are sorted by default, some are not and can't be,
+ but a few like std::vector can be sorted if need be, so this can be
+ specialized in later on. The default is that this will fail though.
+ Specifically, already sorted containers like std::set will return
+ false as well as there is no easy way to check that the given comparer
+ would sort in the same way the set is currently sorted
+
+ \return \b true if the set was sorted, \b false if not. */
+ template<class Compare> bool sort(Compare /*Comp*/) { return false; }
+
/** \brief returns all versions specified on the commandline
Get all versions from the commandline, uses given default version if
@@ -577,35 +851,64 @@ public: /*{{{*/
\param fallback version specification
\param helper responsible for error and message handling */
static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
- Version const &fallback, CacheSetHelper &helper) {
+ CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
VersionContainer vercon;
VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
return vercon;
}
static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
- Version const &fallback) {
+ CacheSetHelper::VerSelector const fallback) {
CacheSetHelper helper;
return FromCommandLine(Cache, cmdline, fallback, helper);
}
static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
- return FromCommandLine(Cache, cmdline, CANDINST);
+ return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST);
}
-
static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
- Version const &fallback, CacheSetHelper &helper,
+ CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
bool const /*onlyFromName = false*/) {
VersionContainer vercon;
VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
return vercon;
}
static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
- Version const &fallback) {
+ CacheSetHelper::VerSelector const fallback) {
CacheSetHelper helper;
return FromString(Cache, pkg, fallback, helper);
}
static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
- return FromString(Cache, pkg, CANDINST);
+ return FromString(Cache, pkg, CacheSetHelper::CANDINST);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
+ Version const &fallback, CacheSetHelper &helper) {
+ VersionContainer vercon;
+ VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
+ return vercon;
+ }
+ static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
+ Version const &fallback) {
+ CacheSetHelper helper;
+ return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
+ }
+ static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
+ Version const &fallback, CacheSetHelper &helper,
+ bool const /*onlyFromName = false*/) {
+ VersionContainer vercon;
+ VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
+ return vercon;
+ }
+ static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
+ Version const &fallback) {
+ CacheSetHelper helper;
+ return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
/** \brief returns all versions specified for the package
@@ -614,18 +917,36 @@ public: /*{{{*/
\param fallback the version(s) you want to get
\param helper the helper used for display and error handling */
static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
- Version const &fallback, CacheSetHelper &helper) {
+ CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
VersionContainer vercon;
VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
return vercon;
}
static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
- Version const &fallback) {
+ CacheSetHelper::VerSelector const fallback) {
CacheSetHelper helper;
return FromPackage(Cache, P, fallback, helper);
}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
+ Version const &fallback, CacheSetHelper &helper) {
+ VersionContainer vercon;
+ VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
+ return vercon;
+ }
+ static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
+ Version const &fallback) {
+ CacheSetHelper helper;
+ return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
- return FromPackage(Cache, P, CANDIDATE);
+ return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
}
static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
@@ -654,26 +975,48 @@ public: /*{{{*/
}
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
- Version const &selector, CacheSetHelper &helper) {
+ CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) {
VersionContainer vercon;
VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
return vercon;
}
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
- Version const &selector) {
+ CacheSetHelper::VerSelector const selector) {
CacheSetHelper helper;
return FromPackage(Cache, D, selector, helper);
}
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
+ Version const &selector, CacheSetHelper &helper) {
+ VersionContainer vercon;
+ VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+ return vercon;
+ }
+ static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
+ Version const &selector) {
+ CacheSetHelper helper;
+ return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+ }
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
- return FromPackage(Cache, D, CANDIDATE);
+ return FromPackage(Cache, D, CacheSetHelper::CANDIDATE);
}
/*}}}*/
}; /*}}}*/
-
+// specialisations for push_back containers: std::list & std::vector /*{{{*/
template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
_cont.push_back(*v);
}
+template<> template<class Cont> void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
+ for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
+ _cont.push_back(*v);
+}
// these two are 'inline' as otherwise the linker has problems with seeing these untemplated
// specializations again and again - but we need to see them, so that library users can use them
template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
@@ -682,11 +1025,29 @@ template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::inse
_cont.push_back(V);
return true;
}
+template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
+ if (V.end() == true)
+ return false;
+ _cont.push_back(V);
+ return true;
+}
template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
for (const_iterator v = begin; v != end; ++v)
_cont.push_back(*v);
}
+template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
+ for (const_iterator v = begin; v != end; ++v)
+ _cont.push_back(*v);
+}
+ /*}}}*/
+
+template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
+ std::sort(_cont.begin(), _cont.end(), Comp);
+ return true;
+}
+
typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
+typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector;
}
#endif
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc
index a5ad6a9ff..b97f7b036 100644
--- a/apt-pkg/cdrom.cc
+++ b/apt-pkg/cdrom.cc
@@ -913,10 +913,14 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
return true;
}
/*}}}*/
-pkgUdevCdromDevices::pkgUdevCdromDevices() /*{{{*/
- : libudev_handle(NULL)
+pkgUdevCdromDevices::pkgUdevCdromDevices() /*{{{*/
+: libudev_handle(NULL), udev_new(NULL), udev_enumerate_add_match_property(NULL),
+ udev_enumerate_scan_devices(NULL), udev_enumerate_get_list_entry(NULL),
+ udev_device_new_from_syspath(NULL), udev_enumerate_get_udev(NULL),
+ udev_list_entry_get_name(NULL), udev_device_get_devnode(NULL),
+ udev_enumerate_new(NULL), udev_list_entry_get_next(NULL),
+ udev_device_get_property_value(NULL), udev_enumerate_add_match_sysattr(NULL)
{
-
}
/*}}}*/
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index 3799c822d..93c1f4664 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -47,23 +47,26 @@ CommandLine::~CommandLine()
char const * CommandLine::GetCommand(Dispatch const * const Map,
unsigned int const argc, char const * const * const argv)
{
- // if there is a -- on the line there must be the word we search for around it
- // as -- marks the end of the options, just not sure if the command can be
- // considered an option or not, so accept both
+ // if there is a -- on the line there must be the word we search for either
+ // before it (as -- marks the end of the options) or right after it (as we can't
+ // decide if the command is actually an option, given that in theory, you could
+ // have parameters named like commands)
for (size_t i = 1; i < argc; ++i)
{
if (strcmp(argv[i], "--") != 0)
continue;
- ++i;
- if (i < argc)
+ // check if command is before --
+ for (size_t k = 1; k < i; ++k)
for (size_t j = 0; Map[j].Match != NULL; ++j)
- if (strcmp(argv[i], Map[j].Match) == 0)
+ if (strcmp(argv[k], Map[j].Match) == 0)
return Map[j].Match;
- i -= 2;
- if (i != 0)
+ // see if the next token after -- is the command
+ ++i;
+ if (i < argc)
for (size_t j = 0; Map[j].Match != NULL; ++j)
if (strcmp(argv[i], Map[j].Match) == 0)
return Map[j].Match;
+ // we found a --, but not a command
return NULL;
}
// no --, so search for the first word matching a command
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index e81f32a52..df409fa36 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -896,7 +896,7 @@ class FileFdPrivate { /*{{{*/
bool eof;
bool compressing;
- LZMAFILE() : file(NULL), eof(false), compressing(false) {}
+ LZMAFILE() : file(NULL), eof(false), compressing(false) { buffer[0] = '\0'; }
~LZMAFILE() {
if (compressing == true)
{
@@ -2126,10 +2126,8 @@ bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode)
int Pipe[2] = {-1, -1};
if(pipe(Pipe) != 0)
- {
return _error->Errno("pipe", _("Failed to create subprocess IPC"));
- return NULL;
- }
+
std::set<int> keep_fds;
keep_fds.insert(Pipe[0]);
keep_fds.insert(Pipe[1]);
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index f24dd9640..9d798cca9 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -32,50 +32,30 @@ static char * GenerateTemporaryFileTemplate(const char *basename) /*{{{*/
/*}}}*/
// ExecGPGV - returns the command needed for verify /*{{{*/
// ---------------------------------------------------------------------
-/* Generating the commandline for calling gpgv is somehow complicated as
+/* Generating the commandline for calling gpg is somehow complicated as
we need to add multiple keyrings and user supplied options.
- Also, as gpgv has no options to enforce a certain reduced style of
+ Also, as gpg has no options to enforce a certain reduced style of
clear-signed files (=the complete content of the file is signed and
the content isn't encoded) we do a divide and conquer approach here
- and split up the clear-signed file in message and signature for gpgv
+ and split up the clear-signed file in message and signature for gpg.
+ And as a cherry on the cake, we use our apt-key wrapper to do part
+ of the lifting in regards to merging keyrings. Fun for the whole family.
*/
void ExecGPGV(std::string const &File, std::string const &FileGPG,
int const &statusfd, int fd[2])
{
#define EINTERNAL 111
- std::string const gpgvpath = _config->Find("Dir::Bin::gpg", "/usr/bin/gpgv");
- // FIXME: remove support for deprecated APT::GPGV setting
- std::string const trustedFile = _config->Find("APT::GPGV::TrustedKeyring", _config->FindFile("Dir::Etc::Trusted"));
- std::string const trustedPath = _config->FindDir("Dir::Etc::TrustedParts");
+ std::string const aptkey = _config->FindFile("Dir::Bin::apt-key", "/usr/bin/apt-key");
bool const Debug = _config->FindB("Debug::Acquire::gpgv", false);
- if (Debug == true)
- {
- std::clog << "gpgv path: " << gpgvpath << std::endl;
- std::clog << "Keyring file: " << trustedFile << std::endl;
- std::clog << "Keyring path: " << trustedPath << std::endl;
- }
-
- std::vector<std::string> keyrings;
- if (DirectoryExists(trustedPath))
- keyrings = GetListOfFilesInDir(trustedPath, "gpg", false, true);
- if (RealFileExists(trustedFile) == true)
- keyrings.push_back(trustedFile);
-
std::vector<const char *> Args;
- Args.reserve(30);
-
- if (keyrings.empty() == true)
- {
- // TRANSLATOR: %s is the trusted keyring parts directory
- ioprintf(std::cerr, _("No keyring installed in %s."),
- _config->FindDir("Dir::Etc::TrustedParts").c_str());
- exit(EINTERNAL);
- }
+ Args.reserve(10);
- Args.push_back(gpgvpath.c_str());
- Args.push_back("--ignore-time-conflict");
+ Args.push_back(aptkey.c_str());
+ Args.push_back("--quiet");
+ Args.push_back("--readonly");
+ Args.push_back("verify");
char statusfdstr[10];
if (statusfd != -1)
@@ -85,13 +65,6 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
Args.push_back(statusfdstr);
}
- for (std::vector<std::string>::const_iterator K = keyrings.begin();
- K != keyrings.end(); ++K)
- {
- Args.push_back("--keyring");
- Args.push_back(K->c_str());
- }
-
Configuration::Item const *Opts;
Opts = _config->Tree("Acquire::gpgv::Options");
if (Opts != 0)
@@ -160,7 +133,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
if (Debug == true)
{
- std::clog << "Preparing to exec: " << gpgvpath;
+ std::clog << "Preparing to exec: ";
for (std::vector<const char *>::const_iterator a = Args.begin(); *a != NULL; ++a)
std::clog << " " << *a;
std::clog << std::endl;
@@ -168,7 +141,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
if (statusfd != -1)
{
- int const nullfd = open("/dev/null", O_RDONLY);
+ int const nullfd = open("/dev/null", O_WRONLY);
close(fd[0]);
// Redirect output to /dev/null; we read from the status fd
if (statusfd != STDOUT_FILENO)
@@ -185,7 +158,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
if (releaseSignature == DETACHED)
{
- execvp(gpgvpath.c_str(), (char **) &Args[0]);
+ execvp(Args[0], (char **) &Args[0]);
ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str());
exit(EINTERNAL);
}
@@ -205,7 +178,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
{
if (statusfd != -1)
dup2(fd[1], statusfd);
- execvp(gpgvpath.c_str(), (char **) &Args[0]);
+ execvp(Args[0], (char **) &Args[0]);
ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str());
UNLINK_EXIT(EINTERNAL);
}
@@ -216,7 +189,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
{
if (errno == EINTR)
continue;
- ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "gpgv");
+ ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "apt-key");
UNLINK_EXIT(EINTERNAL);
}
#undef UNLINK_EXIT
@@ -229,14 +202,14 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
// check if it exit'ed normally …
if (WIFEXITED(Status) == false)
{
- ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "gpgv");
+ ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "apt-key");
exit(EINTERNAL);
}
// … and with a good exit code
if (WEXITSTATUS(Status) != 0)
{
- ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "gpgv", WEXITSTATUS(Status));
+ ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "apt-key", WEXITSTATUS(Status));
exit(WEXITSTATUS(Status));
}
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index feda8d0d8..f90731dd2 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -81,14 +81,18 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
{
string SourcesURI = _config->FindDir("Dir::State::lists") +
URItoFileName(IndexURI("Sources"));
- string SourcesURIgzip = SourcesURI + ".gz";
- if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip))
- return NULL;
- else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip))
- SourcesURI = SourcesURIgzip;
-
- return new debSrcRecordParser(SourcesURI,this);
+ std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+ for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+ {
+ string p;
+ p = SourcesURI + '.' + *t;
+ if (FileExists(p))
+ return new debSrcRecordParser(p, this);
+ }
+ if (FileExists(SourcesURI))
+ return new debSrcRecordParser(SourcesURI, this);
+ return NULL;
}
/*}}}*/
// SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/
@@ -130,11 +134,15 @@ string debSourcesIndex::Info(const char *Type) const
inline string debSourcesIndex::IndexFile(const char *Type) const
{
string s = URItoFileName(IndexURI(Type));
- string sgzip = s + ".gz";
- if (!FileExists(s) && FileExists(sgzip))
- return sgzip;
- else
- return s;
+
+ std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+ for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+ {
+ string p = s + '.' + *t;
+ if (FileExists(p))
+ return p;
+ }
+ return s;
}
string debSourcesIndex::IndexURI(const char *Type) const
@@ -260,11 +268,15 @@ string debPackagesIndex::Info(const char *Type) const
inline string debPackagesIndex::IndexFile(const char *Type) const
{
string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
- string sgzip = s + ".gz";
- if (!FileExists(s) && FileExists(sgzip))
- return sgzip;
- else
- return s;
+
+ std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+ for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+ {
+ string p = s + '.' + *t;
+ if (FileExists(p))
+ return p;
+ }
+ return s;
}
string debPackagesIndex::IndexURI(const char *Type) const
{
@@ -412,11 +424,15 @@ debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section
inline string debTranslationsIndex::IndexFile(const char *Type) const
{
string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
- string sgzip = s + ".gz";
- if (!FileExists(s) && FileExists(sgzip))
- return sgzip;
- else
- return s;
+
+ std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+ for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+ {
+ string p = s + '.' + *t;
+ if (FileExists(p))
+ return p;
+ }
+ return s;
}
string debTranslationsIndex::IndexURI(const char *Type) const
{
@@ -619,7 +635,7 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
CFile->Size = Pkg.FileSize();
CFile->mtime = Pkg.ModificationTime();
- map_stringitem_t const storage = Gen.WriteUniqString("now");
+ map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "now");
CFile->Archive = storage;
if (Gen.MergeList(Parser) == false)
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 3e0d3a791..103b126de 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -58,18 +58,6 @@ debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File),
MultiArchEnabled = Architectures.size() > 1;
}
/*}}}*/
-// ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-map_stringitem_t debListParser::UniqFindTagWrite(const char *Tag)
-{
- const char *Start;
- const char *Stop;
- if (Section.Find(Tag,Start,Stop) == false)
- return 0;
- return WriteUniqString(Start,Stop - Start);
-}
- /*}}}*/
// ListParser::Package - Return the package name /*{{{*/
// ---------------------------------------------------------------------
/* This is to return the name of the package this section describes */
@@ -144,9 +132,67 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/
/* */
bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
{
+ const char *Start;
+ const char *Stop;
+
// Parse the section
- unsigned long const idxSection = UniqFindTagWrite("Section");
- Ver->Section = idxSection;
+ if (Section.Find("Section",Start,Stop) == true)
+ {
+ map_stringitem_t const idx = StoreString(pkgCacheGenerator::SECTION, Start, Stop - Start);
+ Ver->Section = idx;
+ }
+ // Parse the source package name
+ pkgCache::GrpIterator const G = Ver.ParentPkg().Group();
+ Ver->SourcePkgName = G->Name;
+ Ver->SourceVerStr = Ver->VerStr;
+ if (Section.Find("Source",Start,Stop) == true)
+ {
+ const char * const Space = (const char * const) memchr(Start, ' ', Stop - Start);
+ pkgCache::VerIterator V;
+
+ if (Space != NULL)
+ {
+ Stop = Space;
+ const char * const Open = (const char * const) memchr(Space, '(', Stop - Space);
+ if (likely(Open != NULL))
+ {
+ const char * const Close = (const char * const) memchr(Open, ')', Stop - Open);
+ if (likely(Close != NULL))
+ {
+ std::string const version(Open + 1, (Close - Open) - 1);
+ if (version != Ver.VerStr())
+ {
+ map_stringitem_t const idx = StoreString(pkgCacheGenerator::VERSION, version);
+ Ver->SourceVerStr = idx;
+ }
+ }
+ }
+ }
+
+ std::string const pkgname(Start, Stop - Start);
+ if (pkgname != G.Name())
+ {
+ for (pkgCache::PkgIterator P = G.PackageList(); P.end() == false; P = G.NextPkg(P))
+ {
+ for (V = P.VersionList(); V.end() == false; ++V)
+ {
+ if (pkgname == V.SourcePkgName())
+ {
+ Ver->SourcePkgName = V->SourcePkgName;
+ break;
+ }
+ }
+ if (V.end() == false)
+ break;
+ }
+ if (V.end() == true)
+ {
+ map_stringitem_t const idx = StoreString(pkgCacheGenerator::PKGNAME, pkgname);
+ Ver->SourcePkgName = idx;
+ }
+ }
+ }
+
Ver->MultiArch = ParseMultiArch(true);
// Archive Size
Ver->Size = Section.FindULL("Size");
@@ -155,10 +201,8 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
Ver->InstalledSize *= 1024;
// Priority
- const char *Start;
- const char *Stop;
if (Section.Find("Priority",Start,Stop) == true)
- {
+ {
if (GrabWord(string(Start,Stop-Start),PrioList,Ver->Priority) == false)
Ver->Priority = pkgCache::State::Extra;
}
@@ -891,7 +935,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
{
// apt-secure does no longer download individual (per-section) Release
// file. to provide Component pinning we use the section name now
- map_stringitem_t const storage = WriteUniqString(component);
+ map_stringitem_t const storage = StoreString(pkgCacheGenerator::MIXED, component);
FileI->Component = storage;
pkgTagFile TagFile(&File, File.Size());
@@ -900,19 +944,19 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
return false;
std::string data;
- #define APT_INRELEASE(TAG, STORE) \
+ #define APT_INRELEASE(TYPE, TAG, STORE) \
data = Section.FindS(TAG); \
if (data.empty() == false) \
{ \
- map_stringitem_t const storage = WriteUniqString(data); \
+ map_stringitem_t const storage = StoreString(pkgCacheGenerator::TYPE, data); \
STORE = storage; \
}
- APT_INRELEASE("Suite", FileI->Archive)
- APT_INRELEASE("Component", FileI->Component)
- APT_INRELEASE("Version", FileI->Version)
- APT_INRELEASE("Origin", FileI->Origin)
- APT_INRELEASE("Codename", FileI->Codename)
- APT_INRELEASE("Label", FileI->Label)
+ APT_INRELEASE(MIXED, "Suite", FileI->Archive)
+ APT_INRELEASE(MIXED, "Component", FileI->Component)
+ APT_INRELEASE(VERSION, "Version", FileI->Version)
+ APT_INRELEASE(MIXED, "Origin", FileI->Origin)
+ APT_INRELEASE(MIXED, "Codename", FileI->Codename)
+ APT_INRELEASE(MIXED, "Label", FileI->Label)
#undef APT_INRELEASE
Section.FindFlag("NotAutomatic", FileI->Flags, pkgCache::Flag::NotAutomatic);
Section.FindFlag("ButAutomaticUpgrades", FileI->Flags, pkgCache::Flag::ButAutomaticUpgrades);
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index f5ac47e1e..b55e57d41 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -49,7 +49,6 @@ class debListParser : public pkgCacheGenerator::ListParser
std::vector<std::string> Architectures;
bool MultiArchEnabled;
- map_stringitem_t UniqFindTagWrite(const char *Tag);
virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag,
unsigned int Type);
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index a5c05d5ea..95fae9a28 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -1754,11 +1754,6 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
if (Ver.end() == true)
return;
pkgver = Ver.VerStr() == NULL ? "unknown" : Ver.VerStr();
- pkgRecords Recs(Cache);
- pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
- srcpkgname = Parse.SourcePkg();
- if(srcpkgname.empty())
- srcpkgname = pkgname;
// if the file exists already, we check:
// - if it was reported already (touched by apport).
@@ -1809,7 +1804,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
time_t now = time(NULL);
fprintf(report, "Date: %s" , ctime(&now));
fprintf(report, "Package: %s %s\n", pkgname.c_str(), pkgver.c_str());
- fprintf(report, "SourcePackage: %s\n", srcpkgname.c_str());
+ fprintf(report, "SourcePackage: %s\n", Ver.SourcePkgName());
fprintf(report, "ErrorMessage:\n %s\n", errormsg);
// ensure that the log is flushed
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc
index 0d0418e06..2ba914b16 100644
--- a/apt-pkg/edsp.cc
+++ b/apt-pkg/edsp.cc
@@ -95,12 +95,8 @@ bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
pkgCache::VerIterator const &Ver)
{
- pkgRecords Recs(Cache);
- pkgRecords::Parser &rec = Recs.Lookup(Ver.FileList());
- string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg();
-
fprintf(output, "Package: %s\n", Pkg.Name());
- fprintf(output, "Source: %s\n", srcpkg.c_str());
+ fprintf(output, "Source: %s\n", Ver.SourcePkgName());
fprintf(output, "Architecture: %s\n", Ver.Arch());
fprintf(output, "Version: %s\n", Ver.VerStr());
if (Pkg.CurrentVer() == Ver)
diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc
index e013dd44c..c38f24567 100644
--- a/apt-pkg/edsp/edspindexfile.cc
+++ b/apt-pkg/edsp/edspindexfile.cc
@@ -56,7 +56,7 @@ bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
CFile->Size = Pkg.FileSize();
CFile->mtime = Pkg.ModificationTime();
- map_stringitem_t const storage = Gen.WriteUniqString("edsp::scenario");
+ map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "edsp::scenario");
CFile->Archive = storage;
if (Gen.MergeList(Parser) == false)
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index cf6c85912..0d180d59b 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -21,6 +21,8 @@
namespace APT {
namespace Progress {
+PackageManager::PackageManager() : d(NULL), percentage(0.0), last_reported_progress(-1) {};
+PackageManager::~PackageManager() {};
/* Return a APT::Progress::PackageManager based on the global
* apt configuration (i.e. APT::Status-Fd and APT::Status-deb822-Fd)
diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h
index 5d1a20e9b..912700e8d 100644
--- a/apt-pkg/install-progress.h
+++ b/apt-pkg/install-progress.h
@@ -26,9 +26,8 @@ namespace Progress {
int last_reported_progress;
public:
- PackageManager()
- : percentage(0.0), last_reported_progress(-1) {};
- virtual ~PackageManager() {};
+ PackageManager();
+ virtual ~PackageManager();
/* Global Start/Stop */
virtual void Start(int /*child_pty*/=-1) {};
diff --git a/apt-pkg/metaindex.h b/apt-pkg/metaindex.h
index ffabaadbf..7c4d0c1aa 100644
--- a/apt-pkg/metaindex.h
+++ b/apt-pkg/metaindex.h
@@ -53,7 +53,7 @@ class metaIndex
metaIndex(std::string const &URI, std::string const &Dist,
char const * const Type)
- : Indexes(NULL), Type(Type), URI(URI), Dist(Dist)
+ : Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(false)
{
/* nothing */
}
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index e4cd1dc3b..101912f9d 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -1080,7 +1080,7 @@ pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
return Failed;
return Res;
-};
+}
#else
pkgPackageManager::OrderResult
pkgPackageManager::DoInstallPostFork(int statusFd)
diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h
index 4972dcd04..5bcd2045d 100644
--- a/apt-pkg/packagemanager.h
+++ b/apt-pkg/packagemanager.h
@@ -47,8 +47,8 @@ class pkgRecords;
namespace APT {
namespace Progress {
class PackageManager;
- };
-};
+ }
+}
class pkgPackageManager : protected pkgCache::Namespace
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index b1ed0129d..572685ba5 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -82,9 +82,9 @@ pkgCache::Header::Header()
MaxDescFileSize = 0;
FileList = 0;
- StringList = 0;
VerSysName = 0;
Architecture = 0;
+ Architectures = 0;
HashTableSize = _config->FindI("APT::Cache-HashTableSize", 10 * 1048);
memset(Pools,0,sizeof(Pools));
@@ -140,7 +140,6 @@ bool pkgCache::ReMap(bool const &Errorchecks)
DescP = (Description *)Map.Data();
ProvideP = (Provides *)Map.Data();
DepP = (Dependency *)Map.Data();
- StringItemP = (StringItem *)Map.Data();
StrP = (char *)Map.Data();
if (Errorchecks == false)
@@ -215,10 +214,7 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
Package *Pkg = PkgP + HeaderP->PkgHashTable()[Hash(Name)];
for (; Pkg != PkgP; Pkg = PkgP + Pkg->Next)
{
- if (unlikely(Pkg->Name == 0))
- continue;
-
- int const cmp = strcasecmp(Name.c_str(), StrP + Pkg->Name);
+ int const cmp = strcmp(Name.c_str(), StrP + (GrpP + Pkg->Group)->Name);
if (cmp == 0)
return PkgIterator(*this, Pkg);
else if (cmp < 0)
@@ -279,10 +275,7 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) {
// Look at the hash bucket for the group
Group *Grp = GrpP + HeaderP->GrpHashTable()[sHash(Name)];
for (; Grp != GrpP; Grp = GrpP + Grp->Next) {
- if (unlikely(Grp->Name == 0))
- continue;
-
- int const cmp = strcasecmp(Name.c_str(), StrP + Grp->Name);
+ int const cmp = strcmp(Name.c_str(), StrP + Grp->Name);
if (cmp == 0)
return GrpIterator(*this, Grp);
else if (cmp < 0)
@@ -359,19 +352,15 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const {
last one we check, so we do it now. */
if (Arch == "native" || Arch == myArch || Arch == "all") {
pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage;
- if (strcasecmp(myArch, Owner->StrP + Pkg->Arch) == 0)
+ if (strcmp(myArch, Owner->StrP + Pkg->Arch) == 0)
return PkgIterator(*Owner, Pkg);
Arch = myArch;
}
- /* Iterate over the list to find the matching arch
- unfortunately this list includes "package noise"
- (= different packages with same calculated hash),
- so we need to check the name also */
+ // Iterate over the list to find the matching arch
for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP;
Pkg = Owner->PkgP + Pkg->Next) {
- if (S->Name == Pkg->Name &&
- stringcasecmp(Arch, Owner->StrP + Pkg->Arch) == 0)
+ if (stringcmp(Arch, Owner->StrP + Pkg->Arch) == 0)
return PkgIterator(*Owner, Pkg);
if ((Owner->PkgP + S->LastPackage) == Pkg)
break;
@@ -1037,7 +1026,7 @@ bool pkgCache::PrvIterator::IsMultiArchImplicit() const
{
pkgCache::PkgIterator const Owner = OwnerPkg();
pkgCache::PkgIterator const Parent = ParentPkg();
- if (strcmp(Owner.Arch(), Parent.Arch()) != 0 || Owner->Name == Parent->Name)
+ if (strcmp(Owner.Arch(), Parent.Arch()) != 0 || Owner.Group()->Name == Parent.Group()->Name)
return true;
return false;
}
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index 0ce2a2878..6a89eabd7 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -109,7 +109,6 @@ class pkgCache /*{{{*/
struct Description;
struct Provides;
struct Dependency;
- struct StringItem;
struct VerFile;
struct DescFile;
@@ -186,7 +185,6 @@ class pkgCache /*{{{*/
Description *DescP;
Provides *ProvideP;
Dependency *DepP;
- StringItem *StringItemP;
char *StrP;
virtual bool ReMap(bool const &Errorchecks = true);
@@ -290,12 +288,6 @@ struct pkgCache::Header
The PackageFile structures are singly linked lists that represent
all package files that have been merged into the cache. */
map_pointer_t FileList;
- /** \brief index of the first StringItem structure
-
- The cache contains a list of all the unique strings (StringItems).
- The parser reads this list into memory so it can match strings
- against it.*/
- map_pointer_t StringList;
/** \brief String representing the version system used */
map_pointer_t VerSysName;
/** \brief native architecture the cache was built against */
@@ -376,8 +368,11 @@ struct pkgCache::Group
*/
struct pkgCache::Package
{
- /** \brief Name of the package */
- map_stringitem_t Name;
+ /** \brief Name of the package
+ * Note that the access method Name() will remain. It is just this data member
+ * deprecated as this information is already stored and available via the
+ * associated Group – so it is wasting precious binary cache space */
+ APT_DEPRECATED map_stringitem_t Name;
/** \brief Architecture of the package */
map_stringitem_t Arch;
/** \brief Base of a singly linked list of versions
@@ -435,7 +430,7 @@ struct pkgCache::Package
struct pkgCache::PackageFile
{
/** \brief physical disk file that this PackageFile represents */
- map_pointer_t FileName; // StringItem
+ map_stringitem_t FileName;
/** \brief the release information
Please see the files document for a description of what the
@@ -515,6 +510,12 @@ struct pkgCache::Version
map_stringitem_t VerStr;
/** \brief section this version is filled in */
map_stringitem_t Section;
+ /** \brief source package name this version comes from
+ Always contains the name, even if it is the same as the binary name */
+ map_stringitem_t SourcePkgName;
+ /** \brief source version this version comes from
+ Always contains the version string, even if it is the same as the binary version */
+ map_stringitem_t SourceVerStr;
/** \brief Multi-Arch capabilities of a package version */
enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
@@ -603,7 +604,7 @@ struct pkgCache::Description
struct pkgCache::Dependency
{
/** \brief string of the version the dependency is applied against */
- map_stringitem_t Version; // StringItem
+ map_stringitem_t Version;
/** \brief index of the package this depends applies to
The generator will - if the package does not already exist -
@@ -653,24 +654,6 @@ struct pkgCache::Provides
map_pointer_t NextPkgProv; // Provides
};
/*}}}*/
-// StringItem structure /*{{{*/
-/** \brief used for generating single instances of strings
-
- Some things like Section Name are are useful to have as unique tags.
- It is part of a linked list based at pkgCache::Header::StringList
-
- All strings are simply inlined any place in the file that is natural
- for the writer. The client should make no assumptions about the positioning
- of strings. All StringItems should be null-terminated. */
-struct pkgCache::StringItem
-{
- /** \brief string this refers to */
- map_stringitem_t String;
- /** \brief Next link in the chain */
- map_stringitem_t NextItem;
-};
- /*}}}*/
-
inline char const * pkgCache::NativeArch()
{ return StrP + HeaderP->Architecture; }
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index a4d5d8783..6bb246e9f 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -57,8 +57,7 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
FoundFileDeps(0)
{
CurrentFile = 0;
- memset(UniqHash,0,sizeof(UniqHash));
-
+
if (_error->PendingError() == true)
return;
@@ -82,9 +81,7 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
if (unlikely(idxVerSysName == 0))
return;
Cache.HeaderP->VerSysName = idxVerSysName;
- // this pointer is set in ReMap, but we need it now for WriteUniqString
- Cache.StringItemP = (pkgCache::StringItem *)Map.Data();
- map_stringitem_t const idxArchitecture = WriteUniqString(_config->Find("APT::Architecture"));
+ map_stringitem_t const idxArchitecture = StoreString(MIXED, _config->Find("APT::Architecture"));
if (unlikely(idxArchitecture == 0))
return;
Cache.HeaderP->Architecture = idxArchitecture;
@@ -149,10 +146,6 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
CurrentFile += (pkgCache::PackageFile const * const) newMap - (pkgCache::PackageFile const * const) oldMap;
- for (size_t i = 0; i < _count(UniqHash); ++i)
- if (UniqHash[i] != 0)
- UniqHash[i] += (pkgCache::StringItem const * const) newMap - (pkgCache::StringItem const * const) oldMap;
-
for (std::vector<pkgCache::GrpIterator*>::const_iterator i = Dynamic<pkgCache::GrpIterator>::toReMap.begin();
i != Dynamic<pkgCache::GrpIterator>::toReMap.end(); ++i)
(*i)->ReMap(oldMap, newMap);
@@ -369,7 +362,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
/* We know the list is sorted so we use that fact in the search.
Insertion of new versions is done with correct sorting */
int Res = 1;
- for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++)
+ for (; Ver.end() == false; LastVer = &Ver->NextVer, ++Ver)
{
Res = Cache.VS->CmpVersion(Version,Ver.VerStr());
// Version is higher as current version - insert here
@@ -616,7 +609,7 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name)
return false;
Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group);
- map_pointer_t const idxName = WriteStringInMap(Name);
+ map_stringitem_t const idxName = StoreString(PKGNAME, Name);
if (unlikely(idxName == 0))
return false;
Grp->Name = idxName;
@@ -660,7 +653,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
// Insert it into the hash table
map_id_t const Hash = Cache.Hash(Name);
map_pointer_t *insertAt = &Cache.HeaderP->PkgHashTable()[Hash];
- while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.PkgP + *insertAt)->Name) > 0)
+ while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0)
insertAt = &(Cache.PkgP + *insertAt)->Next;
Pkg->Next = *insertAt;
*insertAt = Package;
@@ -675,10 +668,17 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
Grp->LastPackage = Package;
// Set the name, arch and the ID
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
Pkg->Name = Grp->Name;
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
Pkg->Group = Grp.Index();
// all is mapped to the native architecture
- map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : WriteUniqString(Arch.c_str());
+ map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : StoreString(MIXED, Arch);
if (unlikely(idxArch == 0))
return false;
Pkg->Arch = idxArch;
@@ -836,7 +836,7 @@ map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
}
}
// haven't found the version string, so create
- map_stringitem_t const idxVerStr = WriteStringInMap(VerStr);
+ map_stringitem_t const idxVerStr = StoreString(VERSION, VerStr);
if (unlikely(idxVerStr == 0))
return 0;
Ver->VerStr = idxVerStr;
@@ -893,7 +893,7 @@ map_pointer_t pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc,
// Fill it in
Desc = pkgCache::DescIterator(Cache,Cache.DescP + Description);
Desc->ID = Cache.HeaderP->DescriptionCount++;
- map_stringitem_t const idxlanguage_code = WriteUniqString(Lang);
+ map_stringitem_t const idxlanguage_code = StoreString(MIXED, Lang);
if (unlikely(idxlanguage_code == 0))
return 0;
Desc->language_code = idxlanguage_code;
@@ -933,7 +933,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
if (index == 0)
{
void const * const oldMap = Map.Data();
- index = WriteStringInMap(Version);
+ index = StoreString(VERSION, Version);
if (unlikely(index == 0))
return false;
if (OldDepLast != 0 && oldMap != Map.Data())
@@ -1095,7 +1095,7 @@ bool pkgCacheGenerator::SelectFile(const string &File,const string &Site,
// Fill it in
map_stringitem_t const idxFileName = WriteStringInMap(File);
- map_stringitem_t const idxSite = WriteUniqString(Site);
+ map_stringitem_t const idxSite = StoreString(MIXED, Site);
if (unlikely(idxFileName == 0 || idxSite == 0))
return false;
CurrentFile->FileName = idxFileName;
@@ -1103,7 +1103,7 @@ bool pkgCacheGenerator::SelectFile(const string &File,const string &Site,
CurrentFile->NextFile = Cache.HeaderP->FileList;
CurrentFile->Flags = Flags;
CurrentFile->ID = Cache.HeaderP->PackageFileCount;
- map_stringitem_t const idxIndexType = WriteUniqString(Index.GetType()->Label);
+ map_stringitem_t const idxIndexType = StoreString(MIXED, Index.GetType()->Label);
if (unlikely(idxIndexType == 0))
return false;
CurrentFile->IndexType = idxIndexType;
@@ -1120,57 +1120,27 @@ bool pkgCacheGenerator::SelectFile(const string &File,const string &Site,
// ---------------------------------------------------------------------
/* This is used to create handles to strings. Given the same text it
always returns the same number */
-map_stringitem_t pkgCacheGenerator::WriteUniqString(const char *S,
+map_stringitem_t pkgCacheGenerator::StoreString(enum StringType const type, const char *S,
unsigned int Size)
{
- /* We use a very small transient hash table here, this speeds up generation
- by a fair amount on slower machines */
- pkgCache::StringItem *&Bucket = UniqHash[(S[0]*5 + S[1]) % _count(UniqHash)];
- if (Bucket != 0 &&
- stringcmp(S,S+Size,Cache.StrP + Bucket->String) == 0)
- return Bucket->String;
-
- // Search for an insertion point
- pkgCache::StringItem *I = Cache.StringItemP + Cache.HeaderP->StringList;
- int Res = 1;
- map_stringitem_t *Last = &Cache.HeaderP->StringList;
- for (; I != Cache.StringItemP; Last = &I->NextItem,
- I = Cache.StringItemP + I->NextItem)
- {
- Res = stringcmp(S,S+Size,Cache.StrP + I->String);
- if (Res >= 0)
- break;
- }
-
- // Match
- if (Res == 0)
- {
- Bucket = I;
- return I->String;
+ std::string const key(S, Size);
+
+ std::map<std::string,map_stringitem_t> * strings;
+ switch(type) {
+ case MIXED: strings = &strMixed; break;
+ case PKGNAME: strings = &strPkgNames; break;
+ case VERSION: strings = &strVersions; break;
+ case SECTION: strings = &strSections; break;
+ default: _error->Fatal("Unknown enum type used for string storage of '%s'", key.c_str()); return 0;
}
-
- // Get a structure
- void const * const oldMap = Map.Data();
- map_pointer_t const Item = AllocateInMap(sizeof(pkgCache::StringItem));
- if (Item == 0)
- return 0;
- map_stringitem_t const idxString = WriteStringInMap(S,Size);
- if (unlikely(idxString == 0))
- return 0;
- if (oldMap != Map.Data()) {
- Last += (map_pointer_t const * const) Map.Data() - (map_pointer_t const * const) oldMap;
- I += (pkgCache::StringItem const * const) Map.Data() - (pkgCache::StringItem const * const) oldMap;
- }
- *Last = Item;
+ std::map<std::string,map_stringitem_t>::const_iterator const item = strings->find(key);
+ if (item != strings->end())
+ return item->second;
- // Fill in the structure
- pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
- ItemP->NextItem = I - Cache.StringItemP;
- ItemP->String = idxString;
-
- Bucket = ItemP;
- return ItemP->String;
+ map_stringitem_t const idxString = WriteStringInMap(S,Size);
+ strings->insert(std::make_pair(key, idxString));
+ return idxString;
}
/*}}}*/
// CheckValidity - Check that a cache is up-to-date /*{{{*/
diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h
index 42da7b12d..e1d22b88f 100644
--- a/apt-pkg/pkgcachegen.h
+++ b/apt-pkg/pkgcachegen.h
@@ -27,6 +27,7 @@
#include <vector>
#include <string>
+#include <map>
class FileFd;
class pkgSourceList;
@@ -36,13 +37,16 @@ class pkgIndexFile;
class pkgCacheGenerator /*{{{*/
{
private:
-
- pkgCache::StringItem *UniqHash[26];
APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String);
APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len);
APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size);
+ std::map<std::string,map_stringitem_t> strMixed;
+ std::map<std::string,map_stringitem_t> strSections;
+ std::map<std::string,map_stringitem_t> strPkgNames;
+ std::map<std::string,map_stringitem_t> strVersions;
+
public:
class ListParser;
@@ -91,8 +95,9 @@ class pkgCacheGenerator /*{{{*/
public:
- map_stringitem_t WriteUniqString(const char *S,unsigned int const Size);
- inline map_stringitem_t WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());};
+ enum StringType { MIXED, PKGNAME, VERSION, SECTION };
+ map_stringitem_t StoreString(enum StringType const type, const char * S, unsigned int const Size);
+ inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());};
void DropProgress() {Progress = 0;};
bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index,
@@ -145,8 +150,9 @@ class pkgCacheGenerator::ListParser
protected:
- inline map_stringitem_t WriteUniqString(std::string S) {return Owner->WriteUniqString(S);};
- inline map_stringitem_t WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
+ inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);};
+ inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);};
+
inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
@@ -187,7 +193,7 @@ class pkgCacheGenerator::ListParser
virtual bool CollectFileProvides(pkgCache &/*Cache*/,
pkgCache::VerIterator &/*Ver*/) {return true;};
- ListParser() : FoundFileDeps(false) {};
+ ListParser() : Owner(NULL), OldDepLast(NULL), FoundFileDeps(false) {};
virtual ~ListParser() {};
};
/*}}}*/
diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index e37899ec6..7170e8b5b 100644
--- a/apt-pkg/sourcelist.cc
+++ b/apt-pkg/sourcelist.cc
@@ -119,7 +119,7 @@ bool pkgSourceList::Type::ParseStanza(vector<metaIndex *> &List,
std::vector<std::string> list_section = StringSplit(Section, " ");
for (std::vector<std::string>::const_iterator U = list_uris.begin();
- U != list_uris.end(); U++)
+ U != list_uris.end(); ++U)
{
std::string URI = (*U);
if (!FixupURI(URI))
@@ -129,10 +129,10 @@ bool pkgSourceList::Type::ParseStanza(vector<metaIndex *> &List,
}
for (std::vector<std::string>::const_iterator I = list_dist.begin();
- I != list_dist.end(); I++)
+ I != list_dist.end(); ++I)
{
for (std::vector<std::string>::const_iterator J = list_section.begin();
- J != list_section.end(); J++)
+ J != list_section.end(); ++J)
{
if (CreateItem(List, URI, (*I), (*J), Options) == false)
{
@@ -408,7 +408,7 @@ int pkgSourceList::ParseFileDeb822(string File)
string const types = Tags.FindS("Types");
std::vector<std::string> list_types = StringSplit(types, " ");
for (std::vector<std::string>::const_iterator I = list_types.begin();
- I != list_types.end(); I++)
+ I != list_types.end(); ++I)
{
Type *Parse = Type::GetType((*I).c_str());
if (Parse == 0)
diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h
index 261dd8161..35b786e1a 100644
--- a/apt-pkg/sourcelist.h
+++ b/apt-pkg/sourcelist.h
@@ -96,13 +96,9 @@ class pkgSourceList : public pkgSource
public:
- std::vector<metaIndex *> SrcList;
-
int ParseFileDeb822(std::string File);
bool ParseFileOldStyle(std::string File);
- public:
-
bool ReadMainList();
bool Read(std::string File);
diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h
index db43bfbf9..39ec94d86 100644
--- a/apt-pkg/tagfile.h
+++ b/apt-pkg/tagfile.h
@@ -43,7 +43,7 @@ class pkgTagSection
unsigned int StartValue;
unsigned int NextInBucket;
- TagData(unsigned int const StartTag) : StartTag(StartTag), NextInBucket(0) {}
+ TagData(unsigned int const StartTag) : StartTag(StartTag), EndTag(0), StartValue(0), NextInBucket(0) {}
};
std::vector<TagData> Tags;
unsigned int LookupTable[0x100];
@@ -94,7 +94,7 @@ class pkgTagSection
/** \brief amount of Tags in the current section
*
* Note: if a Tag is mentioned repeatly it will be counted multiple
- * times, but only the last occurance is available via Find methods.
+ * times, but only the last occurrence is available via Find methods.
*/
unsigned int Count() const;
bool Exists(const char* const Tag) const;
diff --git a/apt-pkg/upgrade.cc b/apt-pkg/upgrade.cc
index 29b11937b..ca670bdf5 100644
--- a/apt-pkg/upgrade.cc
+++ b/apt-pkg/upgrade.cc
@@ -24,13 +24,14 @@
The problem resolver is used to resolve the problems.
*/
-bool pkgDistUpgrade(pkgDepCache &Cache)
+bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress)
{
std::string const solver = _config->Find("APT::Solver", "internal");
- if (solver != "internal") {
- OpTextProgress Prog(*_config);
- return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, &Prog);
- }
+ if (solver != "internal")
+ return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, Progress);
+
+ if (Progress != NULL)
+ Progress->OverallProgress(0, 100, 1, _("Calculating upgrade"));
pkgDepCache::ActionGroup group(Cache);
@@ -41,12 +42,18 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
if (I->CurrentVer != 0)
Cache.MarkInstall(I, false, 0, false);
+ if (Progress != NULL)
+ Progress->Progress(10);
+
/* Auto upgrade all installed packages, this provides the basis
for the installation */
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (I->CurrentVer != 0)
Cache.MarkInstall(I, true, 0, false);
+ if (Progress != NULL)
+ Progress->Progress(50);
+
/* Now, install each essential package which is not installed
(and not provided by another package in the same name group) */
std::string essential = _config->Find("pkgCacheGen::Essential", "all");
@@ -77,15 +84,24 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
Cache.MarkInstall(I, true, 0, false);
-
+
+ if (Progress != NULL)
+ Progress->Progress(55);
+
/* We do it again over all previously installed packages to force
conflict resolution on them all. */
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (I->CurrentVer != 0)
Cache.MarkInstall(I, false, 0, false);
+ if (Progress != NULL)
+ Progress->Progress(65);
+
pkgProblemResolver Fix(&Cache);
+ if (Progress != NULL)
+ Progress->Progress(95);
+
// Hold back held packages.
if (_config->FindB("APT::Ignore-Hold",false) == false)
{
@@ -98,18 +114,22 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
}
}
}
-
- return Fix.Resolve();
+
+ bool const success = Fix.Resolve(false, Progress);
+ if (Progress != NULL)
+ Progress->Done();
+ return success;
}
/*}}}*/
// AllUpgradeNoNewPackages - Upgrade but no removals or new pkgs /*{{{*/
-static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache)
+static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache, OpProgress * const Progress)
{
std::string const solver = _config->Find("APT::Solver", "internal");
- if (solver != "internal") {
- OpTextProgress Prog(*_config);
- return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog);
- }
+ if (solver != "internal")
+ return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress);
+
+ if (Progress != NULL)
+ Progress->OverallProgress(0, 100, 1, _("Calculating upgrade"));
pkgDepCache::ActionGroup group(Cache);
@@ -131,8 +151,15 @@ static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache)
if (I->CurrentVer != 0 && Cache[I].InstallVer != 0)
Cache.MarkInstall(I, false, 0, false);
}
-
- return Fix.ResolveByKeep();
+
+ if (Progress != NULL)
+ Progress->Progress(50);
+
+ // resolve remaining issues via keep
+ bool const success = Fix.ResolveByKeep(Progress);
+ if (Progress != NULL)
+ Progress->Done();
+ return success;
}
/*}}}*/
// AllUpgradeWithNewInstalls - Upgrade + install new packages as needed /*{{{*/
@@ -141,13 +168,14 @@ static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache)
* Upgrade as much as possible without deleting anything (useful for
* stable systems)
*/
-static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache)
+static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache, OpProgress * const Progress)
{
std::string const solver = _config->Find("APT::Solver", "internal");
- if (solver != "internal") {
- OpTextProgress Prog(*_config);
- return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog);
- }
+ if (solver != "internal")
+ return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress);
+
+ if (Progress != NULL)
+ Progress->OverallProgress(0, 100, 1, _("Calculating upgrade"));
pkgDepCache::ActionGroup group(Cache);
@@ -170,18 +198,30 @@ static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache)
}
}
+ if (Progress != NULL)
+ Progress->Progress(10);
+
// then let auto-install loose
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (Cache[I].Install())
Cache.MarkInstall(I, true, 0, false);
+ if (Progress != NULL)
+ Progress->Progress(50);
+
// ... but it may remove stuff, we we need to clean up afterwards again
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (Cache[I].Delete() == true)
Cache.MarkKeep(I, false, false);
+ if (Progress != NULL)
+ Progress->Progress(60);
+
// resolve remaining issues via keep
- return Fix.ResolveByKeep();
+ bool const success = Fix.ResolveByKeep(Progress);
+ if (Progress != NULL)
+ Progress->Done();
+ return success;
}
/*}}}*/
// AllUpgrade - Upgrade as many packages as possible /*{{{*/
@@ -189,9 +229,9 @@ static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache)
/* Right now the system must be consistent before this can be called.
It also will not change packages marked for install, it only tries
to install packages not marked for install */
-bool pkgAllUpgrade(pkgDepCache &Cache)
+bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress)
{
- return pkgAllUpgradeNoNewPackages(Cache);
+ return pkgAllUpgradeNoNewPackages(Cache, Progress);
}
/*}}}*/
// MinimizeUpgrade - Minimizes the set of packages to be upgraded /*{{{*/
@@ -239,24 +279,25 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache)
return true;
}
/*}}}*/
-// APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/
-bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode)
+// APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/
+bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode, OpProgress * const Progress)
{
- if (mode == 0)
- {
- return pkgDistUpgrade(Cache);
- }
+#if __GNUC__ >= 4
+ // the deprecated methods will become our privates, so that is fine
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ if (mode == ALLOW_EVERYTHING)
+ return pkgDistUpgrade(Cache, Progress);
else if ((mode & ~FORBID_REMOVE_PACKAGES) == 0)
- {
- return pkgAllUpgradeWithNewPackages(Cache);
- }
+ return pkgAllUpgradeWithNewPackages(Cache, Progress);
else if ((mode & ~(FORBID_REMOVE_PACKAGES|FORBID_INSTALL_NEW_PACKAGES)) == 0)
- {
- return pkgAllUpgradeNoNewPackages(Cache);
- }
+ return pkgAllUpgradeNoNewPackages(Cache, Progress);
else
_error->Error("pkgAllUpgrade called with unsupported mode %i", mode);
-
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic pop
+#endif
return false;
}
/*}}}*/
diff --git a/apt-pkg/upgrade.h b/apt-pkg/upgrade.h
index aa883df10..a3f693d86 100644
--- a/apt-pkg/upgrade.h
+++ b/apt-pkg/upgrade.h
@@ -10,23 +10,27 @@
#ifndef PKGLIB_UPGRADE_H
#define PKGLIB_UPGRADE_H
+#include <stddef.h>
+#include <apt-pkg/macros.h>
+
class pkgDepCache;
+class OpProgress;
namespace APT {
namespace Upgrade {
// FIXME: make this "enum class UpgradeMode {" once we enable c++11
enum UpgradeMode {
+ ALLOW_EVERYTHING = 0,
FORBID_REMOVE_PACKAGES = 1,
FORBID_INSTALL_NEW_PACKAGES = 2
};
- bool Upgrade(pkgDepCache &Cache, int UpgradeMode);
+ bool Upgrade(pkgDepCache &Cache, int UpgradeMode, OpProgress * const Progress = NULL);
}
}
// please use APT::Upgrade::Upgrade() instead
-bool pkgDistUpgrade(pkgDepCache &Cache);
-bool pkgAllUpgrade(pkgDepCache &Cache);
-bool pkgMinimizeUpgrade(pkgDepCache &Cache);
-
+APT_DEPRECATED bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL);
+APT_DEPRECATED bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL);
+bool pkgMinimizeUpgrade(pkgDepCache &Cache);
#endif