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/hashes.h>
25 #include <apt-pkg/weakptr.h>
26 #include <apt-pkg/pkgcache.h>
27 #include <apt-pkg/cacheiterators.h>
33 #ifndef APT_8_CLEANER_HEADERS
34 #include <apt-pkg/indexfile.h>
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
53 class IndexTarget
/*{{{*/
54 /** \brief Information about an index file. */
57 /** \brief A URI from which the index file can be downloaded. */
60 /** \brief A description of the index file. */
61 std::string Description
;
63 /** \brief A shorter description of the index file. */
64 std::string ShortDesc
;
66 /** \brief The key by which this index file should be
67 looked up within the meta index file. */
70 /** \brief Is it okay if the file isn't found in the meta index */
73 /** \brief Target specific options defined by the implementation */
74 std::map
<std::string
, std::string
> Options
;
76 IndexTarget(std::string
const &MetaKey
, std::string
const &ShortDesc
,
77 std::string
const &LongDesc
, std::string
const &URI
, bool const IsOptional
,
78 std::map
<std::string
, std::string
> const &Options
);
81 class pkgAcquire::Item
: public WeakPointable
/*{{{*/
82 /** \brief Represents the process by which a pkgAcquire object should
83 * retrieve a file or a collection of files.
85 * By convention, Item subclasses should insert themselves into the
86 * acquire queue when they are created by calling QueueURI(), and
87 * remove themselves by calling Dequeue() when either Done() or
88 * Failed() is invoked. Item objects are also responsible for
89 * notifying the download progress indicator (accessible via
90 * #Owner->Log) of their status.
97 /** \brief The current status of this item. */
100 /** \brief The item is waiting to be downloaded. */
103 /** \brief The item is currently being downloaded. */
106 /** \brief The item has been successfully downloaded. */
109 /** \brief An error was encountered while downloading this
114 /** \brief The item was downloaded but its authenticity could
119 /** \brief The item was could not be downloaded because of
120 * a transient network error (e.g. network down)
122 StatTransientNetworkError
,
125 /** \brief Contains a textual description of the error encountered
126 * if #ItemState is #StatError or #StatAuthError.
128 std::string ErrorText
;
130 /** \brief The size of the object to fetch. */
131 unsigned long long FileSize
;
133 /** \brief How much of the object was already fetched. */
134 unsigned long long PartialSize
;
136 /** \brief If not \b NULL, contains the name of a subprocess that
137 * is operating on this object (for instance, "gzip" or "gpgv").
139 APT_DEPRECATED
const char *Mode
;
141 /** \brief contains the name of the subprocess that is operating on this object
142 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
143 * as it can manage the lifetime of included string properly. */
144 std::string ActiveSubprocess
;
146 /** \brief A client-supplied unique identifier.
148 * This field is initalized to 0; it is meant to be filled in by
149 * clients that wish to use it to uniquely identify items.
151 * APT progress reporting will store an ID there as shown in "Get:42 …"
155 /** \brief If \b true, the entire object has been successfully fetched.
157 * Subclasses should set this to \b true when appropriate.
161 /** \brief If \b true, the URI of this object is "local".
163 * The only effect of this field is to exclude the object from the
164 * download progress indicator's overall statistics.
168 std::string UsedMirror
;
170 /** \brief The number of fetch queues into which this item has been
173 * There is one queue for each source from which an item could be
178 unsigned int QueueCounter
;
180 /** \brief The number of additional fetch items that are expected
181 * once this item is done.
183 * Some items like pkgAcqMeta{Index,Sig} will queue additional
184 * items. This variable can be set by the methods if it knows
185 * in advance how many items to expect to get a more accurate
188 unsigned int ExpectedAdditionalItems
;
190 /** \brief The name of the file into which the retrieved object
193 std::string DestFile
;
195 /** \brief Invoked by the acquire worker when the object couldn't
198 * This is a branch of the continuation of the fetch process.
200 * \param Message An RFC822-formatted message from the acquire
201 * method describing what went wrong. Use LookupTag() to parse
204 * \param Cnf The method via which the worker tried to fetch this object.
208 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
210 /** \brief Invoked by the acquire worker when the object was
211 * fetched successfully.
213 * Note that the object might \e not have been written to
214 * DestFile; check for the presence of an Alt-Filename entry in
215 * Message to find the file to which it was really written.
217 * Done is often used to switch from one stage of the processing
218 * to the next (e.g. fetching, unpacking, copying). It is one
219 * branch of the continuation of the fetch process.
221 * \param Message Data from the acquire method. Use LookupTag()
223 * \param Hashes The HashSums of the object that was fetched.
224 * \param Cnf The method via which the object was fetched.
228 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
229 pkgAcquire::MethodConfig
const * const Cnf
);
231 /** \brief Invoked when the worker starts to fetch this object.
233 * \param Message RFC822-formatted data from the worker process.
234 * Use LookupTag() to parse it.
236 * \param Hashes The expected hashes of the object being fetched.
240 virtual void Start(std::string
const &Message
, unsigned long long const Size
);
242 /** \brief Custom headers to be sent to the fetch process.
244 * \return a string containing RFC822-style headers that are to be
245 * inserted into the 600 URI Acquire message sent to the fetch
246 * subprocess. The headers are inserted after a newline-less
247 * line, so they should (if nonempty) have a leading newline and
248 * no trailing newline.
250 virtual std::string
Custom600Headers() const;
252 /** \brief A "descriptive" URI-like string.
254 * \return a URI that should be used to describe what is being fetched.
256 virtual std::string
DescURI() const = 0;
257 /** \brief Short item description.
259 * \return a brief description of the object being fetched.
261 virtual std::string
ShortDesc() const;
263 /** \brief Invoked by the worker when the download is completely done. */
264 virtual void Finished();
266 /** \return HashSums the DestFile is supposed to have in this stage */
267 virtual HashStringList
GetExpectedHashes() const = 0;
268 /** \return the 'best' hash for display proposes like --print-uris */
269 std::string
HashSum() const;
271 /** \return if having no hashes is a hard failure or not
273 * Idealy this is always \b true for every subclass, but thanks to
274 * historical grow we don't have hashes for all files in all cases
275 * in all steps, so it is slightly more complicated than it should be.
277 virtual bool HashesRequired() const { return true; }
279 /** \return the acquire process with which this item is associated. */
280 pkgAcquire
*GetOwner() const;
282 /** \return \b true if this object is being fetched from a trusted source. */
283 virtual bool IsTrusted() const;
285 /** \brief Report mirror problem
287 * This allows reporting mirror failures back to a centralized
288 * server. The apt-report-mirror-failure script is called for this
290 * \param FailCode A short failure string that is send
292 void ReportMirrorFailure(std::string
const &FailCode
);
294 /** \brief Set the name of the current active subprocess
296 * See also #ActiveSubprocess
298 void SetActiveSubprocess(std::string
const &subprocess
);
300 /** \brief Initialize an item.
302 * Adds the item to the list of items known to the acquire
303 * process, but does not place it into any fetch queues (you must
304 * manually invoke QueueURI() to do so).
306 * \param Owner The new owner of this item.
308 Item(pkgAcquire
* const Owner
);
310 /** \brief Remove this item from its owner's queue by invoking
311 * pkgAcquire::Remove.
316 /** \brief The acquire object with which this item is associated. */
317 pkgAcquire
* const Owner
;
319 /** \brief The item that is currently being downloaded. */
320 pkgAcquire::ItemDesc Desc
;
322 enum RenameOnErrorState
{
332 /** \brief Rename failed file and set error
334 * \param state respresenting the error we encountered
336 bool RenameOnError(RenameOnErrorState
const state
);
338 /** \brief Insert this item into its owner's queue.
340 * The method is designed to check if the request would end
341 * in an IMSHit and if it determines that it would, it isn't
342 * queueing the Item and instead sets it to completion instantly.
344 * \param Item Metadata about this item (its URI and
346 * \return true if the item was inserted, false if IMSHit was detected
348 virtual bool QueueURI(ItemDesc
&Item
);
350 /** \brief Remove this item from its owner's queue. */
353 /** \brief Rename a file without modifying its timestamp.
355 * Many item methods call this as their final action.
357 * \param From The file to be renamed.
359 * \param To The new name of \a From. If \a To exists it will be
360 * overwritten. If \a From and \a To are equal nothing happens.
362 bool Rename(std::string
const &From
, std::string
const &To
);
364 /** \brief Get the full pathname of the final file for the current URI */
365 virtual std::string
GetFinalFilename() const;
370 friend class pkgAcqMetaBase
;
373 class APT_HIDDEN pkgAcqTransactionItem
: public pkgAcquire::Item
/*{{{*/
374 /** \brief baseclass for the indexes files to manage them all together */
377 IndexTarget
const Target
;
378 HashStringList
GetExpectedHashesFor(std::string
const MetaKey
) const;
380 bool QueueURI(pkgAcquire::ItemDesc
&Item
);
383 /** \brief storge name until a transaction is finished */
384 std::string PartialFile
;
386 /** \brief TransactionManager */
387 pkgAcqMetaBase
* const TransactionManager
;
389 enum TransactionStates
{
393 virtual bool TransactionState(TransactionStates
const state
);
395 virtual std::string
DescURI() const { return Target
.URI
; }
396 virtual HashStringList
GetExpectedHashes() const;
397 virtual std::string
GetMetaKey() const;
398 virtual bool HashesRequired() const;
401 pkgAcqTransactionItem(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
);
402 virtual ~pkgAcqTransactionItem();
404 friend class pkgAcqMetaBase
;
407 class APT_HIDDEN pkgAcqMetaBase
: public pkgAcqTransactionItem
/*{{{*/
408 /** \brief the manager of a transaction */
413 std::vector
<pkgAcqTransactionItem
*> Transaction
;
416 /** \brief A package-system-specific parser for the meta-index file. */
417 indexRecords
*MetaIndexParser
;
418 indexRecords
*LastMetaIndexParser
;
421 /** \brief The index files which should be looked up in the meta-index
422 * and then downloaded.
424 std::vector
<IndexTarget
> const IndexTargets
;
426 /** \brief If \b true, the index's signature is currently being verified.
430 /** \brief Starts downloading the individual index files.
432 * \param verify If \b true, only indices whose expected hashsum
433 * can be determined from the meta-index will be downloaded, and
434 * the hashsums of indices will be checked (reporting
435 * #StatAuthError if there is a mismatch). If verify is \b false,
436 * no hashsum checking will be performed.
438 void QueueIndexes(bool const verify
);
440 /** \brief Called when a file is finished being retrieved.
442 * If the file was not downloaded to DestFile, a copy process is
443 * set up to copy it to DestFile; otherwise, Complete is set to \b
444 * true and the file is moved to its final location.
446 * \param Message The message block received from the fetch
449 bool CheckDownloadDone(pkgAcqTransactionItem
* const I
, const std::string
&Message
, HashStringList
const &Hashes
) const;
451 /** \brief Queue the downloaded Signature for verification */
452 void QueueForSignatureVerify(pkgAcqTransactionItem
* const I
, std::string
const &File
, std::string
const &Signature
);
454 virtual std::string
Custom600Headers() const;
456 /** \brief Called when authentication succeeded.
458 * Sanity-checks the authenticated file, queues up the individual
459 * index files for download, and saves the signature in the lists
460 * directory next to the authenticated list file.
462 * \param Message The message block received from the fetch
465 bool CheckAuthDone(std::string
const &Message
);
467 /** Check if the current item should fail at this point */
468 bool CheckStopAuthentication(pkgAcquire::Item
* const I
, const std::string
&Message
);
470 /** \brief Check that the release file is a release file for the
471 * correct distribution.
473 * \return \b true if no fatal errors were encountered.
475 bool VerifyVendor(std::string
const &Message
);
477 virtual bool TransactionState(TransactionStates
const state
);
480 // This refers more to the Transaction-Manager than the actual file
483 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
484 virtual HashStringList
GetExpectedHashes() const;
485 virtual bool HashesRequired() const;
488 void Add(pkgAcqTransactionItem
* const I
);
489 void AbortTransaction();
490 bool TransactionHasError() const;
491 void CommitTransaction();
493 /** \brief Stage (queue) a copy action when the transaction is committed
495 void TransactionStageCopy(pkgAcqTransactionItem
* const I
,
496 const std::string
&From
,
497 const std::string
&To
);
498 /** \brief Stage (queue) a removal action when the transaction is committed
500 void TransactionStageRemoval(pkgAcqTransactionItem
* const I
, const std::string
&FinalFile
);
502 /** \brief Get the full pathname of the final file for the current URI */
503 virtual std::string
GetFinalFilename() const;
505 pkgAcqMetaBase(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
506 std::vector
<IndexTarget
> const IndexTargets
,
507 IndexTarget
const &DataTarget
,
508 indexRecords
* const MetaIndexParser
);
511 /** \brief An item that is responsible for downloading the meta-index {{{
512 * file (i.e., Release) itself and verifying its signature.
514 * Once the download and verification are complete, the downloads of
515 * the individual index files are queued up using pkgAcqDiffIndex.
516 * If the meta-index file had a valid signature, the expected hashsums
517 * of the index files will be the md5sums listed in the meta-index;
518 * otherwise, the expected hashsums will be "" (causing the
519 * authentication of the index files to be bypassed).
521 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
526 IndexTarget
const DetachedSigTarget
;
528 /** \brief delayed constructor */
529 void Init(std::string
const &URIDesc
, std::string
const &ShortDesc
);
532 virtual std::string
DescURI() const;
534 // Specialized action members
535 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
536 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
537 pkgAcquire::MethodConfig
const * const Cnf
);
538 virtual void Finished();
540 /** \brief Create a new pkgAcqMetaIndex. */
541 pkgAcqMetaIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
542 IndexTarget
const &DataTarget
, IndexTarget
const &DetachedSigTarget
,
543 std::vector
<IndexTarget
> const IndexTargets
, indexRecords
* const MetaIndexParser
);
545 friend class pkgAcqMetaSig
;
548 /** \brief An acquire item that downloads the detached signature {{{
549 * of a meta-index (Release) file, then queues up the release
552 * \todo Why protected members?
554 * \sa pkgAcqMetaIndex
556 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqTransactionItem
560 pkgAcqMetaIndex
* const MetaIndex
;
562 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
563 std::string MetaIndexFileSignature
;
567 /** \brief Get the full pathname of the final file for the current URI */
568 virtual std::string
GetFinalFilename() const;
571 virtual bool HashesRequired() const { return false; }
573 // Specialized action members
574 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
575 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
576 pkgAcquire::MethodConfig
const * const Cnf
);
578 /** \brief Create a new pkgAcqMetaSig. */
579 pkgAcqMetaSig(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
,
580 pkgAcqMetaIndex
* const MetaIndex
);
581 virtual ~pkgAcqMetaSig();
584 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
585 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
589 IndexTarget
const ClearsignedTarget
;
590 IndexTarget
const DetachedDataTarget
;
591 IndexTarget
const DetachedSigTarget
;
594 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
595 virtual std::string
Custom600Headers() const;
596 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
597 pkgAcquire::MethodConfig
const * const Cnf
);
599 /** \brief Create a new pkgAcqMetaClearSig. */
600 pkgAcqMetaClearSig(pkgAcquire
* const Owner
,
601 IndexTarget
const &ClearsignedTarget
,
602 IndexTarget
const &DetachedDataTarget
,
603 IndexTarget
const &DetachedSigTarget
,
604 std::vector
<IndexTarget
> const IndexTargets
,
605 indexRecords
* const MetaIndexParser
);
606 virtual ~pkgAcqMetaClearSig();
609 /** \brief Common base class for all classes that deal with fetching indexes {{{*/
610 class APT_HIDDEN pkgAcqBaseIndex
: public pkgAcqTransactionItem
615 /** \brief Get the full pathname of the final file for the current URI */
616 virtual std::string
GetFinalFilename() const;
618 pkgAcqBaseIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
619 IndexTarget
const Target
);
622 /** \brief An item that is responsible for fetching an index file of {{{
623 * package list diffs and starting the package list's download.
625 * This item downloads the Index file and parses it, then enqueues
626 * additional downloads of either the individual patches (using
627 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
629 * \sa pkgAcqIndexDiffs, pkgAcqIndex
631 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
636 /** \brief If \b true, debugging information will be written to std::clog. */
639 /** \brief A description of the Packages file (stored in
640 * pkgAcquire::ItemDesc::Description).
642 std::string Description
;
644 /** \brief Get the full pathname of the final file for the current URI */
645 virtual std::string
GetFinalFilename() const;
647 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
649 virtual bool TransactionState(TransactionStates
const state
);
651 // Specialized action members
652 virtual void Failed(std::string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
);
653 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
654 pkgAcquire::MethodConfig
const * const Cnf
);
655 virtual std::string
DescURI() const {return Target
.URI
+ "Index";};
656 virtual std::string
Custom600Headers() const;
657 virtual std::string
GetMetaKey() const;
659 /** \brief Parse the Index file for a set of Packages diffs.
661 * Parses the Index file and creates additional download items as
664 * \param IndexDiffFile The name of the Index file.
666 * \return \b true if the Index file was successfully parsed, \b
669 bool ParseDiffIndex(std::string
const &IndexDiffFile
);
671 /** \brief Create a new pkgAcqDiffIndex.
673 * \param Owner The Acquire object that owns this item.
675 * \param URI The URI of the list file to download.
677 * \param URIDesc A long description of the list file to download.
679 * \param ShortDesc A short description of the list file to download.
681 pkgAcqDiffIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
682 IndexTarget
const Target
);
684 APT_HIDDEN
void QueueOnIMSHit() const;
687 struct APT_HIDDEN DiffInfo
{ /*{{{*/
688 /** The filename of the diff. */
691 /** The hashes of the file after the diff is applied */
692 HashStringList result_hashes
;
694 /** The hashes of the diff */
695 HashStringList patch_hashes
;
697 /** The hashes of the compressed diff */
698 HashStringList download_hashes
;
701 /** \brief An item that is responsible for fetching client-merge patches {{{
702 * that need to be applied to a given package index file.
704 * Instead of downloading and applying each patch one by one like its
705 * sister #pkgAcqIndexDiffs this class will download all patches at once
706 * and call rred with all the patches downloaded once. Rred will then
707 * merge and apply them in one go, which should be a lot faster – but is
708 * incompatible with server-based merges of patches like reprepro can do.
710 * \sa pkgAcqDiffIndex, pkgAcqIndex
712 class APT_HIDDEN pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
718 /** \brief If \b true, debugging output will be written to
723 /** \brief description of the file being downloaded. */
724 std::string Description
;
726 /** \brief information about the current patch */
727 struct DiffInfo
const patch
;
729 /** \brief list of all download items for the patches */
730 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
732 /** The current status of this patch. */
735 /** \brief The diff is currently being fetched. */
738 /** \brief The diff is currently being applied. */
741 /** \brief the work with this diff is done */
744 /** \brief something bad happened and fallback was triggered */
749 /** \brief Called when the patch file failed to be downloaded.
751 * This method will fall back to downloading the whole index file
752 * outright; its arguments are ignored.
754 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
755 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
756 pkgAcquire::MethodConfig
const * const Cnf
);
757 virtual std::string
Custom600Headers() const;
758 virtual std::string
DescURI() const {return Target
.URI
+ "Index";};
759 virtual HashStringList
GetExpectedHashes() const;
760 virtual bool HashesRequired() const;
762 /** \brief Create an index merge-diff item.
764 * \param Owner The pkgAcquire object that owns this item.
766 * \param URI The URI of the package index file being
769 * \param URIDesc A long description of this item.
771 * \param ShortDesc A brief description of this item.
773 * \param patch contains infos about the patch this item is supposed
774 * to download which were read from the index
776 * \param allPatches contains all related items so that each item can
777 * check if it was the last one to complete the download step
779 pkgAcqIndexMergeDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
780 IndexTarget
const Target
, DiffInfo
const &patch
,
781 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
784 /** \brief An item that is responsible for fetching server-merge patches {{{
785 * that need to be applied to a given package index file.
787 * After downloading and applying a single patch, this item will
788 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
789 * patches. If no patch can be found that applies to an intermediate
790 * file or if one of the patches cannot be downloaded, falls back to
791 * downloading the entire package index file using pkgAcqIndex.
793 * \sa pkgAcqDiffIndex, pkgAcqIndex
795 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
801 /** \brief Queue up the next diff download.
803 * Search for the next available diff that applies to the file
804 * that currently exists on disk, and enqueue it by calling
807 * \return \b true if an applicable diff was found, \b false
810 APT_HIDDEN
bool QueueNextDiff();
812 /** \brief Handle tasks that must be performed after the item
813 * finishes downloading.
815 * Dequeues the item and checks the resulting file's hashsums
816 * against ExpectedHashes after the last patch was applied.
817 * There is no need to check the md5/sha1 after a "normal"
818 * patch because QueueNextDiff() will check the sha1 later.
820 * \param allDone If \b true, the file was entirely reconstructed,
821 * and its md5sum is verified.
823 APT_HIDDEN
void Finish(bool const allDone
=false);
827 /** \brief If \b true, debugging output will be written to
832 /** A description of the file being downloaded. */
833 std::string Description
;
835 /** The patches that remain to be downloaded, including the patch
836 * being downloaded right now. This list should be ordered so
837 * that each diff appears before any diff that depends on it.
839 * \todo These are indexed by sha1sum; why not use some sort of
840 * dictionary instead of relying on ordering and stripping them
843 std::vector
<DiffInfo
> available_patches
;
845 /** The current status of this patch. */
848 /** \brief The diff is in an unknown state. */
851 /** \brief The diff is currently being fetched. */
854 /** \brief The diff is currently being applied. */
860 /** \brief Called when the patch file failed to be downloaded.
862 * This method will fall back to downloading the whole index file
863 * outright; its arguments are ignored.
865 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
867 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
868 pkgAcquire::MethodConfig
const * const Cnf
);
869 virtual std::string
Custom600Headers() const;
870 virtual std::string
DescURI() const {return Target
.URI
+ "IndexDiffs";};
871 virtual HashStringList
GetExpectedHashes() const;
872 virtual bool HashesRequired() const;
874 /** \brief Create an index diff item.
876 * After filling in its basic fields, this invokes Finish(true) if
877 * \a diffs is empty, or QueueNextDiff() otherwise.
879 * \param Owner The pkgAcquire object that owns this item.
881 * \param URI The URI of the package index file being
884 * \param URIDesc A long description of this item.
886 * \param ShortDesc A brief description of this item.
888 * \param diffs The remaining diffs from the index of diffs. They
889 * should be ordered so that each diff appears before any diff
890 * that depends on it.
892 pkgAcqIndexDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
893 IndexTarget
const Target
,
894 std::vector
<DiffInfo
> const &diffs
=std::vector
<DiffInfo
>());
897 /** \brief An acquire item that is responsible for fetching an index {{{
898 * file (e.g., Packages or Sources).
900 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
902 * \todo Why does pkgAcqIndex have protected members?
904 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
910 /** \brief The stages the method goes through
912 * The method first downloads the indexfile, then its decompressed (or
913 * copied) and verified
917 STAGE_DECOMPRESS_AND_VERIFY
,
921 /** \brief Handle what needs to be done when the download is done */
922 void StageDownloadDone(std::string
const &Message
,
923 HashStringList
const &Hashes
,
924 pkgAcquire::MethodConfig
const * const Cfg
);
926 /** \brief Handle what needs to be done when the decompression/copy is
929 void StageDecompressDone(std::string
const &Message
,
930 HashStringList
const &Hashes
,
931 pkgAcquire::MethodConfig
const * const Cfg
);
933 /** \brief If \b set, this partially downloaded file will be
934 * removed when the download completes.
936 std::string EraseFileName
;
938 /** \brief The compression-related file extensions that are being
939 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
941 std::string CompressionExtensions
;
943 /** \brief The actual compression extension currently used */
944 std::string CurrentCompressionExtension
;
946 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
947 void InitByHashIfNeeded();
949 /** \brief Auto select the right compression to use */
950 void AutoSelectCompression();
952 /** \brief Schedule file for verification after a IMS hit */
953 void ReverifyAfterIMS();
955 /** \brief Get the full pathname of the final file for the current URI */
956 virtual std::string
GetFinalFilename() const;
958 virtual bool TransactionState(TransactionStates
const state
);
961 // Specialized action members
962 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
963 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
964 pkgAcquire::MethodConfig
const * const Cnf
);
965 virtual std::string
Custom600Headers() const;
966 virtual std::string
DescURI() const {return Desc
.URI
;};
967 virtual std::string
GetMetaKey() const;
969 pkgAcqIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
970 IndexTarget
const Target
);
972 void Init(std::string
const &URI
, std::string
const &URIDesc
,
973 std::string
const &ShortDesc
);
976 /** \brief An item that is responsible for fetching a package file. {{{
978 * If the package file already exists in the cache, nothing will be
981 class pkgAcqArchive
: public pkgAcquire::Item
986 HashStringList ExpectedHashes
;
989 /** \brief The package version being fetched. */
990 pkgCache::VerIterator Version
;
992 /** \brief The list of sources from which to pick archives to
993 * download this package from.
995 pkgSourceList
*Sources
;
997 /** \brief A package records object, used to look up the file
998 * corresponding to each version of the package.
1002 /** \brief A location in which the actual filename of the package
1005 std::string
&StoreFilename
;
1007 /** \brief The next file for this version to try to download. */
1008 pkgCache::VerFileIterator Vf
;
1010 /** \brief How many (more) times to try to find a new source from
1011 * which to download this package version if it fails.
1013 * Set from Acquire::Retries.
1015 unsigned int Retries
;
1017 /** \brief \b true if this version file is being downloaded from a
1022 /** \brief Queue up the next available file for this version. */
1025 /** \brief Get the full pathname of the final file for the current URI */
1026 virtual std::string
GetFinalFilename() const;
1030 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1031 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
1032 pkgAcquire::MethodConfig
const * const Cnf
);
1033 virtual std::string
DescURI() const;
1034 virtual std::string
ShortDesc() const;
1035 virtual void Finished();
1036 virtual bool IsTrusted() const;
1037 virtual HashStringList
GetExpectedHashes() const;
1038 virtual bool HashesRequired() const;
1040 /** \brief Create a new pkgAcqArchive.
1042 * \param Owner The pkgAcquire object with which this item is
1045 * \param Sources The sources from which to download version
1048 * \param Recs A package records object, used to look up the file
1049 * corresponding to each version of the package.
1051 * \param Version The package version to download.
1053 * \param[out] StoreFilename A location in which the actual filename of
1054 * the package should be stored. It will be set to a guessed
1055 * basename in the constructor, and filled in with a fully
1056 * qualified filename once the download finishes.
1058 pkgAcqArchive(pkgAcquire
* const Owner
,pkgSourceList
* const Sources
,
1059 pkgRecords
* const Recs
,pkgCache::VerIterator
const &Version
,
1060 std::string
&StoreFilename
);
1063 /** \brief Retrieve an arbitrary file to the current directory. {{{
1065 * The file is retrieved even if it is accessed via a URL type that
1066 * normally is a NOP, such as "file". If the download fails, the
1067 * partial file is renamed to get a ".FAILED" extension.
1069 class pkgAcqFile
: public pkgAcquire::Item
1073 /** \brief How many times to retry the download, set from
1076 unsigned int Retries
;
1078 /** \brief Should this file be considered a index file */
1081 HashStringList
const ExpectedHashes
;
1083 virtual HashStringList
GetExpectedHashes() const;
1084 virtual bool HashesRequired() const;
1086 // Specialized action members
1087 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1088 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1089 pkgAcquire::MethodConfig
const * const Cnf
);
1090 virtual std::string
DescURI() const {return Desc
.URI
;};
1091 virtual std::string
Custom600Headers() const;
1093 /** \brief Create a new pkgAcqFile object.
1095 * \param Owner The pkgAcquire object with which this object is
1098 * \param URI The URI to download.
1100 * \param Hashes The hashsums of the file to download, if they are known;
1101 * otherwise empty list.
1103 * \param Size The size of the file to download, if it is known;
1106 * \param Desc A description of the file being downloaded.
1108 * \param ShortDesc A brief description of the file being
1111 * \param DestDir The directory the file should be downloaded into.
1113 * \param DestFilename The filename+path the file is downloaded to.
1115 * \param IsIndexFile The file is considered a IndexFile and cache-control
1116 * headers like "cache-control: max-age=0" are send
1118 * If DestFilename is empty, download to DestDir/\<basename\> if
1119 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1120 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1121 * is the absolute name to which the file should be downloaded.
1124 pkgAcqFile(pkgAcquire
* const Owner
, std::string
const &URI
, HashStringList
const &Hashes
, unsigned long long const Size
,
1125 std::string
const &Desc
, std::string
const &ShortDesc
,
1126 std::string
const &DestDir
="", std::string
const &DestFilename
="",
1127 bool const IsIndexFile
=false);