Acquire Item - Item to acquire
When an item is instantiated it will add it self to the local list in
- the Owner Acquire class. Derived classes will then call QueueURI to
- register all the URI's they wish to fetch at the initial moment.
-
+ the Owner Acquire class. Derived classes will then call QueueURI to
+ register all the URI's they wish to fetch at the initial moment.
+
Three item classes are provided to provide functionality for
downloading of Index, Translation and Packages files.
-
+
A Archive class is provided for downloading .deb files. It does Hash
checking and source location as well as a retry algorithm.
-
+
##################################################################### */
/*}}}*/
#ifndef PKGLIB_ACQUIRE_ITEM_H
class pkgRecords;
class pkgSourceList;
class IndexTarget;
-class pkgAcqMetaIndex;
+class pkgAcqMetaBase;
+
+class APT_HIDDEN IndexTarget /*{{{*/
+/** \brief Information about an index file. */
+{
+ public:
+ /** \brief A URI from which the index file can be downloaded. */
+ std::string const URI;
+
+ /** \brief A description of the index file. */
+ std::string const Description;
+
+ /** \brief A shorter description of the index file. */
+ std::string const ShortDesc;
+
+ /** \brief The key by which this index file should be
+ * looked up within the meta signature file.
+ */
+ std::string const MetaKey;
+
+ virtual bool IsOptional() const {
+ return false;
+ }
+
+ IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
+ std::string const &LongDesc, std::string const &URI) :
+ URI(URI), Description(LongDesc), ShortDesc(ShortDesc), MetaKey(MetaKey) {}
+};
+ /*}}}*/
+class APT_HIDDEN OptionalIndexTarget : public IndexTarget /*{{{*/
+/** \brief Information about an optional index file. */
+{
+ public:
+ virtual bool IsOptional() const {
+ return true;
+ }
-/** \brief Represents the process by which a pkgAcquire object should {{{
+ OptionalIndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
+ std::string const &LongDesc, std::string const &URI) :
+ IndexTarget(MetaKey, ShortDesc, LongDesc, URI) {}
+};
+ /*}}}*/
+class pkgAcquire::Item : public WeakPointable /*{{{*/
+/** \brief Represents the process by which a pkgAcquire object should
* retrieve a file or a collection of files.
*
* By convention, Item subclasses should insert themselves into the
*
* \see pkgAcquire
*/
-class pkgAcquire::Item : public WeakPointable
-{
- protected:
-
- /** \brief The acquire object with which this item is associated. */
- pkgAcquire *Owner;
-
- /** \brief Insert this item into its owner's queue.
- *
- * \param Item Metadata about this item (its URI and
- * description).
- */
- inline void QueueURI(ItemDesc &Item)
- {Owner->Enqueue(Item);};
-
- /** \brief Remove this item from its owner's queue. */
- inline void Dequeue() {Owner->Dequeue(this);};
-
- /** \brief Rename a file without modifying its timestamp.
- *
- * Many item methods call this as their final action.
- *
- * \param From The file to be renamed.
- *
- * \param To The new name of \a From. If \a To exists it will be
- * overwritten.
- */
- void Rename(std::string From,std::string To);
-
+{
public:
/** \brief The current status of this item. */
*/
StatAuthError,
- /** \brief The item was could not be downloaded because of
+ /** \brief The item was could not be downloaded because of
* a transient network error (e.g. network down)
*/
StatTransientNetworkError,
/** \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.
- *
+ *
* This field is initalized to 0; it is meant to be filled in by
* clients that wish to use it to uniquely identify items.
*
- * \todo it's unused in apt itself
+ * APT progress reporting will store an ID there as shown in "Get:42 …"
*/
unsigned long ID;
* download progress indicator's overall statistics.
*/
bool Local;
+
std::string UsedMirror;
/** \brief The number of fetch queues into which this item has been
*/
unsigned int QueueCounter;
- /** \brief TransactionID */
- unsigned long TransactionID;
-
/** \brief The number of additional fetch items that are expected
* once this item is done.
*
* progress.
*/
unsigned int ExpectedAdditionalItems;
-
+
/** \brief The name of the file into which the retrieved object
* will be written.
*/
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.
*
*
* \sa pkgAcqMethod
*/
- virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
+ virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
/** \brief Invoked by the acquire worker when the object was
* fetched successfully.
*
* \param Message Data from the acquire method. Use LookupTag()
* to parse it.
- * \param Size The size of the object that was fetched.
* \param Hashes The HashSums of the object that was fetched.
* \param Cnf The method via which the object was fetched.
*
* \sa pkgAcqMethod
*/
- virtual void Done(std::string Message, unsigned long long Size, HashStringList const &Hashes,
- pkgAcquire::MethodConfig *Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
/** \brief Invoked when the worker starts to fetch this object.
*
* \param Message RFC822-formatted data from the worker process.
* Use LookupTag() to parse it.
*
- * \param Size The size of the object being fetched.
+ * \param Hashes The expected hashes of the object being fetched.
*
* \sa pkgAcqMethod
*/
- virtual void Start(std::string Message,unsigned long long Size);
+ virtual void Start(std::string const &Message, unsigned long long const Size);
/** \brief Custom headers to be sent to the fetch process.
*
* line, so they should (if nonempty) have a leading newline and
* no trailing newline.
*/
- virtual std::string Custom600Headers() const {return std::string();};
+ virtual std::string Custom600Headers() const;
/** \brief A "descriptive" URI-like string.
*
*
* \return a brief description of the object being fetched.
*/
- virtual std::string ShortDesc() const {return DescURI();}
+ virtual std::string ShortDesc() const;
/** \brief Invoked by the worker when the download is completely done. */
- virtual void Finished() {};
-
- /** \brief HashSums
+ virtual void Finished();
+
+ /** \return HashSums the DestFile is supposed to have in this stage */
+ virtual HashStringList GetExpectedHashes() const = 0;
+ /** \return the 'best' hash for display proposes like --print-uris */
+ std::string HashSum() const;
+
+ /** \return if having no hashes is a hard failure or not
*
- * \return the HashSums of this object, if applicable; otherwise, an
- * empty list.
+ * Idealy this is always \b true for every subclass, but thanks to
+ * historical grow we don't have hashes for all files in all cases
+ * in all steps, so it is slightly more complicated than it should be.
*/
- 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() : ""; };
+ virtual bool HashesRequired() const { return true; }
/** \return the acquire process with which this item is associated. */
- pkgAcquire *GetOwner() const {return Owner;};
+ pkgAcquire *GetOwner() const;
/** \return \b true if this object is being fetched from a trusted source. */
- virtual bool IsTrusted() const {return false;};
-
- // report mirror problems
+ virtual bool IsTrusted() const;
+
/** \brief Report mirror problem
- *
+ *
* This allows reporting mirror failures back to a centralized
* server. The apt-report-mirror-failure script is called for this
- *
+ *
* \param FailCode A short failure string that is send
*/
- void ReportMirrorFailure(std::string FailCode);
+ void ReportMirrorFailure(std::string const &FailCode);
+ /** \brief Set the name of the current active subprocess
+ *
+ * See also #ActiveSubprocess
+ */
+ void SetActiveSubprocess(std::string const &subprocess);
/** \brief Initialize an item.
*
* manually invoke QueueURI() to do so).
*
* \param Owner The new owner of this item.
- * \param ExpectedHashes of the file represented by this item
*/
- Item(pkgAcquire *Owner,
- HashStringList const &ExpectedHashes=HashStringList(),
- unsigned long TransactionID=0);
+ Item(pkgAcquire * const Owner);
/** \brief Remove this item from its owner's queue by invoking
* pkgAcquire::Remove.
virtual ~Item();
protected:
+ /** \brief The acquire object with which this item is associated. */
+ pkgAcquire * const Owner;
+
+ /** \brief The item that is currently being downloaded. */
+ pkgAcquire::ItemDesc Desc;
enum RenameOnErrorState {
HashSumMismatch,
SizeMismatch,
- InvalidFormat
+ InvalidFormat,
+ SignatureError,
+ NotClearsigned,
+ MaximumSizeExceeded,
+ PDiffError,
};
/** \brief Rename failed file and set error
*/
bool RenameOnError(RenameOnErrorState const state);
- /** \brief The HashSums of the item is supposed to have than done */
- HashStringList ExpectedHashes;
+ /** \brief Insert this item into its owner's queue.
+ *
+ * The method is designed to check if the request would end
+ * in an IMSHit and if it determines that it would, it isn't
+ * queueing the Item and instead sets it to completion instantly.
+ *
+ * \param Item Metadata about this item (its URI and
+ * description).
+ * \return true if the item was inserted, false if IMSHit was detected
+ */
+ virtual bool QueueURI(ItemDesc &Item);
- /** \brief The item that is currently being downloaded. */
- pkgAcquire::ItemDesc Desc;
-};
- /*}}}*/
-/** \brief Information about an index patch (aka diff). */ /*{{{*/
-struct DiffInfo {
- /** The filename of the diff. */
- std::string file;
+ /** \brief Remove this item from its owner's queue. */
+ void Dequeue();
+
+ /** \brief Rename a file without modifying its timestamp.
+ *
+ * Many item methods call this as their final action.
+ *
+ * \param From The file to be renamed.
+ *
+ * \param To The new name of \a From. If \a To exists it will be
+ * overwritten. If \a From and \a To are equal nothing happens.
+ */
+ bool Rename(std::string const &From, std::string const &To);
+
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
- /** The sha1 hash of the diff. */
- std::string sha1;
+ private:
+ void *d;
- /** The size of the diff. */
- unsigned long size;
+ friend class pkgAcqMetaBase;
};
/*}}}*/
-/** \brief An item that is responsible for fetching a SubIndex {{{
- *
- * The MetaIndex file includes only records for important indexes
- * and records for these SubIndex files so these can carry records
- * for addition files like PDiffs and Translations
- */
-class pkgAcqSubIndex : public pkgAcquire::Item
+class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item /*{{{*/
+/** \brief baseclass for the indexes files to manage them all together */
{
- protected:
- /** \brief If \b true, debugging information will be written to std::clog. */
- bool Debug;
+ protected:
+ IndexTarget const * const Target;
+ HashStringList GetExpectedHashesFor(std::string const MetaKey) const;
- 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 DescURI() const {return Desc.URI;};
- virtual std::string Custom600Headers() const;
- virtual bool ParseIndex(std::string const &IndexFile);
+ bool QueueURI(pkgAcquire::ItemDesc &Item);
- /** \brief Create a new pkgAcqSubIndex.
- *
- * \param Owner The Acquire object that owns this item.
- *
- * \param URI The URI of the list file to download.
- *
- * \param URIDesc A long description of the list file to download.
- *
- * \param ShortDesc A short description of the list file to download.
- *
- * \param ExpectedHashes The list file's hashsums which are expected.
- */
- pkgAcqSubIndex(pkgAcquire *Owner,
- unsigned long TransactionID,
- std::string const &URI,std::string const &URIDesc,
- std::string const &ShortDesc, HashStringList const &ExpectedHashes);
+ public:
+ /** \brief storge name until a transaction is finished */
+ std::string PartialFile;
+
+ /** \brief TransactionManager */
+ pkgAcqMetaBase * const TransactionManager;
+
+ enum TransactionStates {
+ TransactionCommit,
+ TransactionAbort,
+ };
+ virtual bool TransactionState(TransactionStates const state);
+
+ virtual std::string DescURI() const { return Target->URI; }
+ virtual HashStringList GetExpectedHashes() const;
+ virtual std::string GetMetaKey() const;
+ virtual bool HashesRequired() const;
+
+
+ pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const * const Target);
+ virtual ~pkgAcqTransactionItem();
+
+ friend class pkgAcqMetaBase;
};
/*}}}*/
-
-class pkgAcqMetaSigBase : public pkgAcquire::Item
+class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
+/** \brief the manager of a transaction */
{
+ void *d;
+
protected:
- bool GenerateAuthWarning(const std::string &RealURI,
- const std::string &Message);
+ std::vector<pkgAcqTransactionItem*> Transaction;
+ IndexTarget const DataTarget;
public:
- pkgAcqMetaSigBase(pkgAcquire *Owner,
- HashStringList const &ExpectedHashes=HashStringList(),
- unsigned long TransactionID=0);
-};
-
-/** \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 pkgAcqMetaSigBase
-{
- protected:
- /** \brief The URI that is actually being downloaded; never
- * modified by pkgAcqMetaIndex.
- */
- std::string RealURI;
+ /** \brief A package-system-specific parser for the meta-index file. */
+ indexRecords *MetaIndexParser;
+ indexRecords *LastMetaIndexParser;
+ protected:
- /** \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.
+ /** \brief The index files which should be looked up in the meta-index
+ * and then downloaded.
*/
- std::string SigFile;
-
- /** \brief The index files to download. */
- const std::vector<IndexTarget*>* IndexTargets;
-
- /** \brief The parser for the meta-index file. */
- indexRecords* MetaIndexParser;
+ const std::vector<IndexTarget*>* const IndexTargets;
/** \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.
+ /** \brief Starts downloading the individual index files.
*
- * \return \b true if no fatal errors were encountered.
+ * \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.
*/
- bool VerifyVendor(std::string Message);
+ void QueueIndexes(bool const verify);
/** \brief Called when a file is finished being retrieved.
*
* \param Message The message block received from the fetch
* subprocess.
*/
- void RetrievalDone(std::string Message);
+ bool CheckDownloadDone(pkgAcqTransactionItem * const I, const std::string &Message, HashStringList const &Hashes) const;
+
+ /** \brief Queue the downloaded Signature for verification */
+ void QueueForSignatureVerify(pkgAcqTransactionItem * const I, std::string const &File, std::string const &Signature);
+
+ virtual std::string Custom600Headers() const;
/** \brief Called when authentication succeeded.
*
* \param Message The message block received from the fetch
* subprocess.
*/
- void AuthDone(std::string Message);
+ bool CheckAuthDone(std::string const &Message);
- /** \brief Starts downloading the individual index files.
+ /** Check if the current item should fail at this point */
+ bool CheckStopAuthentication(pkgAcquire::Item * const I, const std::string &Message);
+
+ /** \brief Check that the release file is a release file for the
+ * correct distribution.
*
- * \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.
+ * \return \b true if no fatal errors were encountered.
*/
- void QueueIndexes(bool verify);
+ bool VerifyVendor(std::string const &Message);
- /** \brief The URI of the meta-index file for the detached signature */
- std::string MetaIndexSigURI;
+ virtual bool TransactionState(TransactionStates const state);
- /** \brief A "URI-style" description of the meta-index file */
- std::string MetaIndexSigURIDesc;
+ public:
+ // This refers more to the Transaction-Manager than the actual file
+ bool IMSHit;
+
+ virtual bool QueueURI(pkgAcquire::ItemDesc &Item);
+ virtual HashStringList GetExpectedHashes() const;
+ virtual bool HashesRequired() const;
- /** \brief A brief description of the meta-index file */
- std::string MetaIndexSigShortDesc;
+ // transaction code
+ void Add(pkgAcqTransactionItem * const I);
+ void AbortTransaction();
+ bool TransactionHasError() const;
+ void CommitTransaction();
+
+ /** \brief Stage (queue) a copy action when the transaction is committed
+ */
+ void TransactionStageCopy(pkgAcqTransactionItem * const I,
+ const std::string &From,
+ const std::string &To);
+ /** \brief Stage (queue) a removal action when the transaction is committed
+ */
+ void TransactionStageRemoval(pkgAcqTransactionItem * const I, const std::string &FinalFile);
+
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
+
+ pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ std::vector<IndexTarget*> const * const IndexTargets,
+ IndexTarget const &DataTarget,
+ indexRecords* const MetaIndexParser);
+};
+ /*}}}*/
+/** \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 APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
+{
+ void *d;
+
+ protected:
+ IndexTarget const DetachedSigTarget;
/** \brief delayed constructor */
- void Init(std::string URIDesc, std::string ShortDesc);
-
+ void Init(std::string const &URIDesc, std::string const &ShortDesc);
+
public:
-
+ virtual std::string DescURI() const;
+
// 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 Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
virtual void Finished();
/** \brief Create a new pkgAcqMetaIndex. */
- pkgAcqMetaIndex(pkgAcquire *Owner,
- unsigned long TransactionID,
- std::string URI,std::string URIDesc, std::string ShortDesc,
- std::string MetaIndexSigURI, std::string MetaIndexSigURIDesc, std::string MetaIndexSigShortDesc,
- const std::vector<IndexTarget*>* IndexTargets,
- indexRecords* MetaIndexParser);
+ pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ IndexTarget const &DataTarget, IndexTarget const &DetachedSigTarget,
+ const std::vector<IndexTarget*>* const IndexTargets, indexRecords * const MetaIndexParser);
+
+ friend class pkgAcqMetaSig;
};
/*}}}*/
-/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
-class pkgAcqMetaClearSig : public pkgAcqMetaIndex
+/** \brief An acquire item that downloads the detached signature {{{
+ * of a meta-index (Release) file, then queues up the release
+ * file itself.
+ *
+ * \todo Why protected members?
+ *
+ * \sa pkgAcqMetaIndex
+ */
+class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem
{
- /** \brief The URI of the meta-index file for the detached signature */
- std::string MetaIndexURI;
+ void *d;
+
+ pkgAcqMetaIndex * const MetaIndex;
+
+ /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
+ std::string MetaIndexFileSignature;
- /** \brief A "URI-style" description of the meta-index file */
- std::string MetaIndexURIDesc;
+ protected:
+
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
- /** \brief A brief description of the meta-index file */
- std::string MetaIndexShortDesc;
+ public:
+ virtual bool HashesRequired() const { return false; }
- /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
- std::string MetaSigURI;
+ // Specialized action members
+ virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
- /** \brief A "URI-style" description of the meta-signature file */
- std::string MetaSigURIDesc;
+ /** \brief Create a new pkgAcqMetaSig. */
+ pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const * const Target,
+ pkgAcqMetaIndex * const MetaIndex);
+ virtual ~pkgAcqMetaSig();
+};
+ /*}}}*/
+/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
+class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
+{
+ void *d;
- /** \brief A brief description of the meta-signature file */
- std::string MetaSigShortDesc;
+ IndexTarget const ClearsignedTarget;
+ IndexTarget const DetachedDataTarget;
+ IndexTarget const DetachedSigTarget;
public:
- virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
+ virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
virtual std::string Custom600Headers() const;
- virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
- pkgAcquire::MethodConfig *Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
/** \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);
+ pkgAcqMetaClearSig(pkgAcquire * const Owner,
+ IndexTarget const &ClearsignedTarget,
+ IndexTarget const &DetachedDataTarget,
+ IndexTarget const &DetachedSigTarget,
+ std::vector<IndexTarget*> const * const IndexTargets,
+ indexRecords * const MetaIndexParser);
virtual ~pkgAcqMetaClearSig();
};
/*}}}*/
+/** \brief Common base class for all classes that deal with fetching indexes {{{*/
+class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
+{
+ void *d;
+ public:
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
-/** \brief Common base class for all classes that deal with fetching {{{
- indexes
- */
-class pkgAcqBaseIndex : public pkgAcquire::Item
-{
- protected:
- /** \brief Pointer to the IndexTarget data
- */
- const struct IndexTarget * Target;
- indexRecords *MetaIndexParser;
- /** \brief The MetaIndex Key */
- std::string MetaKey;
-
- pkgAcqBaseIndex(pkgAcquire *Owner,
- unsigned long TransactionID,
- struct IndexTarget const * const Target,
- HashStringList const &ExpectedHashes,
- indexRecords *MetaIndexParser)
- : Item(Owner, ExpectedHashes, TransactionID), Target(Target),
- MetaIndexParser(MetaIndexParser) {};
+ pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ IndexTarget const * const Target);
};
/*}}}*/
/** \brief An item that is responsible for fetching an index file of {{{
*
* \sa pkgAcqIndexDiffs, pkgAcqIndex
*/
-class pkgAcqDiffIndex : public pkgAcqBaseIndex
+class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
{
+ void *d;
+
protected:
/** \brief If \b true, debugging information will be written to std::clog. */
bool Debug;
- /** \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 index file which will be patched to generate the new
* file.
*/
*/
std::string Description;
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
+
+ virtual bool QueueURI(pkgAcquire::ItemDesc &Item);
+
+ virtual bool TransactionState(TransactionStates const state);
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 DescURI() const {return RealURI + "Index";};
+ virtual void Failed(std::string const &Message, pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
+ virtual std::string DescURI() const {return Target->URI + "Index";};
virtual std::string Custom600Headers() const;
+ virtual std::string GetMetaKey() const;
/** \brief Parse the Index file for a set of Packages diffs.
*
* \return \b true if the Index file was successfully parsed, \b
* false otherwise.
*/
- bool ParseDiffIndex(std::string IndexDiffFile);
-
+ bool ParseDiffIndex(std::string const &IndexDiffFile);
/** \brief Create a new pkgAcqDiffIndex.
*
* \param URIDesc A long description of the list file to download.
*
* \param ShortDesc A short description of the list file to download.
- *
- * \param ExpectedHashes The list file's hashsums which are expected.
*/
- pkgAcqDiffIndex(pkgAcquire *Owner,
- unsigned long TransactionID,
- struct IndexTarget const * const Target,
- HashStringList const &ExpectedHashes,
- indexRecords *MetaIndexParser);
+ pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ IndexTarget const * const Target);
+ private:
+ APT_HIDDEN void QueueOnIMSHit() const;
+};
+ /*}}}*/
+struct APT_HIDDEN DiffInfo { /*{{{*/
+ /** The filename of the diff. */
+ std::string file;
+
+ /** The hashes of the file after the diff is applied */
+ HashStringList result_hashes;
+
+ /** The hashes of the diff */
+ HashStringList patch_hashes;
+
+ /** The hashes of the compressed diff */
+ HashStringList download_hashes;
};
/*}}}*/
/** \brief An item that is responsible for fetching client-merge patches {{{
*
* \sa pkgAcqDiffIndex, pkgAcqIndex
*/
-class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
+class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
{
+ void *d;
+
protected:
/** \brief If \b true, debugging output will be written to
*/
bool Debug;
- /** \brief URI of the package index file that is being
- * reconstructed.
- */
- std::string RealURI;
-
/** \brief description of the file being downloaded. */
std::string Description;
* This method will fall back to downloading the whole index file
* outright; its arguments are ignored.
*/
- 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 void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
+ virtual std::string Custom600Headers() const;
+ virtual std::string DescURI() const {return Target->URI + "Index";};
+ virtual HashStringList GetExpectedHashes() const;
+ virtual bool HashesRequired() const;
/** \brief Create an index merge-diff item.
*
*
* \param ShortDesc A brief description of this item.
*
- * \param ExpectedHashes The expected md5sum of the completely
- * reconstructed package index file; the index file will be tested
- * against this value when it is entirely reconstructed.
- *
* \param patch contains infos about the patch this item is supposed
* to download which were read from the index
*
* \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,
- unsigned long TransactionID,
- struct IndexTarget const * const Target,
- HashStringList const &ExpectedHash,
- indexRecords *MetaIndexParser,
- DiffInfo const &patch,
+ pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ IndexTarget const * const Target,
+ DiffInfo const &patch,
std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
};
/*}}}*/
*
* \sa pkgAcqDiffIndex, pkgAcqIndex
*/
-class pkgAcqIndexDiffs : public pkgAcqBaseIndex
+class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
{
+ void *d;
+
private:
/** \brief Queue up the next diff download.
* \return \b true if an applicable diff was found, \b false
* otherwise.
*/
- bool QueueNextDiff();
+ APT_HIDDEN bool QueueNextDiff();
/** \brief Handle tasks that must be performed after the item
* finishes downloading.
* \param allDone If \b true, the file was entirely reconstructed,
* and its md5sum is verified.
*/
- void Finish(bool allDone=false);
+ APT_HIDDEN void Finish(bool const allDone=false);
protected:
*/
bool Debug;
- /** \brief The URI of the package index file that is being
- * reconstructed.
- */
- std::string RealURI;
-
/** A description of the file being downloaded. */
std::string Description;
*/
std::vector<DiffInfo> available_patches;
- /** Stop applying patches when reaching that sha1 */
- std::string ServerSha1;
-
/** The current status of this patch. */
enum DiffState
{
/** \brief The diff is currently being fetched. */
StateFetchDiff,
-
- /** \brief The diff is currently being uncompressed. */
- StateUnzipDiff, // FIXME: No longer used
/** \brief The diff is currently being applied. */
StateApplyDiff
} State;
public:
-
+
/** \brief Called when the patch file failed to be downloaded.
*
* This method will fall back to downloading the whole index file
* outright; its arguments are ignored.
*/
- virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
+ virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const 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 void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
+ virtual std::string Custom600Headers() const;
+ virtual std::string DescURI() const {return Target->URI + "IndexDiffs";};
+ virtual HashStringList GetExpectedHashes() const;
+ virtual bool HashesRequired() const;
/** \brief Create an index diff item.
*
*
* \param ShortDesc A brief description of this item.
*
- * \param ExpectedHashes The expected md5sum of the completely
- * reconstructed package index file; the index file will be tested
- * against this value when it is entirely reconstructed.
- *
- * \param ServerSha1 is the sha1sum of the current file on the server
- *
* \param diffs The remaining diffs from the index of diffs. They
* should be ordered so that each diff appears before any diff
* that depends on it.
*/
- pkgAcqIndexDiffs(pkgAcquire *Owner,
- unsigned long TransactionID,
- struct IndexTarget const * const Target,
- HashStringList const &ExpectedHash,
- indexRecords *MetaIndexParser,
- std::string ServerSha1,
- std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
+ pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ IndexTarget const * const Target,
+ std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>());
};
/*}}}*/
/** \brief An acquire item that is responsible for fetching an index {{{
*
* \todo Why does pkgAcqIndex have protected members?
*/
-class pkgAcqIndex : public pkgAcqBaseIndex
+class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
{
- protected:
+ void *d;
- /** \brief If \b true, the index file has been decompressed. */
- bool Decompression;
+ protected:
- /** \brief If \b true, the partially downloaded file will be
- * removed when the download completes.
+ /** \brief The stages the method goes through
+ *
+ * The method first downloads the indexfile, then its decompressed (or
+ * copied) and verified
*/
- bool Erase;
+ enum AllStages {
+ STAGE_DOWNLOAD,
+ STAGE_DECOMPRESS_AND_VERIFY,
+ };
+ AllStages Stage;
- // FIXME:
- // Unused, used to be used to verify that "Packages: " header was there
- bool __DELME_ON_NEXT_ABI_BREAK_Verify;
+ /** \brief Handle what needs to be done when the download is done */
+ void StageDownloadDone(std::string const &Message,
+ HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cfg);
- /** \brief The object that is actually being fetched (minus any
- * compression-related extensions).
+ /** \brief Handle what needs to be done when the decompression/copy is
+ * done
*/
- std::string RealURI;
+ void StageDecompressDone(std::string const &Message,
+ HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cfg);
+
+ /** \brief If \b set, this partially downloaded file will be
+ * removed when the download completes.
+ */
+ std::string EraseFileName;
/** \brief The compression-related file extensions that are being
* added to the downloaded file one by one if first fails (e.g., "gz bz2").
*/
- std::string CompressionExtension;
+ std::string CompressionExtensions;
+
+ /** \brief The actual compression extension currently used */
+ std::string CurrentCompressionExtension;
/** \brief Do the changes needed to fetch via AptByHash (if needed) */
- void InitByHashIfNeeded(const std::string MetaKey);
+ void InitByHashIfNeeded();
/** \brief Auto select the right compression to use */
void AutoSelectCompression();
- /** \brief Get the full pathname of the final file for the given URI
- */
- std::string GetFinalFilename(std::string const &URI,
- std::string const &compExt);
-
/** \brief Schedule file for verification after a IMS hit */
- void ReverifyAfterIMS(std::string const &FileName);
+ void ReverifyAfterIMS();
- 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 Desc.URI;};
+ /** \brief Validate the downloaded index file */
+ bool ValidateFile(std::string const &FileName);
- /** \brief Create a pkgAcqIndex.
- *
- * \param Owner The pkgAcquire object with which this item is
- * associated.
- *
- * \param URI The URI of the index file that is to be downloaded.
- *
- * \param URIDesc A "URI-style" description of this index file.
- *
- * \param ShortDesc A brief description of this index file.
- *
- * \param ExpectedHashes The expected hashsum of this index file.
- *
- * \param compressExt The compression-related extension with which
- * this index file should be downloaded, or "" to autodetect
- * Compression types can be set with config Acquire::CompressionTypes,
- * default is ".lzma" or ".bz2" (if the needed binaries are present)
- * fallback is ".gz" or none.
- */
- pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
- std::string ShortDesc, HashStringList const &ExpectedHashes,
- std::string compressExt="");
- pkgAcqIndex(pkgAcquire *Owner, unsigned long TransactionID,
- IndexTarget const * const Target,
- HashStringList const &ExpectedHash,
- indexRecords *MetaIndexParser);
-
- void Init(std::string const &URI, std::string const &URIDesc,
- std::string const &ShortDesc);
-};
- /*}}}*/
-/** \brief An acquire item that is responsible for fetching a {{{
- * translated index file.
- *
- * The only difference from pkgAcqIndex is that transient failures
- * are suppressed: no error occurs if the translated index file is
- * missing.
- */
-class pkgAcqIndexTrans : public pkgAcqIndex
-{
- public:
-
- virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
- virtual std::string Custom600Headers() const;
-
- /** \brief Create a pkgAcqIndexTrans.
- *
- * \param Owner The pkgAcquire object with which this item is
- * associated.
- *
- * \param URI The URI of the index file that is to be downloaded.
- *
- * \param URIDesc A "URI-style" description of this index file.
- *
- * \param ShortDesc A brief description of this index file.
- */
- pkgAcqIndexTrans(pkgAcquire *Owner,
- std::string URI,std::string URIDesc,
- std::string ShortDesc);
- pkgAcqIndexTrans(pkgAcquire *Owner,
- unsigned long TransactionID,
- IndexTarget const * const Target,
- HashStringList const &ExpectedHashes,
- indexRecords *MetaIndexParser);
-};
- /*}}}*/
-/** \brief Information about an index file. */ /*{{{*/
-class IndexTarget
-{
- public:
- /** \brief A URI from which the index file can be downloaded. */
- std::string URI;
-
- /** \brief A description of the index file. */
- std::string Description;
-
- /** \brief A shorter description of the index file. */
- std::string ShortDesc;
-
- /** \brief The key by which this index file should be
- * looked up within the meta signature file.
- */
- std::string MetaKey;
-
- virtual bool IsOptional() const {
- return false;
- }
- virtual bool IsSubIndex() const {
- return false;
- }
-};
- /*}}}*/
-/** \brief Information about an optional index file. */ /*{{{*/
-class OptionalIndexTarget : public IndexTarget
-{
- virtual bool IsOptional() const {
- return true;
- }
-};
- /*}}}*/
-/** \brief Information about an subindex index file. */ /*{{{*/
-class SubIndexTarget : public IndexTarget
-{
- virtual bool IsSubIndex() const {
- return true;
- }
-};
- /*}}}*/
-/** \brief Information about an subindex index file. */ /*{{{*/
-class OptionalSubIndexTarget : public OptionalIndexTarget
-{
- virtual bool IsSubIndex() const {
- return true;
- }
-};
- /*}}}*/
-
-/** \brief An acquire item that downloads the detached signature {{{
- * of a meta-index (Release) file, then queues up the release
- * file itself.
- *
- * \todo Why protected members?
- *
- * \sa pkgAcqMetaIndex
- */
-class pkgAcqMetaSig : public pkgAcqMetaSigBase
-{
- protected:
- /** \brief The last good signature file */
- std::string LastGoodSig;
-
- /** \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.
- */
- std::string RealURI;
-
- /** \brief A package-system-specific parser for the meta-index file. */
- indexRecords* MetaIndexParser;
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
- /** \brief The file we need to verify */
- std::string MetaIndexFile;
-
- /** \brief The index files which should be looked up in the meta-index
- * and then downloaded.
- *
- * \todo Why a list of pointers instead of a list of structs?
- */
- const std::vector<IndexTarget*>* IndexTargets;
-
- /** \brief If we are in fetching or download state */
- bool AuthPass;
-
- /** \brief Was this file already on disk */
- bool IMSHit;
+ virtual bool TransactionState(TransactionStates const state);
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 void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
virtual std::string Custom600Headers() const;
- virtual std::string DescURI() const {return RealURI; };
+ virtual std::string DescURI() const {return Desc.URI;};
+ virtual std::string GetMetaKey() const;
- /** \brief Create a new pkgAcqMetaSig. */
- pkgAcqMetaSig(pkgAcquire *Owner,
- unsigned long TransactionID,
- std::string URI,std::string URIDesc, std::string ShortDesc,
- std::string MetaIndexFile,
- const std::vector<IndexTarget*>* IndexTargets,
- indexRecords* MetaIndexParser);
- virtual ~pkgAcqMetaSig();
+ pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
+ IndexTarget const * const Target);
+
+ void Init(std::string const &URI, std::string const &URIDesc,
+ std::string const &ShortDesc);
};
/*}}}*/
/** \brief An item that is responsible for fetching a package file. {{{
*/
class pkgAcqArchive : public pkgAcquire::Item
{
+ void *d;
+
+ bool LocalSource;
+ HashStringList ExpectedHashes;
+
protected:
/** \brief The package version being fetched. */
pkgCache::VerIterator Version;
/** \brief \b true if this version file is being downloaded from a
* trusted source.
*/
- bool Trusted;
+ bool Trusted;
/** \brief Queue up the next available file for this version. */
bool QueueNext();
-
+
+ /** \brief Get the full pathname of the final file for the current URI */
+ virtual std::string GetFinalFilename() const;
+
public:
-
- 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 void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &Hashes,
+ pkgAcquire::MethodConfig const * const Cnf);
+ virtual std::string DescURI() const;
+ virtual std::string ShortDesc() const;
virtual void Finished();
virtual bool IsTrusted() const;
-
+ virtual HashStringList GetExpectedHashes() const;
+ virtual bool HashesRequired() const;
+
/** \brief Create a new pkgAcqArchive.
*
* \param Owner The pkgAcquire object with which this item is
* basename in the constructor, and filled in with a fully
* qualified filename once the download finishes.
*/
- pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
- pkgRecords *Recs,pkgCache::VerIterator const &Version,
+ pkgAcqArchive(pkgAcquire * const Owner,pkgSourceList * const Sources,
+ pkgRecords * const Recs,pkgCache::VerIterator const &Version,
std::string &StoreFilename);
};
/*}}}*/
*/
class pkgAcqFile : public pkgAcquire::Item
{
+ void *d;
+
/** \brief How many times to retry the download, set from
* Acquire::Retries.
*/
unsigned int Retries;
-
+
/** \brief Should this file be considered a index file */
bool IsIndexFile;
+ HashStringList const ExpectedHashes;
public:
-
+ virtual HashStringList GetExpectedHashes() const;
+ virtual bool HashesRequired() const;
+
// Specialized action members
- 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 void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
+ virtual void Done(std::string const &Message, HashStringList const &CalcHashes,
+ pkgAcquire::MethodConfig const * const Cnf);
virtual std::string DescURI() const {return Desc.URI;};
virtual std::string Custom600Headers() const;
* is the absolute name to which the file should be downloaded.
*/
- pkgAcqFile(pkgAcquire *Owner, std::string URI, HashStringList const &Hashes, unsigned long long Size,
- std::string Desc, std::string ShortDesc,
- const std::string &DestDir="", const std::string &DestFilename="",
- bool IsIndexFile=false);
+ pkgAcqFile(pkgAcquire * const Owner, std::string const &URI, HashStringList const &Hashes, unsigned long long const Size,
+ std::string const &Desc, std::string const &ShortDesc,
+ std::string const &DestDir="", std::string const &DestFilename="",
+ bool const IsIndexFile=false);
};
/*}}}*/
/** @} */