diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-04-27 22:25:33 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-05-09 13:06:27 +0200 |
commit | fa3b260f438b20c5abb7e86f06d794e15771b4b2 (patch) | |
tree | 614c77b0eef440ae2a8b7460da1ef66fc057c777 | |
parent | a311fb96b84757ef8628e6a754232614a53b7891 (diff) |
promote ExpectedHashes to a pkgAcquire::Item member
Beside being another big API break with hopefully zero fallout in
reality it avoids having the same member and helper code in each and
every subclass.
-rw-r--r-- | apt-pkg/acquire-item.cc | 49 | ||||
-rw-r--r-- | apt-pkg/acquire-item.h | 93 |
2 files changed, 40 insertions, 102 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 1156d6f33..ce19e5486 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -64,12 +64,10 @@ static void printHashSumComparision(std::string const &URI, HashStringList const /*}}}*/ // Acquire::Item::Item - Constructor /*{{{*/ -// --------------------------------------------------------------------- -/* */ -pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), FileSize(0), - PartialSize(0), Mode(0), ID(0), Complete(false), - Local(false), QueueCounter(0), - ExpectedAdditionalItems(0) +pkgAcquire::Item::Item(pkgAcquire *Owner, HashStringList const &ExpectedHashes) : + Owner(Owner), FileSize(0), PartialSize(0), Mode(0), ID(0), Complete(false), + Local(false), QueueCounter(0), ExpectedAdditionalItems(0), + ExpectedHashes(ExpectedHashes) { Owner->Add(this); Status = StatIdle; @@ -243,7 +241,7 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode) pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire *Owner, string const &URI, string const &URIDesc, string const &ShortDesc, HashStringList const &ExpectedHashes) - : Item(Owner), ExpectedHashes(ExpectedHashes) + : Item(Owner, ExpectedHashes) { /* XXX: Beware: Currently this class does nothing (of value) anymore ! */ Debug = _config->FindB("Debug::pkgAcquire::SubIndex",false); @@ -356,10 +354,10 @@ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile) /*{{{*/ * the original packages file */ pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner, - struct IndexTarget const * const Target, + IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser) - : Item(Owner), ExpectedHashes(ExpectedHashes), Target(Target), + : Item(Owner, ExpectedHashes), Target(Target), MetaIndexParser(MetaIndexParser) { @@ -622,7 +620,7 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, HashStringList const &ExpectedHashes, string ServerSha1, vector<DiffInfo> diffs) - : Item(Owner), RealURI(URI), ExpectedHashes(ExpectedHashes), + : Item(Owner, ExpectedHashes), RealURI(URI), available_patches(diffs), ServerSha1(ServerSha1) { @@ -653,8 +651,7 @@ void pkgAcqIndexDiffs::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/) if(Debug) std::clog << "pkgAcqIndexDiffs failed: " << Desc.URI << " with " << Message << std::endl << "Falling back to normal index file acquire" << std::endl; - new pkgAcqIndex(Owner, RealURI, Description,Desc.ShortDesc, - ExpectedHashes); + new pkgAcqIndex(Owner, RealURI, Description,Desc.ShortDesc, HashSums()); Finish(); } /*}}}*/ @@ -668,7 +665,7 @@ void pkgAcqIndexDiffs::Finish(bool allDone) DestFile = _config->FindDir("Dir::State::lists"); DestFile += URItoFileName(RealURI); - if(ExpectedHashes.usable() && !ExpectedHashes.VerifyFile(DestFile)) + if(HashSums().usable() && !HashSums().VerifyFile(DestFile)) { RenameOnError(HashSumMismatch); Dequeue(); @@ -795,7 +792,7 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size, HashStringLi // see if there is more to download if(available_patches.empty() == false) { new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc, - ExpectedHashes, ServerSha1, available_patches); + HashSums(), ServerSha1, available_patches); return Finish(); } else return Finish(true); @@ -808,7 +805,7 @@ pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire *Owner, string const &ShortDesc, HashStringList const &ExpectedHashes, DiffInfo const &patch, std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches) - : Item(Owner), RealURI(URI), ExpectedHashes(ExpectedHashes), + : Item(Owner, ExpectedHashes), RealURI(URI), patch(patch),allPatches(allPatches), State(StateFetchDiff) { @@ -934,7 +931,7 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, string URI,string URIDesc,string ShortDesc, HashStringList const &ExpectedHashes, string comprExt) - : Item(Owner), RealURI(URI), ExpectedHashes(ExpectedHashes), Target(0), + : Item(Owner, ExpectedHashes), RealURI(URI), Target(0), MetaIndexParser(0) { if(comprExt.empty() == true) @@ -952,9 +949,9 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, Init(URI, URIDesc, ShortDesc); } -pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target, +pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser) - : Item(Owner), RealURI(Target->URI), ExpectedHashes(ExpectedHashes) + : Item(Owner, ExpectedHashes), RealURI(Target->URI) { // autoselect the compression method std::vector<std::string> types = APT::Configuration::getCompressionTypes(); @@ -1209,7 +1206,7 @@ pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, : pkgAcqIndex(Owner, URI, URIDesc, ShortDesc, HashStringList(), "") { } -pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target, +pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser) : pkgAcqIndex(Owner, Target, ExpectedHashes, MetaIndexParser) { @@ -1265,7 +1262,7 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner, /*{{{*/ string MetaIndexShortDesc, const vector<IndexTarget*>* IndexTargets, indexRecords* MetaIndexParser) : - Item(Owner), RealURI(URI), MetaIndexURI(MetaIndexURI), + Item(Owner, HashStringList()), RealURI(URI), MetaIndexURI(MetaIndexURI), MetaIndexURIDesc(MetaIndexURIDesc), MetaIndexShortDesc(MetaIndexShortDesc), MetaIndexParser(MetaIndexParser), IndexTargets(IndexTargets) { @@ -1410,9 +1407,9 @@ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/ pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire *Owner, /*{{{*/ string URI,string URIDesc,string ShortDesc, string SigFile, - const vector<struct IndexTarget*>* IndexTargets, + const vector<IndexTarget*>* IndexTargets, indexRecords* MetaIndexParser) : - Item(Owner), RealURI(URI), SigFile(SigFile), IndexTargets(IndexTargets), + Item(Owner, HashStringList()), RealURI(URI), SigFile(SigFile), IndexTargets(IndexTargets), MetaIndexParser(MetaIndexParser), AuthPass(false), IMSHit(false) { DestFile = _config->FindDir("Dir::State::lists") + "partial/"; @@ -1619,7 +1616,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ // at this point the real Items are loaded in the fetcher ExpectedAdditionalItems = 0; - for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin(); + for (vector <IndexTarget*>::const_iterator Target = IndexTargets->begin(); Target != IndexTargets->end(); ++Target) { @@ -1841,7 +1838,7 @@ pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire *Owner, /*{{{*/ string const &URI, string const &URIDesc, string const &ShortDesc, string const &MetaIndexURI, string const &MetaIndexURIDesc, string const &MetaIndexShortDesc, string const &MetaSigURI, string const &MetaSigURIDesc, string const &MetaSigShortDesc, - const vector<struct IndexTarget*>* IndexTargets, + const vector<IndexTarget*>* IndexTargets, indexRecords* MetaIndexParser) : pkgAcqMetaIndex(Owner, URI, URIDesc, ShortDesc, "", IndexTargets, MetaIndexParser), MetaIndexURI(MetaIndexURI), MetaIndexURIDesc(MetaIndexURIDesc), MetaIndexShortDesc(MetaIndexShortDesc), @@ -1926,7 +1923,7 @@ void pkgAcqMetaClearSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /* pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, pkgRecords *Recs,pkgCache::VerIterator const &Version, string &StoreFilename) : - Item(Owner), Version(Version), Sources(Sources), Recs(Recs), + Item(Owner, HashStringList()), Version(Version), Sources(Sources), Recs(Recs), StoreFilename(StoreFilename), Vf(Version.FileList()), Trusted(false) { @@ -2232,7 +2229,7 @@ pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI, HashStringList const &Hashe unsigned long long Size,string Dsc,string ShortDesc, const string &DestDir, const string &DestFilename, bool IsIndexFile) : - Item(Owner), ExpectedHashes(Hashes), IsIndexFile(IsIndexFile) + Item(Owner, Hashes), IsIndexFile(IsIndexFile) { Retries = _config->FindI("Acquire::Retries",0); diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 2c39be46c..d054b96af 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -46,6 +46,7 @@ class indexRecords; class pkgRecords; class pkgSourceList; +class IndexTarget; /** \brief Represents the process by which a pkgAcquire object should {{{ * retrieve a file or a collection of files. @@ -259,7 +260,7 @@ class pkgAcquire::Item : public WeakPointable * \return the HashSums of this object, if applicable; otherwise, an * empty list. */ - virtual HashStringList HashSums() const {return HashStringList();}; + HashStringList HashSums() const {return ExpectedHashes;}; std::string HashSum() const {HashStringList const hashes = HashSums(); HashString const * const hs = hashes.find(NULL); return hs != NULL ? hs->toStr() : ""; }; /** \return the acquire process with which this item is associated. */ @@ -285,12 +286,10 @@ class pkgAcquire::Item : public WeakPointable * process, but does not place it into any fetch queues (you must * manually invoke QueueURI() to do so). * - * Initializes all fields of the item other than Owner to 0, - * false, or the empty string. - * * \param Owner The new owner of this item. + * \param ExpectedHashes of the file represented by this item */ - Item(pkgAcquire *Owner); + Item(pkgAcquire *Owner, HashStringList const &ExpectedHashes); /** \brief Remove this item from its owner's queue by invoking * pkgAcquire::Remove. @@ -310,6 +309,12 @@ class pkgAcquire::Item : public WeakPointable * \param state respresenting the error we encountered */ bool RenameOnError(RenameOnErrorState const state); + + /** \brief The HashSums of the item is supposed to have than done */ + HashStringList ExpectedHashes; + + /** \brief The item that is currently being downloaded. */ + pkgAcquire::ItemDesc Desc; }; /*}}}*/ /** \brief Information about an index patch (aka diff). */ /*{{{*/ @@ -336,13 +341,6 @@ class pkgAcqSubIndex : public pkgAcquire::Item /** \brief If \b true, debugging information will be written to std::clog. */ bool Debug; - /** \brief The item that is currently being downloaded. */ - pkgAcquire::ItemDesc Desc; - - /** \brief The Hashes that this file should have after download - */ - HashStringList ExpectedHashes; - public: // Specialized action members virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); @@ -383,19 +381,11 @@ class pkgAcqDiffIndex : public pkgAcquire::Item /** \brief If \b true, debugging information will be written to std::clog. */ bool Debug; - /** \brief The item that is currently being downloaded. */ - pkgAcquire::ItemDesc Desc; - /** \brief The URI of the index file to recreate at our end (either * by downloading it or by applying partial patches). */ std::string RealURI; - /** \brief The Hashes that the real index file should have after - * all patches have been applied. - */ - HashStringList ExpectedHashes; - /** \brief The index file which will be patched to generate the new * file. */ @@ -470,21 +460,11 @@ class pkgAcqIndexMergeDiffs : public pkgAcquire::Item */ bool Debug; - /** \brief description of the item that is currently being - * downloaded. - */ - pkgAcquire::ItemDesc Desc; - /** \brief URI of the package index file that is being * reconstructed. */ std::string RealURI; - /** \brief The Hashes that the real index file should have after - * all patches have been applied. - */ - HashStringList ExpectedHashes; - /** \brief description of the file being downloaded. */ std::string Description; @@ -593,21 +573,11 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item */ bool Debug; - /** \brief A description of the item that is currently being - * downloaded. - */ - pkgAcquire::ItemDesc Desc; - /** \brief The URI of the package index file that is being * reconstructed. */ std::string RealURI; - /** \brief The HashSums of the package index file that is being - * reconstructed. - */ - HashStringList ExpectedHashes; - /** A description of the file being downloaded. */ std::string Description; @@ -712,19 +682,11 @@ class pkgAcqIndex : public pkgAcquire::Item // the downloaded file contains the expected tag bool Verify; - /** \brief The download request that is currently being - * processed. - */ - pkgAcquire::ItemDesc Desc; - /** \brief The object that is actually being fetched (minus any * compression-related extensions). */ std::string RealURI; - /** \brief The expected hashsum of the decompressed index file. */ - HashStringList ExpectedHashes; - /** \brief The compression-related file extensions that are being * added to the downloaded file one by one if first fails (e.g., "gz bz2"). */ @@ -743,7 +705,6 @@ class pkgAcqIndex : public pkgAcquire::Item pkgAcquire::MethodConfig *Cnf); virtual std::string Custom600Headers() const; virtual std::string DescURI() const {return Desc.URI;}; - virtual HashStringList HashSums() const {return ExpectedHashes; }; /** \brief Create a pkgAcqIndex. * @@ -767,7 +728,7 @@ class pkgAcqIndex : public pkgAcquire::Item pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc, HashStringList const &ExpectedHashes, std::string compressExt=""); - pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target, + pkgAcqIndex(pkgAcquire *Owner, IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser); void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc); }; @@ -799,7 +760,7 @@ class pkgAcqIndexTrans : public pkgAcqIndex */ pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc); - pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target, + pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser); }; /*}}}*/ @@ -868,9 +829,6 @@ class pkgAcqMetaSig : public pkgAcquire::Item /** \brief The last good signature file */ std::string LastGoodSig; - /** \brief The fetch request that is currently being processed. */ - pkgAcquire::ItemDesc Desc; - /** \brief The URI of the signature file. Unlike Desc.URI, this is * never modified; it is used to determine the file that is being * downloaded. @@ -898,7 +856,7 @@ class pkgAcqMetaSig : public pkgAcquire::Item * * \todo Why a list of pointers instead of a list of structs? */ - const std::vector<struct IndexTarget*>* IndexTargets; + const std::vector<IndexTarget*>* IndexTargets; public: @@ -912,7 +870,7 @@ class pkgAcqMetaSig : public pkgAcquire::Item /** \brief Create a new pkgAcqMetaSig. */ pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc, std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc, - const std::vector<struct IndexTarget*>* IndexTargets, + const std::vector<IndexTarget*>* IndexTargets, indexRecords* MetaIndexParser); virtual ~pkgAcqMetaSig(); }; @@ -930,9 +888,6 @@ class pkgAcqMetaSig : public pkgAcquire::Item class pkgAcqMetaIndex : public pkgAcquire::Item { protected: - /** \brief The fetch command that is currently being processed. */ - pkgAcquire::ItemDesc Desc; - /** \brief The URI that is actually being downloaded; never * modified by pkgAcqMetaIndex. */ @@ -946,7 +901,7 @@ class pkgAcqMetaIndex : public pkgAcquire::Item std::string SigFile; /** \brief The index files to download. */ - const std::vector<struct IndexTarget*>* IndexTargets; + const std::vector<IndexTarget*>* IndexTargets; /** \brief The parser for the meta-index file. */ indexRecords* MetaIndexParser; @@ -1009,7 +964,7 @@ class pkgAcqMetaIndex : public pkgAcquire::Item pkgAcqMetaIndex(pkgAcquire *Owner, std::string URI,std::string URIDesc, std::string ShortDesc, std::string SigFile, - const std::vector<struct IndexTarget*>* IndexTargets, + const std::vector<IndexTarget*>* IndexTargets, indexRecords* MetaIndexParser); }; /*}}}*/ @@ -1043,7 +998,7 @@ public: std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc, std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc, std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc, - const std::vector<struct IndexTarget*>* IndexTargets, + const std::vector<IndexTarget*>* IndexTargets, indexRecords* MetaIndexParser); virtual ~pkgAcqMetaClearSig(); }; @@ -1059,9 +1014,6 @@ class pkgAcqArchive : public pkgAcquire::Item /** \brief The package version being fetched. */ pkgCache::VerIterator Version; - /** \brief The fetch command that is currently being processed. */ - pkgAcquire::ItemDesc Desc; - /** \brief The list of sources from which to pick archives to * download this package from. */ @@ -1072,9 +1024,6 @@ class pkgAcqArchive : public pkgAcquire::Item */ pkgRecords *Recs; - /** \brief The hashsum of this package. */ - HashStringList ExpectedHashes; - /** \brief A location in which the actual filename of the package * should be stored. */ @@ -1106,7 +1055,6 @@ class pkgAcqArchive : public pkgAcquire::Item virtual std::string DescURI() const {return Desc.URI;}; virtual std::string ShortDesc() const {return Desc.ShortDesc;}; virtual void Finished(); - virtual HashStringList HashSums() const {return ExpectedHashes; }; virtual bool IsTrusted() const; /** \brief Create a new pkgAcqArchive. @@ -1140,12 +1088,6 @@ class pkgAcqArchive : public pkgAcquire::Item */ class pkgAcqFile : public pkgAcquire::Item { - /** \brief The currently active download process. */ - pkgAcquire::ItemDesc Desc; - - /** \brief The hashsum of the file to download, if it is known. */ - HashStringList ExpectedHashes; - /** \brief How many times to retry the download, set from * Acquire::Retries. */ @@ -1161,7 +1103,6 @@ class pkgAcqFile : public pkgAcquire::Item 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 HashStringList HashSums() const { return ExpectedHashes; }; virtual std::string Custom600Headers() const; /** \brief Create a new pkgAcqFile object. |