diff options
author | Michael Vogt <mvo@ubuntu.com> | 2014-07-18 23:21:46 +0200 |
---|---|---|
committer | Michael Vogt <mvo@ubuntu.com> | 2014-07-18 23:21:46 +0200 |
commit | 564720959e4ae47921b795fe6c5ce46e1e1bdc95 (patch) | |
tree | abaa12f1cee1cceadc11cd98a7b2352a1fce0af2 | |
parent | 9c3e15ab5f8b5864c43a08065a6bc8cf376fd138 (diff) |
WIP transaction based update
-rw-r--r-- | apt-pkg/acquire-item.cc | 118 | ||||
-rw-r--r-- | apt-pkg/acquire-item.h | 302 | ||||
-rw-r--r-- | apt-pkg/acquire.cc | 50 | ||||
-rw-r--r-- | apt-pkg/acquire.h | 4 |
4 files changed, 303 insertions, 171 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 221d2a267..bd11ba66c 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -66,7 +66,7 @@ static void printHashSumComparision(std::string const &URI, HashStringList const // Acquire::Item::Item - Constructor /*{{{*/ 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), + Local(false), QueueCounter(0), TransactionID(0), ExpectedAdditionalItems(0), ExpectedHashes(ExpectedHashes) { Owner->Add(this); @@ -353,11 +353,12 @@ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile) /*{{{*/ * patches. If anything goes wrong in that process, it will fall back to * the original packages file */ -pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner, +pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcqMetaIndex *MetaOwner, IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser) - : pkgAcqBaseIndex(Owner, Target, ExpectedHashes, MetaIndexParser) + : pkgAcqBaseIndex(MetaOwner, Target, ExpectedHashes, + MetaIndexParser) { Debug = _config->FindB("Debug::pkgAcquire::Diffs",false); @@ -455,7 +456,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/ std::clog << "Package file is up-to-date" << std::endl; // list cleanup needs to know that this file as well as the already // present index is ours, so we create an empty diff to save it for us - new pkgAcqIndexDiffs(Owner, Target, ExpectedHashes, MetaIndexParser, + new pkgAcqIndexDiffs(MetaOwner, Target, ExpectedHashes, MetaIndexParser, ServerSha1, available_patches); return true; } @@ -542,14 +543,14 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/ if (pdiff_merge == false) { - new pkgAcqIndexDiffs(Owner, Target, ExpectedHashes, MetaIndexParser, + new pkgAcqIndexDiffs(MetaOwner, Target, ExpectedHashes, MetaIndexParser, ServerSha1, available_patches); } else { std::vector<pkgAcqIndexMergeDiffs*> *diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size()); for(size_t i = 0; i < available_patches.size(); ++i) - (*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, Target, + (*diffs)[i] = new pkgAcqIndexMergeDiffs(MetaOwner, Target, ExpectedHashes, MetaIndexParser, available_patches[i], @@ -577,7 +578,7 @@ void pkgAcqDiffIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/ std::clog << "pkgAcqDiffIndex failed: " << Desc.URI << " with " << Message << std::endl << "Falling back to normal index file acquire" << std::endl; - new pkgAcqIndex(Owner, Target, ExpectedHashes, MetaIndexParser); + new pkgAcqIndex(MetaOwner, Target, ExpectedHashes, MetaIndexParser); Complete = false; Status = StatDone; @@ -619,13 +620,13 @@ void pkgAcqDiffIndex::Done(string Message,unsigned long long Size,HashStringList /* The package diff is added to the queue. one object is constructed * for each diff and the index */ -pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, +pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcqMetaIndex *MetaOwner, struct IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser, string ServerSha1, vector<DiffInfo> diffs) - : pkgAcqBaseIndex(Owner, Target, ExpectedHashes, MetaIndexParser), + : pkgAcqBaseIndex(MetaOwner, Target, ExpectedHashes, MetaIndexParser), available_patches(diffs), ServerSha1(ServerSha1) { @@ -657,7 +658,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, Target, ExpectedHashes, MetaIndexParser); + new pkgAcqIndex(MetaOwner, Target, ExpectedHashes, MetaIndexParser); Finish(); } /*}}}*/ @@ -797,7 +798,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, Target, + new pkgAcqIndexDiffs(MetaOwner, Target, ExpectedHashes, MetaIndexParser, ServerSha1, available_patches); return Finish(); @@ -807,13 +808,13 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size, HashStringLi } /*}}}*/ // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/ -pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire *Owner, +pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcqMetaIndex *MetaOwner, struct IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser, DiffInfo const &patch, std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches) - : pkgAcqBaseIndex(Owner, Target, ExpectedHashes, MetaIndexParser), + : pkgAcqBaseIndex(MetaOwner, Target, ExpectedHashes, MetaIndexParser), patch(patch), allPatches(allPatches), State(StateFetchDiff) { @@ -856,7 +857,7 @@ void pkgAcqIndexMergeDiffs::Failed(string Message,pkgAcquire::MethodConfig * /*C // first failure means we should fallback State = StateErrorDiff; std::clog << "Falling back to normal index file acquire" << std::endl; - new pkgAcqIndex(Owner, Target, ExpectedHashes, MetaIndexParser); + new pkgAcqIndex(MetaOwner, Target, ExpectedHashes, MetaIndexParser); } /*}}}*/ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStringList const &Hashes, /*{{{*/ @@ -954,6 +955,7 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, Init(URI, URIDesc, ShortDesc); } +#if 0 pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target, HashStringList const &ExpectedHash, indexRecords *MetaIndexParser) @@ -961,6 +963,27 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target, RealURI(Target->URI) { // autoselect the compression method + AutoSelectCompression(); + Init(Target->URI, Target->Description, Target->ShortDesc); +} +#endif + /*}}}*/ +pkgAcqIndex::pkgAcqIndex(pkgAcqMetaIndex *MetaOwner, + IndexTarget const *Target, + HashStringList const &ExpectedHash, + indexRecords *MetaIndexParser) + : pkgAcqBaseIndex(MetaOwner->GetOwner(), Target, ExpectedHash, + MetaIndexParser), RealURI(Target->URI) +{ + // autoselect the compression method + AutoSelectCompression(); + Init(Target->URI, Target->Description, Target->ShortDesc); + + TransactionID = (unsigned long)MetaOwner; +} + /*}}}*/ +void pkgAcqIndex::AutoSelectCompression() +{ std::vector<std::string> types = APT::Configuration::getCompressionTypes(); CompressionExtension = ""; if (ExpectedHashes.usable()) @@ -976,10 +999,7 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target, } if (CompressionExtension.empty() == false) CompressionExtension.erase(CompressionExtension.end()-1); - - Init(Target->URI, Target->Description, Target->ShortDesc); } - /*}}}*/ // AcqIndex::Init - defered Constructor /*{{{*/ void pkgAcqIndex::Init(string const &URI, string const &URIDesc, string const &ShortDesc) { Decompression = false; @@ -1092,6 +1112,9 @@ void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/ } Item::Failed(Message,Cnf); + + /// cancel the entire transaction + Owner->AbortTransaction(TransactionID); } /*}}}*/ // AcqIndex::Done - Finished a fetch /*{{{*/ @@ -1112,6 +1135,7 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,HashStringList con { RenameOnError(HashSumMismatch); printHashSumComparision(RealURI, ExpectedHashes, Hashes); + Failed(Message, Cfg); return; } @@ -1132,16 +1156,18 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,HashStringList con if (_error->PendingError() == true || tag.Step(sec) == false || sec.Exists("Package") == false) { RenameOnError(InvalidFormat); + Failed(Message, Cfg); return; } } - // Done, move it into position + // Done, queue for rename on transaction finished + PartialFile = DestFile; + string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(RealURI); - Rename(DestFile,FinalFile); - chmod(FinalFile.c_str(),0644); - + DestFile = FinalFile; +#if 0 /* We restore the original name to DestFile so that the clean operation will work OK */ DestFile = _config->FindDir("Dir::State::lists") + "partial/"; @@ -1150,7 +1176,7 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,HashStringList con // Remove the compressed version. if (Erase == true) unlink(DestFile.c_str()); - +#endif return; } @@ -1237,9 +1263,10 @@ pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, : pkgAcqIndex(Owner, URI, URIDesc, ShortDesc, HashStringList(), "") { } -pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const * const Target, + /*}}}*/ +pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcqMetaIndex *MetaOwner, IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser) - : pkgAcqIndex(Owner, Target, ExpectedHashes, MetaIndexParser) + : pkgAcqIndex(MetaOwner, Target, ExpectedHashes, MetaIndexParser) { // load the filesize indexRecords::checkSum *Record = MetaIndexParser->Lookup(string(Target->MetaKey)); @@ -1388,11 +1415,18 @@ void pkgAcqMetaSig::Done(string Message,unsigned long long Size, HashStringList if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) Rename(LastGoodSig, DestFile); + // queue for copy + PartialFile = DestFile; + DestFile = _config->FindDir("Dir::State::lists"); + DestFile += URItoFileName(RealURI); + // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved - new pkgAcqMetaIndex(Owner, MetaIndexURI, MetaIndexURIDesc, - MetaIndexShortDesc, DestFile, IndexTargets, - MetaIndexParser); + pkgAcqMetaIndex *mi = new pkgAcqMetaIndex( + Owner, MetaIndexURI, MetaIndexURIDesc, + MetaIndexShortDesc, DestFile, IndexTargets, + MetaIndexParser); + TransactionID = (unsigned long)mi; } /*}}}*/ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/ @@ -1446,6 +1480,8 @@ pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire *Owner, /*{{{*/ DestFile = _config->FindDir("Dir::State::lists") + "partial/"; DestFile += URItoFileName(URI); + TransactionID = (unsigned long)this; + // Create the item Desc.Description = URIDesc; Desc.Owner = this; @@ -1536,8 +1572,7 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,HashStringList FinalFile += URItoFileName(RealURI); if (SigFile == DestFile) SigFile = FinalFile; - Rename(DestFile,FinalFile); - chmod(FinalFile.c_str(),0644); + PartialFile = DestFile; DestFile = FinalFile; } } @@ -1609,6 +1644,7 @@ void pkgAcqMetaIndex::AuthDone(string Message) /*{{{*/ // Download further indexes with verification QueueIndexes(true); +#if 0 // is it a clearsigned MetaIndex file? if (DestFile == SigFile) return; @@ -1618,6 +1654,7 @@ void pkgAcqMetaIndex::AuthDone(string Message) /*{{{*/ URItoFileName(RealURI) + ".gpg"; Rename(SigFile,VerifiedSigFile); chmod(VerifiedSigFile.c_str(),0644); +#endif } /*}}}*/ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ @@ -1700,9 +1737,9 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ { if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true && MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true) - new pkgAcqDiffIndex(Owner, *Target, ExpectedIndexHashes, MetaIndexParser); + new pkgAcqDiffIndex(this, *Target, ExpectedIndexHashes, MetaIndexParser); else - new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHashes, MetaIndexParser); + new pkgAcqIndexTrans(this, *Target, ExpectedIndexHashes, MetaIndexParser); } continue; } @@ -1713,9 +1750,9 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ instead, but passing the required info to it is to much hassle */ if(_config->FindB("Acquire::PDiffs",true) == true && (verify == false || MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true)) - new pkgAcqDiffIndex(Owner, *Target, ExpectedIndexHashes, MetaIndexParser); + new pkgAcqDiffIndex(this, *Target, ExpectedIndexHashes, MetaIndexParser); else - new pkgAcqIndex(Owner, *Target, ExpectedIndexHashes, MetaIndexParser); + new pkgAcqIndex(this, *Target, ExpectedIndexHashes, MetaIndexParser); } } /*}}}*/ @@ -1799,8 +1836,10 @@ bool pkgAcqMetaIndex::VerifyVendor(string Message) /*{{{*/ // pkgAcqMetaIndex::Failed - no Release file present or no signature file present /*{{{*/ // --------------------------------------------------------------------- /* */ -void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/) +void pkgAcqMetaIndex::Failed(string /*Message*/, + pkgAcquire::MethodConfig * /*Cnf*/) { +#if 0 if (AuthPass == true) { // gpgv method failed, if we have a good signature @@ -1838,7 +1877,7 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/) // gpgv method failed ReportMirrorFailure("GPGFailure"); } - +#endif /* Always move the meta index, even if gpgv failed. This ensures * that PackageFile objects are correctly filled in */ if (FileExists(DestFile)) { @@ -1864,6 +1903,15 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/) QueueIndexes(false); } /*}}}*/ + +void pkgAcqMetaIndex::Finished() +{ + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "Finished: " << DestFile <<std::endl; + Owner->CommitTransaction((unsigned long)this); +} + + pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire *Owner, /*{{{*/ string const &URI, string const &URIDesc, string const &ShortDesc, string const &MetaIndexURI, string const &MetaIndexURIDesc, string const &MetaIndexShortDesc, diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 0500a3627..6c9fec695 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -47,6 +47,7 @@ class indexRecords; class pkgRecords; class pkgSourceList; class IndexTarget; +class pkgAcqMetaIndex; /** \brief Represents the process by which a pkgAcquire object should {{{ * retrieve a file or a collection of files. @@ -116,7 +117,7 @@ class pkgAcquire::Item : public WeakPointable /** \brief The item was could not be downloaded because of * a transient network error (e.g. network down) */ - StatTransientNetworkError + StatTransientNetworkError, } Status; /** \brief Contains a textual description of the error encountered @@ -168,6 +169,9 @@ class pkgAcquire::Item : public WeakPointable */ unsigned int QueueCounter; + /** \brief TransactionID */ + unsigned long TransactionID; + /** \brief The number of additional fetch items that are expected * once this item is done. * @@ -183,6 +187,9 @@ class pkgAcquire::Item : public WeakPointable */ std::string DestFile; + /** \brief storge name until a transaction is finished */ + std::string PartialFile; + /** \brief Invoked by the acquire worker when the object couldn't * be fetched. * @@ -368,6 +375,137 @@ class pkgAcqSubIndex : public pkgAcquire::Item }; /*}}}*/ +/** \brief An item that is responsible for downloading the meta-index {{{ + * file (i.e., Release) itself and verifying its signature. + * + * Once the download and verification are complete, the downloads of + * the individual index files are queued up using pkgAcqDiffIndex. + * If the meta-index file had a valid signature, the expected hashsums + * of the index files will be the md5sums listed in the meta-index; + * otherwise, the expected hashsums will be "" (causing the + * authentication of the index files to be bypassed). + */ +class pkgAcqMetaIndex : public pkgAcquire::Item +{ + protected: + /** \brief The URI that is actually being downloaded; never + * modified by pkgAcqMetaIndex. + */ + std::string RealURI; + + /** \brief The file in which the signature for this index was stored. + * + * If empty, the signature and the md5sums of the individual + * indices will not be checked. + */ + std::string SigFile; + + /** \brief The index files to download. */ + const std::vector<IndexTarget*>* IndexTargets; + + /** \brief The parser for the meta-index file. */ + indexRecords* MetaIndexParser; + + /** \brief If \b true, the index's signature is currently being verified. + */ + bool AuthPass; + // required to deal gracefully with problems caused by incorrect ims hits + bool IMSHit; + + /** \brief Check that the release file is a release file for the + * correct distribution. + * + * \return \b true if no fatal errors were encountered. + */ + bool VerifyVendor(std::string Message); + + /** \brief Called when a file is finished being retrieved. + * + * If the file was not downloaded to DestFile, a copy process is + * set up to copy it to DestFile; otherwise, Complete is set to \b + * true and the file is moved to its final location. + * + * \param Message The message block received from the fetch + * subprocess. + */ + void RetrievalDone(std::string Message); + + /** \brief Called when authentication succeeded. + * + * Sanity-checks the authenticated file, queues up the individual + * index files for download, and saves the signature in the lists + * directory next to the authenticated list file. + * + * \param Message The message block received from the fetch + * subprocess. + */ + void AuthDone(std::string Message); + + /** \brief Starts downloading the individual index files. + * + * \param verify If \b true, only indices whose expected hashsum + * can be determined from the meta-index will be downloaded, and + * the hashsums of indices will be checked (reporting + * #StatAuthError if there is a mismatch). If verify is \b false, + * no hashsum checking will be performed. + */ + void QueueIndexes(bool verify); + + public: + + // Specialized action members + 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 Custom600Headers() const; + virtual std::string DescURI() const {return RealURI; }; + virtual void Finished(); + + /** \brief Create a new pkgAcqMetaIndex. */ + pkgAcqMetaIndex(pkgAcquire *Owner, + std::string URI,std::string URIDesc, std::string ShortDesc, + std::string SigFile, + const std::vector<IndexTarget*>* IndexTargets, + indexRecords* MetaIndexParser); +}; + /*}}}*/ +/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/ +class pkgAcqMetaClearSig : public pkgAcqMetaIndex +{ + /** \brief The URI of the meta-index file for the detached signature */ + std::string MetaIndexURI; + + /** \brief A "URI-style" description of the meta-index file */ + std::string MetaIndexURIDesc; + + /** \brief A brief description of the meta-index file */ + std::string MetaIndexShortDesc; + + /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */ + std::string MetaSigURI; + + /** \brief A "URI-style" description of the meta-signature file */ + std::string MetaSigURIDesc; + + /** \brief A brief description of the meta-signature file */ + std::string MetaSigShortDesc; + +public: + void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); + virtual std::string Custom600Headers() const; + + /** \brief Create a new pkgAcqMetaClearSig. */ + pkgAcqMetaClearSig(pkgAcquire *Owner, + 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<IndexTarget*>* IndexTargets, + indexRecords* MetaIndexParser); + virtual ~pkgAcqMetaClearSig(); +}; + /*}}}*/ + + /** \brief Common base class for all classes that deal with fetching {{{ indexes */ @@ -378,13 +516,21 @@ class pkgAcqBaseIndex : public pkgAcquire::Item */ const struct IndexTarget * Target; indexRecords *MetaIndexParser; + pkgAcqMetaIndex *MetaOwner; + + pkgAcqBaseIndex(pkgAcqMetaIndex *MetaOwner, + struct IndexTarget const * const Target, + HashStringList const &ExpectedHashes, + indexRecords *MetaIndexParser) + : Item(MetaOwner->GetOwner(), ExpectedHashes), Target(Target), + MetaIndexParser(MetaIndexParser), MetaOwner(MetaOwner) {}; pkgAcqBaseIndex(pkgAcquire *Owner, struct IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser) : Item(Owner, ExpectedHashes), Target(Target), - MetaIndexParser(MetaIndexParser) {}; + MetaIndexParser(MetaIndexParser), MetaOwner(0) {}; }; /*}}}*/ @@ -451,7 +597,7 @@ class pkgAcqDiffIndex : public pkgAcqBaseIndex * * \param ExpectedHashes The list file's hashsums which are expected. */ - pkgAcqDiffIndex(pkgAcquire *Owner, + pkgAcqDiffIndex(pkgAcqMetaIndex *MetaIndexOwner, struct IndexTarget const * const Target, HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser); @@ -539,7 +685,7 @@ class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex * \param allPatches contains all related items so that each item can * check if it was the last one to complete the download step */ - pkgAcqIndexMergeDiffs(pkgAcquire *Owner, + pkgAcqIndexMergeDiffs(pkgAcqMetaIndex *MetaIndexOwner, struct IndexTarget const * const Target, HashStringList const &ExpectedHash, indexRecords *MetaIndexParser, @@ -667,7 +813,7 @@ class pkgAcqIndexDiffs : public pkgAcqBaseIndex * should be ordered so that each diff appears before any diff * that depends on it. */ - pkgAcqIndexDiffs(pkgAcquire *Owner, + pkgAcqIndexDiffs(pkgAcqMetaIndex *MetaIndexOwner, struct IndexTarget const * const Target, HashStringList const &ExpectedHash, indexRecords *MetaIndexParser, @@ -710,6 +856,9 @@ class pkgAcqIndex : public pkgAcqBaseIndex /** \brief Do the changes needed to fetch via AptByHash (if needed) */ void InitByHashIfNeeded(const std::string MetaKey); + /** \brief Auto select the right compression to use */ + void AutoSelectCompression(); + public: // Specialized action members @@ -741,10 +890,17 @@ class pkgAcqIndex : public pkgAcqBaseIndex pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc, HashStringList const &ExpectedHashes, std::string compressExt=""); +#if 0 pkgAcqIndex(pkgAcquire *Owner, IndexTarget const * const Target, HashStringList const &ExpectedHash, indexRecords *MetaIndexParser); +#endif + pkgAcqIndex(pkgAcqMetaIndex *MetaIndexOwner, + IndexTarget const * const Target, + HashStringList const &ExpectedHash, + indexRecords *MetaIndexParser); + void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc); }; @@ -774,10 +930,12 @@ class pkgAcqIndexTrans : public pkgAcqIndex * * \param ShortDesc A brief description of this index file. */ - pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc, + pkgAcqIndexTrans(pkgAcquire *Owner, + std::string URI,std::string URIDesc, std::string ShortDesc); - pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const * const Target, - HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser); + pkgAcqIndexTrans(pkgAcqMetaIndex *Owner, IndexTarget const * const Target, + HashStringList const &ExpectedHashes, + indexRecords *MetaIndexParser); }; /*}}}*/ /** \brief Information about an index file. */ /*{{{*/ @@ -891,134 +1049,6 @@ class pkgAcqMetaSig : public pkgAcquire::Item virtual ~pkgAcqMetaSig(); }; /*}}}*/ -/** \brief An item that is responsible for downloading the meta-index {{{ - * file (i.e., Release) itself and verifying its signature. - * - * Once the download and verification are complete, the downloads of - * the individual index files are queued up using pkgAcqDiffIndex. - * If the meta-index file had a valid signature, the expected hashsums - * of the index files will be the md5sums listed in the meta-index; - * otherwise, the expected hashsums will be "" (causing the - * authentication of the index files to be bypassed). - */ -class pkgAcqMetaIndex : public pkgAcquire::Item -{ - protected: - /** \brief The URI that is actually being downloaded; never - * modified by pkgAcqMetaIndex. - */ - std::string RealURI; - - /** \brief The file in which the signature for this index was stored. - * - * If empty, the signature and the md5sums of the individual - * indices will not be checked. - */ - std::string SigFile; - - /** \brief The index files to download. */ - const std::vector<IndexTarget*>* IndexTargets; - - /** \brief The parser for the meta-index file. */ - indexRecords* MetaIndexParser; - - /** \brief If \b true, the index's signature is currently being verified. - */ - bool AuthPass; - // required to deal gracefully with problems caused by incorrect ims hits - bool IMSHit; - - /** \brief Check that the release file is a release file for the - * correct distribution. - * - * \return \b true if no fatal errors were encountered. - */ - bool VerifyVendor(std::string Message); - - /** \brief Called when a file is finished being retrieved. - * - * If the file was not downloaded to DestFile, a copy process is - * set up to copy it to DestFile; otherwise, Complete is set to \b - * true and the file is moved to its final location. - * - * \param Message The message block received from the fetch - * subprocess. - */ - void RetrievalDone(std::string Message); - - /** \brief Called when authentication succeeded. - * - * Sanity-checks the authenticated file, queues up the individual - * index files for download, and saves the signature in the lists - * directory next to the authenticated list file. - * - * \param Message The message block received from the fetch - * subprocess. - */ - void AuthDone(std::string Message); - - /** \brief Starts downloading the individual index files. - * - * \param verify If \b true, only indices whose expected hashsum - * can be determined from the meta-index will be downloaded, and - * the hashsums of indices will be checked (reporting - * #StatAuthError if there is a mismatch). If verify is \b false, - * no hashsum checking will be performed. - */ - void QueueIndexes(bool verify); - - public: - - // Specialized action members - 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 Custom600Headers() const; - virtual std::string DescURI() const {return RealURI; }; - - /** \brief Create a new pkgAcqMetaIndex. */ - pkgAcqMetaIndex(pkgAcquire *Owner, - std::string URI,std::string URIDesc, std::string ShortDesc, - std::string SigFile, - const std::vector<IndexTarget*>* IndexTargets, - indexRecords* MetaIndexParser); -}; - /*}}}*/ -/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/ -class pkgAcqMetaClearSig : public pkgAcqMetaIndex -{ - /** \brief The URI of the meta-index file for the detached signature */ - std::string MetaIndexURI; - - /** \brief A "URI-style" description of the meta-index file */ - std::string MetaIndexURIDesc; - - /** \brief A brief description of the meta-index file */ - std::string MetaIndexShortDesc; - - /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */ - std::string MetaSigURI; - - /** \brief A "URI-style" description of the meta-signature file */ - std::string MetaSigURIDesc; - - /** \brief A brief description of the meta-signature file */ - std::string MetaSigShortDesc; - -public: - void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); - virtual std::string Custom600Headers() const; - - /** \brief Create a new pkgAcqMetaClearSig. */ - pkgAcqMetaClearSig(pkgAcquire *Owner, - 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<IndexTarget*>* IndexTargets, - indexRecords* MetaIndexParser); - virtual ~pkgAcqMetaClearSig(); -}; - /*}}}*/ /** \brief An item that is responsible for fetching a package file. {{{ * * If the package file already exists in the cache, nothing will be diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 8467dab5b..2e2e39d51 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -37,6 +37,7 @@ #include <sys/time.h> #include <sys/select.h> #include <errno.h> +#include <sys/stat.h> #include <apti18n.h> /*}}}*/ @@ -168,6 +169,55 @@ void pkgAcquire::Remove(Item *Itm) } } /*}}}*/ +// Acquire::AbortTransaction - Remove a transaction /*{{{*/ +void pkgAcquire::AbortTransaction(unsigned long TransactionID) +{ + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "AbortTransaction: " << TransactionID << std::endl; + + std::vector<Item*> Transaction; + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) + if((*I)->TransactionID == TransactionID) + Transaction.push_back(*I); + + for (std::vector<Item*>::iterator I = Transaction.begin(); + I != Transaction.end(); ++I) + { + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << " Cancel: " << (*I)->DestFile << std::endl; + Dequeue(*I); + (*I)->Status = pkgAcquire::Item::StatError; + } +} + /*}}}*/ +// Acquire::CommitTransaction - Commit a transaction /*{{{*/ +void pkgAcquire::CommitTransaction(unsigned long TransactionID) +{ + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "CommitTransaction: " << TransactionID << std::endl; + + std::vector<Item*> Transaction; + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) + if((*I)->TransactionID == TransactionID) + Transaction.push_back(*I); + + for (std::vector<Item*>::iterator I = Transaction.begin(); + I != Transaction.end(); ++I) + { + if((*I)->PartialFile != "" && + (*I)->Status == pkgAcquire::Item::StatDone) + { + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "mv " + << (*I)->PartialFile << " -> " + << (*I)->DestFile << std::endl; + Rename((*I)->PartialFile, (*I)->DestFile); + chmod((*I)->DestFile.c_str(),0644); + } + } +} + /*}}}*/ + // Acquire::Add - Add a worker /*{{{*/ // --------------------------------------------------------------------- /* A list of workers is kept so that the select loop can direct their FD diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index 0113021b2..0b955cc76 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -248,6 +248,10 @@ class pkgAcquire public: + /** \brief Abort a given transaction */ + void AbortTransaction(unsigned long TransactionID); + void CommitTransaction(unsigned long TransactionID); + /** \brief Retrieve information about a fetch method by name. * * \param Access The name of the method to look up. |