1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
4 /* ######################################################################
6 Acquire Item - Item to acquire
8 When an item is instantiated it will add it self to the local list in
9 the Owner Acquire class. Derived classes will then call QueueURI to
10 register all the URI's they wish to fetch at the initial moment.
12 Three item classes are provided to provide functionality for
13 downloading of Index, Translation and Packages files.
15 A Archive class is provided for downloading .deb files. It does Hash
16 checking and source location as well as a retry algorithm.
18 ##################################################################### */
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
23 #include <apt-pkg/acquire.h>
24 #include <apt-pkg/indexfile.h>
25 #include <apt-pkg/hashes.h>
26 #include <apt-pkg/weakptr.h>
27 #include <apt-pkg/pkgcache.h>
28 #include <apt-pkg/cacheiterators.h>
34 #ifndef APT_8_CLEANER_HEADERS
35 #include <apt-pkg/vendor.h>
36 #include <apt-pkg/sourcelist.h>
37 #include <apt-pkg/pkgrecords.h>
38 #include <apt-pkg/indexrecords.h>
41 /** \addtogroup acquire
44 * \file acquire-item.h
52 class pkgAcquire::Item
: public WeakPointable
/*{{{*/
53 /** \brief Represents the process by which a pkgAcquire object should
54 * retrieve a file or a collection of files.
56 * By convention, Item subclasses should insert themselves into the
57 * acquire queue when they are created by calling QueueURI(), and
58 * remove themselves by calling Dequeue() when either Done() or
59 * Failed() is invoked. Item objects are also responsible for
60 * notifying the download progress indicator (accessible via
61 * #Owner->Log) of their status.
68 /** \brief The current status of this item. */
71 /** \brief The item is waiting to be downloaded. */
74 /** \brief The item is currently being downloaded. */
77 /** \brief The item has been successfully downloaded. */
80 /** \brief An error was encountered while downloading this
85 /** \brief The item was downloaded but its authenticity could
90 /** \brief The item was could not be downloaded because of
91 * a transient network error (e.g. network down)
93 StatTransientNetworkError
,
96 /** \brief Contains a textual description of the error encountered
97 * if #ItemState is #StatError or #StatAuthError.
99 std::string ErrorText
;
101 /** \brief The size of the object to fetch. */
102 unsigned long long FileSize
;
104 /** \brief How much of the object was already fetched. */
105 unsigned long long PartialSize
;
107 /** \brief If not \b NULL, contains the name of a subprocess that
108 * is operating on this object (for instance, "gzip" or "gpgv").
110 APT_DEPRECATED
const char *Mode
;
112 /** \brief contains the name of the subprocess that is operating on this object
113 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
114 * as it can manage the lifetime of included string properly. */
115 std::string ActiveSubprocess
;
117 /** \brief A client-supplied unique identifier.
119 * This field is initalized to 0; it is meant to be filled in by
120 * clients that wish to use it to uniquely identify items.
122 * APT progress reporting will store an ID there as shown in "Get:42 …"
126 /** \brief If \b true, the entire object has been successfully fetched.
128 * Subclasses should set this to \b true when appropriate.
132 /** \brief If \b true, the URI of this object is "local".
134 * The only effect of this field is to exclude the object from the
135 * download progress indicator's overall statistics.
139 std::string UsedMirror
;
141 /** \brief The number of fetch queues into which this item has been
144 * There is one queue for each source from which an item could be
149 unsigned int QueueCounter
;
151 /** \brief The number of additional fetch items that are expected
152 * once this item is done.
154 * Some items like pkgAcqMeta{Index,Sig} will queue additional
155 * items. This variable can be set by the methods if it knows
156 * in advance how many items to expect to get a more accurate
159 unsigned int ExpectedAdditionalItems
;
161 /** \brief The name of the file into which the retrieved object
164 std::string DestFile
;
166 /** \brief Invoked by the acquire worker when the object couldn't
169 * This is a branch of the continuation of the fetch process.
171 * \param Message An RFC822-formatted message from the acquire
172 * method describing what went wrong. Use LookupTag() to parse
175 * \param Cnf The method via which the worker tried to fetch this object.
179 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
181 /** \brief Invoked by the acquire worker when the object was
182 * fetched successfully.
184 * Note that the object might \e not have been written to
185 * DestFile; check for the presence of an Alt-Filename entry in
186 * Message to find the file to which it was really written.
188 * Done is often used to switch from one stage of the processing
189 * to the next (e.g. fetching, unpacking, copying). It is one
190 * branch of the continuation of the fetch process.
192 * \param Message Data from the acquire method. Use LookupTag()
194 * \param Hashes The HashSums of the object that was fetched.
195 * \param Cnf The method via which the object was fetched.
199 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
200 pkgAcquire::MethodConfig
const * const Cnf
);
202 /** \brief Invoked when the worker starts to fetch this object.
204 * \param Message RFC822-formatted data from the worker process.
205 * Use LookupTag() to parse it.
207 * \param Hashes The expected hashes of the object being fetched.
211 virtual void Start(std::string
const &Message
, unsigned long long const Size
);
213 /** \brief Custom headers to be sent to the fetch process.
215 * \return a string containing RFC822-style headers that are to be
216 * inserted into the 600 URI Acquire message sent to the fetch
217 * subprocess. The headers are inserted after a newline-less
218 * line, so they should (if nonempty) have a leading newline and
219 * no trailing newline.
221 virtual std::string
Custom600Headers() const;
223 /** \brief A "descriptive" URI-like string.
225 * \return a URI that should be used to describe what is being fetched.
227 virtual std::string
DescURI() const = 0;
228 /** \brief Short item description.
230 * \return a brief description of the object being fetched.
232 virtual std::string
ShortDesc() const;
234 /** \brief Invoked by the worker when the download is completely done. */
235 virtual void Finished();
237 /** \return HashSums the DestFile is supposed to have in this stage */
238 virtual HashStringList
GetExpectedHashes() const = 0;
239 /** \return the 'best' hash for display proposes like --print-uris */
240 std::string
HashSum() const;
242 /** \return if having no hashes is a hard failure or not
244 * Idealy this is always \b true for every subclass, but thanks to
245 * historical grow we don't have hashes for all files in all cases
246 * in all steps, so it is slightly more complicated than it should be.
248 virtual bool HashesRequired() const { return true; }
250 /** \return the acquire process with which this item is associated. */
251 pkgAcquire
*GetOwner() const;
252 pkgAcquire::ItemDesc
&GetItemDesc();
254 /** \return \b true if this object is being fetched from a trusted source. */
255 virtual bool IsTrusted() const;
257 /** \brief Report mirror problem
259 * This allows reporting mirror failures back to a centralized
260 * server. The apt-report-mirror-failure script is called for this
262 * \param FailCode A short failure string that is send
264 void ReportMirrorFailure(std::string
const &FailCode
);
266 /** \brief Set the name of the current active subprocess
268 * See also #ActiveSubprocess
270 void SetActiveSubprocess(std::string
const &subprocess
);
272 /** \brief Initialize an item.
274 * Adds the item to the list of items known to the acquire
275 * process, but does not place it into any fetch queues (you must
276 * manually invoke QueueURI() to do so).
278 * \param Owner The new owner of this item.
280 Item(pkgAcquire
* const Owner
);
282 /** \brief Remove this item from its owner's queue by invoking
283 * pkgAcquire::Remove.
288 /** \brief The acquire object with which this item is associated. */
289 pkgAcquire
* const Owner
;
291 /** \brief The item that is currently being downloaded. */
292 pkgAcquire::ItemDesc Desc
;
294 enum RenameOnErrorState
{
304 /** \brief Rename failed file and set error
306 * \param state respresenting the error we encountered
308 bool RenameOnError(RenameOnErrorState
const state
);
310 /** \brief Insert this item into its owner's queue.
312 * The method is designed to check if the request would end
313 * in an IMSHit and if it determines that it would, it isn't
314 * queueing the Item and instead sets it to completion instantly.
316 * \param Item Metadata about this item (its URI and
318 * \return true if the item was inserted, false if IMSHit was detected
320 virtual bool QueueURI(ItemDesc
&Item
);
322 /** \brief Remove this item from its owner's queue. */
325 /** \brief Rename a file without modifying its timestamp.
327 * Many item methods call this as their final action.
329 * \param From The file to be renamed.
331 * \param To The new name of \a From. If \a To exists it will be
332 * overwritten. If \a From and \a To are equal nothing happens.
334 bool Rename(std::string
const &From
, std::string
const &To
);
336 /** \brief Get the full pathname of the final file for the current URI */
337 virtual std::string
GetFinalFilename() const;
342 friend class pkgAcqMetaBase
;
345 class APT_HIDDEN pkgAcqTransactionItem
: public pkgAcquire::Item
/*{{{*/
346 /** \brief baseclass for the indexes files to manage them all together */
349 IndexTarget
const Target
;
350 HashStringList
GetExpectedHashesFor(std::string
const MetaKey
) const;
352 bool QueueURI(pkgAcquire::ItemDesc
&Item
);
355 /** \brief storge name until a transaction is finished */
356 std::string PartialFile
;
358 /** \brief TransactionManager */
359 pkgAcqMetaBase
* const TransactionManager
;
361 enum TransactionStates
{
365 virtual bool TransactionState(TransactionStates
const state
);
367 virtual std::string
DescURI() const { return Target
.URI
; }
368 virtual HashStringList
GetExpectedHashes() const;
369 virtual std::string
GetMetaKey() const;
370 virtual bool HashesRequired() const;
373 pkgAcqTransactionItem(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
);
374 virtual ~pkgAcqTransactionItem();
376 friend class pkgAcqMetaBase
;
379 class APT_HIDDEN pkgAcqMetaBase
: public pkgAcqTransactionItem
/*{{{*/
380 /** \brief the manager of a transaction */
385 std::vector
<pkgAcqTransactionItem
*> Transaction
;
388 /** \brief A package-system-specific parser for the meta-index file. */
389 indexRecords
*MetaIndexParser
;
390 indexRecords
*LastMetaIndexParser
;
393 /** \brief The index files which should be looked up in the meta-index
394 * and then downloaded.
396 std::vector
<IndexTarget
> const IndexTargets
;
398 /** \brief If \b true, the index's signature is currently being verified.
402 /** \brief Starts downloading the individual index files.
404 * \param verify If \b true, only indices whose expected hashsum
405 * can be determined from the meta-index will be downloaded, and
406 * the hashsums of indices will be checked (reporting
407 * #StatAuthError if there is a mismatch). If verify is \b false,
408 * no hashsum checking will be performed.
410 void QueueIndexes(bool const verify
);
412 /** \brief Called when a file is finished being retrieved.
414 * If the file was not downloaded to DestFile, a copy process is
415 * set up to copy it to DestFile; otherwise, Complete is set to \b
416 * true and the file is moved to its final location.
418 * \param Message The message block received from the fetch
421 bool CheckDownloadDone(pkgAcqTransactionItem
* const I
, const std::string
&Message
, HashStringList
const &Hashes
) const;
423 /** \brief Queue the downloaded Signature for verification */
424 void QueueForSignatureVerify(pkgAcqTransactionItem
* const I
, std::string
const &File
, std::string
const &Signature
);
426 virtual std::string
Custom600Headers() const;
428 /** \brief Called when authentication succeeded.
430 * Sanity-checks the authenticated file, queues up the individual
431 * index files for download, and saves the signature in the lists
432 * directory next to the authenticated list file.
434 * \param Message The message block received from the fetch
437 bool CheckAuthDone(std::string
const &Message
);
439 /** Check if the current item should fail at this point */
440 bool CheckStopAuthentication(pkgAcquire::Item
* const I
, const std::string
&Message
);
442 /** \brief Check that the release file is a release file for the
443 * correct distribution.
445 * \return \b true if no fatal errors were encountered.
447 bool VerifyVendor(std::string
const &Message
);
449 virtual bool TransactionState(TransactionStates
const state
);
452 // This refers more to the Transaction-Manager than the actual file
455 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
456 virtual HashStringList
GetExpectedHashes() const;
457 virtual bool HashesRequired() const;
460 void Add(pkgAcqTransactionItem
* const I
);
461 void AbortTransaction();
462 bool TransactionHasError() const;
463 void CommitTransaction();
465 /** \brief Stage (queue) a copy action when the transaction is committed
467 void TransactionStageCopy(pkgAcqTransactionItem
* const I
,
468 const std::string
&From
,
469 const std::string
&To
);
470 /** \brief Stage (queue) a removal action when the transaction is committed
472 void TransactionStageRemoval(pkgAcqTransactionItem
* const I
, const std::string
&FinalFile
);
474 /** \brief Get the full pathname of the final file for the current URI */
475 virtual std::string
GetFinalFilename() const;
477 pkgAcqMetaBase(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
478 std::vector
<IndexTarget
> const IndexTargets
,
479 IndexTarget
const &DataTarget
,
480 indexRecords
* const MetaIndexParser
);
483 /** \brief An item that is responsible for downloading the meta-index {{{
484 * file (i.e., Release) itself and verifying its signature.
486 * Once the download and verification are complete, the downloads of
487 * the individual index files are queued up using pkgAcqDiffIndex.
488 * If the meta-index file had a valid signature, the expected hashsums
489 * of the index files will be the md5sums listed in the meta-index;
490 * otherwise, the expected hashsums will be "" (causing the
491 * authentication of the index files to be bypassed).
493 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
498 IndexTarget
const DetachedSigTarget
;
500 /** \brief delayed constructor */
501 void Init(std::string
const &URIDesc
, std::string
const &ShortDesc
);
504 virtual std::string
DescURI() const;
506 // Specialized action members
507 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
508 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
509 pkgAcquire::MethodConfig
const * const Cnf
);
510 virtual void Finished();
512 /** \brief Create a new pkgAcqMetaIndex. */
513 pkgAcqMetaIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
514 IndexTarget
const &DataTarget
, IndexTarget
const &DetachedSigTarget
,
515 std::vector
<IndexTarget
> const IndexTargets
, indexRecords
* const MetaIndexParser
);
517 friend class pkgAcqMetaSig
;
520 /** \brief An acquire item that downloads the detached signature {{{
521 * of a meta-index (Release) file, then queues up the release
524 * \todo Why protected members?
526 * \sa pkgAcqMetaIndex
528 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqTransactionItem
532 pkgAcqMetaIndex
* const MetaIndex
;
534 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
535 std::string MetaIndexFileSignature
;
539 /** \brief Get the full pathname of the final file for the current URI */
540 virtual std::string
GetFinalFilename() const;
543 virtual bool HashesRequired() const { return false; }
545 // Specialized action members
546 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
547 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
548 pkgAcquire::MethodConfig
const * const Cnf
);
550 /** \brief Create a new pkgAcqMetaSig. */
551 pkgAcqMetaSig(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
,
552 pkgAcqMetaIndex
* const MetaIndex
);
553 virtual ~pkgAcqMetaSig();
556 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
557 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
561 IndexTarget
const ClearsignedTarget
;
562 IndexTarget
const DetachedDataTarget
;
563 IndexTarget
const DetachedSigTarget
;
566 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
567 virtual std::string
Custom600Headers() const;
568 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
569 pkgAcquire::MethodConfig
const * const Cnf
);
571 /** \brief Create a new pkgAcqMetaClearSig. */
572 pkgAcqMetaClearSig(pkgAcquire
* const Owner
,
573 IndexTarget
const &ClearsignedTarget
,
574 IndexTarget
const &DetachedDataTarget
,
575 IndexTarget
const &DetachedSigTarget
,
576 std::vector
<IndexTarget
> const IndexTargets
,
577 indexRecords
* const MetaIndexParser
);
578 virtual ~pkgAcqMetaClearSig();
581 /** \brief Common base class for all classes that deal with fetching indexes {{{*/
582 class APT_HIDDEN pkgAcqBaseIndex
: public pkgAcqTransactionItem
587 /** \brief Get the full pathname of the final file for the current URI */
588 virtual std::string
GetFinalFilename() const;
590 pkgAcqBaseIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
591 IndexTarget
const Target
);
594 /** \brief An item that is responsible for fetching an index file of {{{
595 * package list diffs and starting the package list's download.
597 * This item downloads the Index file and parses it, then enqueues
598 * additional downloads of either the individual patches (using
599 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
601 * \sa pkgAcqIndexDiffs, pkgAcqIndex
603 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
608 /** \brief If \b true, debugging information will be written to std::clog. */
611 /** \brief A description of the Packages file (stored in
612 * pkgAcquire::ItemDesc::Description).
614 std::string Description
;
616 /** \brief Get the full pathname of the final file for the current URI */
617 virtual std::string
GetFinalFilename() const;
619 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
621 virtual bool TransactionState(TransactionStates
const state
);
623 // Specialized action members
624 virtual void Failed(std::string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
);
625 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
626 pkgAcquire::MethodConfig
const * const Cnf
);
627 virtual std::string
DescURI() const {return Target
.URI
+ "Index";};
628 virtual std::string
Custom600Headers() const;
629 virtual std::string
GetMetaKey() const;
631 /** \brief Parse the Index file for a set of Packages diffs.
633 * Parses the Index file and creates additional download items as
636 * \param IndexDiffFile The name of the Index file.
638 * \return \b true if the Index file was successfully parsed, \b
641 bool ParseDiffIndex(std::string
const &IndexDiffFile
);
643 /** \brief Create a new pkgAcqDiffIndex.
645 * \param Owner The Acquire object that owns this item.
647 * \param URI The URI of the list file to download.
649 * \param URIDesc A long description of the list file to download.
651 * \param ShortDesc A short description of the list file to download.
653 pkgAcqDiffIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
654 IndexTarget
const Target
);
656 APT_HIDDEN
void QueueOnIMSHit() const;
659 struct APT_HIDDEN DiffInfo
{ /*{{{*/
660 /** The filename of the diff. */
663 /** The hashes of the file after the diff is applied */
664 HashStringList result_hashes
;
666 /** The hashes of the diff */
667 HashStringList patch_hashes
;
669 /** The hashes of the compressed diff */
670 HashStringList download_hashes
;
673 /** \brief An item that is responsible for fetching client-merge patches {{{
674 * that need to be applied to a given package index file.
676 * Instead of downloading and applying each patch one by one like its
677 * sister #pkgAcqIndexDiffs this class will download all patches at once
678 * and call rred with all the patches downloaded once. Rred will then
679 * merge and apply them in one go, which should be a lot faster – but is
680 * incompatible with server-based merges of patches like reprepro can do.
682 * \sa pkgAcqDiffIndex, pkgAcqIndex
684 class APT_HIDDEN pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
690 /** \brief If \b true, debugging output will be written to
695 /** \brief description of the file being downloaded. */
696 std::string Description
;
698 /** \brief information about the current patch */
699 struct DiffInfo
const patch
;
701 /** \brief list of all download items for the patches */
702 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
704 /** The current status of this patch. */
707 /** \brief The diff is currently being fetched. */
710 /** \brief The diff is currently being applied. */
713 /** \brief the work with this diff is done */
716 /** \brief something bad happened and fallback was triggered */
721 /** \brief Called when the patch file failed to be downloaded.
723 * This method will fall back to downloading the whole index file
724 * outright; its arguments are ignored.
726 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
727 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
728 pkgAcquire::MethodConfig
const * const Cnf
);
729 virtual std::string
Custom600Headers() const;
730 virtual std::string
DescURI() const {return Target
.URI
+ "Index";};
731 virtual HashStringList
GetExpectedHashes() const;
732 virtual bool HashesRequired() const;
734 /** \brief Create an index merge-diff item.
736 * \param Owner The pkgAcquire object that owns this item.
738 * \param URI The URI of the package index file being
741 * \param URIDesc A long description of this item.
743 * \param ShortDesc A brief description of this item.
745 * \param patch contains infos about the patch this item is supposed
746 * to download which were read from the index
748 * \param allPatches contains all related items so that each item can
749 * check if it was the last one to complete the download step
751 pkgAcqIndexMergeDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
752 IndexTarget
const Target
, DiffInfo
const &patch
,
753 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
756 /** \brief An item that is responsible for fetching server-merge patches {{{
757 * that need to be applied to a given package index file.
759 * After downloading and applying a single patch, this item will
760 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
761 * patches. If no patch can be found that applies to an intermediate
762 * file or if one of the patches cannot be downloaded, falls back to
763 * downloading the entire package index file using pkgAcqIndex.
765 * \sa pkgAcqDiffIndex, pkgAcqIndex
767 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
773 /** \brief Queue up the next diff download.
775 * Search for the next available diff that applies to the file
776 * that currently exists on disk, and enqueue it by calling
779 * \return \b true if an applicable diff was found, \b false
782 APT_HIDDEN
bool QueueNextDiff();
784 /** \brief Handle tasks that must be performed after the item
785 * finishes downloading.
787 * Dequeues the item and checks the resulting file's hashsums
788 * against ExpectedHashes after the last patch was applied.
789 * There is no need to check the md5/sha1 after a "normal"
790 * patch because QueueNextDiff() will check the sha1 later.
792 * \param allDone If \b true, the file was entirely reconstructed,
793 * and its md5sum is verified.
795 APT_HIDDEN
void Finish(bool const allDone
=false);
799 /** \brief If \b true, debugging output will be written to
804 /** A description of the file being downloaded. */
805 std::string Description
;
807 /** The patches that remain to be downloaded, including the patch
808 * being downloaded right now. This list should be ordered so
809 * that each diff appears before any diff that depends on it.
811 * \todo These are indexed by sha1sum; why not use some sort of
812 * dictionary instead of relying on ordering and stripping them
815 std::vector
<DiffInfo
> available_patches
;
817 /** The current status of this patch. */
820 /** \brief The diff is in an unknown state. */
823 /** \brief The diff is currently being fetched. */
826 /** \brief The diff is currently being applied. */
832 /** \brief Called when the patch file failed to be downloaded.
834 * This method will fall back to downloading the whole index file
835 * outright; its arguments are ignored.
837 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
839 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
840 pkgAcquire::MethodConfig
const * const Cnf
);
841 virtual std::string
Custom600Headers() const;
842 virtual std::string
DescURI() const {return Target
.URI
+ "IndexDiffs";};
843 virtual HashStringList
GetExpectedHashes() const;
844 virtual bool HashesRequired() const;
846 /** \brief Create an index diff item.
848 * After filling in its basic fields, this invokes Finish(true) if
849 * \a diffs is empty, or QueueNextDiff() otherwise.
851 * \param Owner The pkgAcquire object that owns this item.
853 * \param URI The URI of the package index file being
856 * \param URIDesc A long description of this item.
858 * \param ShortDesc A brief description of this item.
860 * \param diffs The remaining diffs from the index of diffs. They
861 * should be ordered so that each diff appears before any diff
862 * that depends on it.
864 pkgAcqIndexDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
865 IndexTarget
const Target
,
866 std::vector
<DiffInfo
> const &diffs
=std::vector
<DiffInfo
>());
869 /** \brief An acquire item that is responsible for fetching an index {{{
870 * file (e.g., Packages or Sources).
872 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
874 * \todo Why does pkgAcqIndex have protected members?
876 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
882 /** \brief The stages the method goes through
884 * The method first downloads the indexfile, then its decompressed (or
885 * copied) and verified
889 STAGE_DECOMPRESS_AND_VERIFY
,
893 /** \brief Handle what needs to be done when the download is done */
894 void StageDownloadDone(std::string
const &Message
,
895 HashStringList
const &Hashes
,
896 pkgAcquire::MethodConfig
const * const Cfg
);
898 /** \brief Handle what needs to be done when the decompression/copy is
901 void StageDecompressDone(std::string
const &Message
,
902 HashStringList
const &Hashes
,
903 pkgAcquire::MethodConfig
const * const Cfg
);
905 /** \brief If \b set, this partially downloaded file will be
906 * removed when the download completes.
908 std::string EraseFileName
;
910 /** \brief The compression-related file extensions that are being
911 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
913 std::string CompressionExtensions
;
915 /** \brief The actual compression extension currently used */
916 std::string CurrentCompressionExtension
;
918 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
919 void InitByHashIfNeeded();
921 /** \brief Auto select the right compression to use */
922 void AutoSelectCompression();
924 /** \brief Schedule file for verification after a IMS hit */
925 void ReverifyAfterIMS();
927 /** \brief Get the full pathname of the final file for the current URI */
928 virtual std::string
GetFinalFilename() const;
930 virtual bool TransactionState(TransactionStates
const state
);
933 // Specialized action members
934 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
935 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
936 pkgAcquire::MethodConfig
const * const Cnf
);
937 virtual std::string
Custom600Headers() const;
938 virtual std::string
DescURI() const {return Desc
.URI
;};
939 virtual std::string
GetMetaKey() const;
941 pkgAcqIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
942 IndexTarget
const Target
);
944 void Init(std::string
const &URI
, std::string
const &URIDesc
,
945 std::string
const &ShortDesc
);
948 /** \brief An item that is responsible for fetching a package file. {{{
950 * If the package file already exists in the cache, nothing will be
953 class pkgAcqArchive
: public pkgAcquire::Item
958 HashStringList ExpectedHashes
;
961 /** \brief The package version being fetched. */
962 pkgCache::VerIterator Version
;
964 /** \brief The list of sources from which to pick archives to
965 * download this package from.
967 pkgSourceList
*Sources
;
969 /** \brief A package records object, used to look up the file
970 * corresponding to each version of the package.
974 /** \brief A location in which the actual filename of the package
977 std::string
&StoreFilename
;
979 /** \brief The next file for this version to try to download. */
980 pkgCache::VerFileIterator Vf
;
982 /** \brief How many (more) times to try to find a new source from
983 * which to download this package version if it fails.
985 * Set from Acquire::Retries.
987 unsigned int Retries
;
989 /** \brief \b true if this version file is being downloaded from a
994 /** \brief Queue up the next available file for this version. */
997 /** \brief Get the full pathname of the final file for the current URI */
998 virtual std::string
GetFinalFilename() const;
1002 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1003 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
1004 pkgAcquire::MethodConfig
const * const Cnf
);
1005 virtual std::string
DescURI() const;
1006 virtual std::string
ShortDesc() const;
1007 virtual void Finished();
1008 virtual bool IsTrusted() const;
1009 virtual HashStringList
GetExpectedHashes() const;
1010 virtual bool HashesRequired() const;
1012 /** \brief Create a new pkgAcqArchive.
1014 * \param Owner The pkgAcquire object with which this item is
1017 * \param Sources The sources from which to download version
1020 * \param Recs A package records object, used to look up the file
1021 * corresponding to each version of the package.
1023 * \param Version The package version to download.
1025 * \param[out] StoreFilename A location in which the actual filename of
1026 * the package should be stored. It will be set to a guessed
1027 * basename in the constructor, and filled in with a fully
1028 * qualified filename once the download finishes.
1030 pkgAcqArchive(pkgAcquire
* const Owner
,pkgSourceList
* const Sources
,
1031 pkgRecords
* const Recs
,pkgCache::VerIterator
const &Version
,
1032 std::string
&StoreFilename
);
1035 /** \brief Retrieve the changelog for the given version {{{
1037 * Downloads the changelog to a temporary file it will also remove again
1038 * while it is deconstructed or downloads it to a named location.
1040 class pkgAcqChangelog
: public pkgAcquire::Item
1043 std::string TemporaryDirectory
;
1044 std::string
const SrcName
;
1045 std::string
const SrcVersion
;
1048 // we will never have hashes for changelogs.
1049 // If you need verified ones, download the deb and extract the changelog.
1050 virtual HashStringList
GetExpectedHashes() const { return HashStringList(); }
1051 virtual bool HashesRequired() const { return false; }
1053 // Specialized action members
1054 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1055 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1056 pkgAcquire::MethodConfig
const * const Cnf
);
1057 virtual std::string
DescURI() const {return Desc
.URI
;};
1059 /** returns the URI to the changelog of this version
1061 * @param Ver is the version to get the changelog for
1062 * @return the URI which will be used to acquire the changelog
1064 static std::string
URI(pkgCache::VerIterator
const &Ver
);
1066 /** returns the URI to the changelog of this version
1068 * \param Rls is the Release file the package comes from
1069 * \param Component in which the package resides, can be empty
1070 * \param SrcName is the source package name
1071 * \param SrcVersion is the source package version
1072 * @return the URI which will be used to acquire the changelog
1074 static std::string
URI(pkgCache::RlsFileIterator
const &Rls
,
1075 char const * const Component
, char const * const SrcName
,
1076 char const * const SrcVersion
);
1078 /** returns the URI to the changelog of this version
1080 * \param Template URI where CHANGEPATH has to be filled in
1081 * \param Component in which the package resides, can be empty
1082 * \param SrcName is the source package name
1083 * \param SrcVersion is the source package version
1084 * @return the URI which will be used to acquire the changelog
1086 static std::string
URI(std::string
const &Template
,
1087 char const * const Component
, char const * const SrcName
,
1088 char const * const SrcVersion
);
1090 /** returns the URI template for this release file
1092 * \param Rls is a Release file
1093 * @return the URI template to use for this release file
1095 static std::string
URITemplate(pkgCache::RlsFileIterator
const &Rls
);
1097 /** \brief Create a new pkgAcqChangelog object.
1099 * \param Owner The pkgAcquire object with which this object is
1101 * \param Ver is the version to get the changelog for
1102 * \param DestDir The directory the file should be downloaded into.
1103 * Will be an autocreated (and cleaned up) temporary directory if not set.
1104 * \param DestFilename The filename the file should have in #DestDir
1105 * Defaults to sourcepackagename.changelog if not set.
1107 pkgAcqChangelog(pkgAcquire
* const Owner
, pkgCache::VerIterator
const &Ver
,
1108 std::string
const &DestDir
="", std::string
const &DestFilename
="");
1110 /** \brief Create a new pkgAcqChangelog object.
1112 * \param Owner The pkgAcquire object with which this object is
1114 * \param Rls is the Release file the package comes from
1115 * \param Component in which the package resides, can be empty
1116 * \param SrcName is the source package name
1117 * \param SrcVersion is the source package version
1118 * \param DestDir The directory the file should be downloaded into.
1119 * Will be an autocreated (and cleaned up) temporary directory if not set.
1120 * \param DestFilename The filename the file should have in #DestDir
1121 * Defaults to sourcepackagename.changelog if not set.
1123 pkgAcqChangelog(pkgAcquire
* const Owner
, pkgCache::RlsFileIterator
const &Rls
,
1124 char const * const Component
, char const * const SrcName
, char const * const SrcVersion
,
1125 std::string
const &DestDir
="", std::string
const &DestFilename
="");
1127 /** \brief Create a new pkgAcqChangelog object.
1129 * \param Owner The pkgAcquire object with which this object is
1131 * \param URI is to be used to get the changelog
1132 * \param SrcName is the source package name
1133 * \param SrcVersion is the source package version
1134 * \param DestDir The directory the file should be downloaded into.
1135 * Will be an autocreated (and cleaned up) temporary directory if not set.
1136 * \param DestFilename The filename the file should have in #DestDir
1137 * Defaults to sourcepackagename.changelog if not set.
1139 pkgAcqChangelog(pkgAcquire
* const Owner
, std::string
const &URI
,
1140 char const * const SrcName
, char const * const SrcVersion
,
1141 std::string
const &DestDir
="", std::string
const &DestFilename
="");
1143 virtual ~pkgAcqChangelog();
1146 APT_HIDDEN
void Init(std::string
const &DestDir
, std::string
const &DestFilename
);
1149 /** \brief Retrieve an arbitrary file to the current directory. {{{
1151 * The file is retrieved even if it is accessed via a URL type that
1152 * normally is a NOP, such as "file". If the download fails, the
1153 * partial file is renamed to get a ".FAILED" extension.
1155 class pkgAcqFile
: public pkgAcquire::Item
1159 /** \brief How many times to retry the download, set from
1162 unsigned int Retries
;
1164 /** \brief Should this file be considered a index file */
1167 HashStringList
const ExpectedHashes
;
1169 virtual HashStringList
GetExpectedHashes() const;
1170 virtual bool HashesRequired() const;
1172 // Specialized action members
1173 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1174 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1175 pkgAcquire::MethodConfig
const * const Cnf
);
1176 virtual std::string
DescURI() const {return Desc
.URI
;};
1177 virtual std::string
Custom600Headers() const;
1179 /** \brief Create a new pkgAcqFile object.
1181 * \param Owner The pkgAcquire object with which this object is
1184 * \param URI The URI to download.
1186 * \param Hashes The hashsums of the file to download, if they are known;
1187 * otherwise empty list.
1189 * \param Size The size of the file to download, if it is known;
1192 * \param Desc A description of the file being downloaded.
1194 * \param ShortDesc A brief description of the file being
1197 * \param DestDir The directory the file should be downloaded into.
1199 * \param DestFilename The filename+path the file is downloaded to.
1201 * \param IsIndexFile The file is considered a IndexFile and cache-control
1202 * headers like "cache-control: max-age=0" are send
1204 * If DestFilename is empty, download to DestDir/\<basename\> if
1205 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1206 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1207 * is the absolute name to which the file should be downloaded.
1210 pkgAcqFile(pkgAcquire
* const Owner
, std::string
const &URI
, HashStringList
const &Hashes
, unsigned long long const Size
,
1211 std::string
const &Desc
, std::string
const &ShortDesc
,
1212 std::string
const &DestDir
="", std::string
const &DestFilename
="",
1213 bool const IsIndexFile
=false);