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;
253 /** \return \b true if this object is being fetched from a trusted source. */
254 virtual bool IsTrusted() const;
256 /** \brief Report mirror problem
258 * This allows reporting mirror failures back to a centralized
259 * server. The apt-report-mirror-failure script is called for this
261 * \param FailCode A short failure string that is send
263 void ReportMirrorFailure(std::string
const &FailCode
);
265 /** \brief Set the name of the current active subprocess
267 * See also #ActiveSubprocess
269 void SetActiveSubprocess(std::string
const &subprocess
);
271 /** \brief Initialize an item.
273 * Adds the item to the list of items known to the acquire
274 * process, but does not place it into any fetch queues (you must
275 * manually invoke QueueURI() to do so).
277 * \param Owner The new owner of this item.
279 Item(pkgAcquire
* const Owner
);
281 /** \brief Remove this item from its owner's queue by invoking
282 * pkgAcquire::Remove.
287 /** \brief The acquire object with which this item is associated. */
288 pkgAcquire
* const Owner
;
290 /** \brief The item that is currently being downloaded. */
291 pkgAcquire::ItemDesc Desc
;
293 enum RenameOnErrorState
{
303 /** \brief Rename failed file and set error
305 * \param state respresenting the error we encountered
307 bool RenameOnError(RenameOnErrorState
const state
);
309 /** \brief Insert this item into its owner's queue.
311 * The method is designed to check if the request would end
312 * in an IMSHit and if it determines that it would, it isn't
313 * queueing the Item and instead sets it to completion instantly.
315 * \param Item Metadata about this item (its URI and
317 * \return true if the item was inserted, false if IMSHit was detected
319 virtual bool QueueURI(ItemDesc
&Item
);
321 /** \brief Remove this item from its owner's queue. */
324 /** \brief Rename a file without modifying its timestamp.
326 * Many item methods call this as their final action.
328 * \param From The file to be renamed.
330 * \param To The new name of \a From. If \a To exists it will be
331 * overwritten. If \a From and \a To are equal nothing happens.
333 bool Rename(std::string
const &From
, std::string
const &To
);
335 /** \brief Get the full pathname of the final file for the current URI */
336 virtual std::string
GetFinalFilename() const;
341 friend class pkgAcqMetaBase
;
344 class APT_HIDDEN pkgAcqTransactionItem
: public pkgAcquire::Item
/*{{{*/
345 /** \brief baseclass for the indexes files to manage them all together */
348 IndexTarget
const Target
;
349 HashStringList
GetExpectedHashesFor(std::string
const MetaKey
) const;
351 bool QueueURI(pkgAcquire::ItemDesc
&Item
);
354 /** \brief storge name until a transaction is finished */
355 std::string PartialFile
;
357 /** \brief TransactionManager */
358 pkgAcqMetaBase
* const TransactionManager
;
360 enum TransactionStates
{
364 virtual bool TransactionState(TransactionStates
const state
);
366 virtual std::string
DescURI() const { return Target
.URI
; }
367 virtual HashStringList
GetExpectedHashes() const;
368 virtual std::string
GetMetaKey() const;
369 virtual bool HashesRequired() const;
372 pkgAcqTransactionItem(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
);
373 virtual ~pkgAcqTransactionItem();
375 friend class pkgAcqMetaBase
;
378 class APT_HIDDEN pkgAcqMetaBase
: public pkgAcqTransactionItem
/*{{{*/
379 /** \brief the manager of a transaction */
384 std::vector
<pkgAcqTransactionItem
*> Transaction
;
387 /** \brief A package-system-specific parser for the meta-index file. */
388 indexRecords
*MetaIndexParser
;
389 indexRecords
*LastMetaIndexParser
;
392 /** \brief The index files which should be looked up in the meta-index
393 * and then downloaded.
395 std::vector
<IndexTarget
> const IndexTargets
;
397 /** \brief If \b true, the index's signature is currently being verified.
401 /** \brief Starts downloading the individual index files.
403 * \param verify If \b true, only indices whose expected hashsum
404 * can be determined from the meta-index will be downloaded, and
405 * the hashsums of indices will be checked (reporting
406 * #StatAuthError if there is a mismatch). If verify is \b false,
407 * no hashsum checking will be performed.
409 void QueueIndexes(bool const verify
);
411 /** \brief Called when a file is finished being retrieved.
413 * If the file was not downloaded to DestFile, a copy process is
414 * set up to copy it to DestFile; otherwise, Complete is set to \b
415 * true and the file is moved to its final location.
417 * \param Message The message block received from the fetch
420 bool CheckDownloadDone(pkgAcqTransactionItem
* const I
, const std::string
&Message
, HashStringList
const &Hashes
) const;
422 /** \brief Queue the downloaded Signature for verification */
423 void QueueForSignatureVerify(pkgAcqTransactionItem
* const I
, std::string
const &File
, std::string
const &Signature
);
425 virtual std::string
Custom600Headers() const;
427 /** \brief Called when authentication succeeded.
429 * Sanity-checks the authenticated file, queues up the individual
430 * index files for download, and saves the signature in the lists
431 * directory next to the authenticated list file.
433 * \param Message The message block received from the fetch
436 bool CheckAuthDone(std::string
const &Message
);
438 /** Check if the current item should fail at this point */
439 bool CheckStopAuthentication(pkgAcquire::Item
* const I
, const std::string
&Message
);
441 /** \brief Check that the release file is a release file for the
442 * correct distribution.
444 * \return \b true if no fatal errors were encountered.
446 bool VerifyVendor(std::string
const &Message
);
448 virtual bool TransactionState(TransactionStates
const state
);
451 // This refers more to the Transaction-Manager than the actual file
454 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
455 virtual HashStringList
GetExpectedHashes() const;
456 virtual bool HashesRequired() const;
459 void Add(pkgAcqTransactionItem
* const I
);
460 void AbortTransaction();
461 bool TransactionHasError() const;
462 void CommitTransaction();
464 /** \brief Stage (queue) a copy action when the transaction is committed
466 void TransactionStageCopy(pkgAcqTransactionItem
* const I
,
467 const std::string
&From
,
468 const std::string
&To
);
469 /** \brief Stage (queue) a removal action when the transaction is committed
471 void TransactionStageRemoval(pkgAcqTransactionItem
* const I
, const std::string
&FinalFile
);
473 /** \brief Get the full pathname of the final file for the current URI */
474 virtual std::string
GetFinalFilename() const;
476 pkgAcqMetaBase(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
477 std::vector
<IndexTarget
> const IndexTargets
,
478 IndexTarget
const &DataTarget
,
479 indexRecords
* const MetaIndexParser
);
482 /** \brief An item that is responsible for downloading the meta-index {{{
483 * file (i.e., Release) itself and verifying its signature.
485 * Once the download and verification are complete, the downloads of
486 * the individual index files are queued up using pkgAcqDiffIndex.
487 * If the meta-index file had a valid signature, the expected hashsums
488 * of the index files will be the md5sums listed in the meta-index;
489 * otherwise, the expected hashsums will be "" (causing the
490 * authentication of the index files to be bypassed).
492 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
497 IndexTarget
const DetachedSigTarget
;
499 /** \brief delayed constructor */
500 void Init(std::string
const &URIDesc
, std::string
const &ShortDesc
);
503 virtual std::string
DescURI() const;
505 // Specialized action members
506 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
507 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
508 pkgAcquire::MethodConfig
const * const Cnf
);
509 virtual void Finished();
511 /** \brief Create a new pkgAcqMetaIndex. */
512 pkgAcqMetaIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
513 IndexTarget
const &DataTarget
, IndexTarget
const &DetachedSigTarget
,
514 std::vector
<IndexTarget
> const IndexTargets
, indexRecords
* const MetaIndexParser
);
516 friend class pkgAcqMetaSig
;
519 /** \brief An acquire item that downloads the detached signature {{{
520 * of a meta-index (Release) file, then queues up the release
523 * \todo Why protected members?
525 * \sa pkgAcqMetaIndex
527 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqTransactionItem
531 pkgAcqMetaIndex
* const MetaIndex
;
533 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
534 std::string MetaIndexFileSignature
;
538 /** \brief Get the full pathname of the final file for the current URI */
539 virtual std::string
GetFinalFilename() const;
542 virtual bool HashesRequired() const { return false; }
544 // Specialized action members
545 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
546 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
547 pkgAcquire::MethodConfig
const * const Cnf
);
549 /** \brief Create a new pkgAcqMetaSig. */
550 pkgAcqMetaSig(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
,
551 pkgAcqMetaIndex
* const MetaIndex
);
552 virtual ~pkgAcqMetaSig();
555 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
556 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
560 IndexTarget
const ClearsignedTarget
;
561 IndexTarget
const DetachedDataTarget
;
562 IndexTarget
const DetachedSigTarget
;
565 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
566 virtual std::string
Custom600Headers() const;
567 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
568 pkgAcquire::MethodConfig
const * const Cnf
);
570 /** \brief Create a new pkgAcqMetaClearSig. */
571 pkgAcqMetaClearSig(pkgAcquire
* const Owner
,
572 IndexTarget
const &ClearsignedTarget
,
573 IndexTarget
const &DetachedDataTarget
,
574 IndexTarget
const &DetachedSigTarget
,
575 std::vector
<IndexTarget
> const IndexTargets
,
576 indexRecords
* const MetaIndexParser
);
577 virtual ~pkgAcqMetaClearSig();
580 /** \brief Common base class for all classes that deal with fetching indexes {{{*/
581 class APT_HIDDEN pkgAcqBaseIndex
: public pkgAcqTransactionItem
586 /** \brief Get the full pathname of the final file for the current URI */
587 virtual std::string
GetFinalFilename() const;
589 pkgAcqBaseIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
590 IndexTarget
const Target
);
593 /** \brief An item that is responsible for fetching an index file of {{{
594 * package list diffs and starting the package list's download.
596 * This item downloads the Index file and parses it, then enqueues
597 * additional downloads of either the individual patches (using
598 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
600 * \sa pkgAcqIndexDiffs, pkgAcqIndex
602 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
607 /** \brief If \b true, debugging information will be written to std::clog. */
610 /** \brief A description of the Packages file (stored in
611 * pkgAcquire::ItemDesc::Description).
613 std::string Description
;
615 /** \brief Get the full pathname of the final file for the current URI */
616 virtual std::string
GetFinalFilename() const;
618 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
620 virtual bool TransactionState(TransactionStates
const state
);
622 // Specialized action members
623 virtual void Failed(std::string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
);
624 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
625 pkgAcquire::MethodConfig
const * const Cnf
);
626 virtual std::string
DescURI() const {return Target
.URI
+ "Index";};
627 virtual std::string
Custom600Headers() const;
628 virtual std::string
GetMetaKey() const;
630 /** \brief Parse the Index file for a set of Packages diffs.
632 * Parses the Index file and creates additional download items as
635 * \param IndexDiffFile The name of the Index file.
637 * \return \b true if the Index file was successfully parsed, \b
640 bool ParseDiffIndex(std::string
const &IndexDiffFile
);
642 /** \brief Create a new pkgAcqDiffIndex.
644 * \param Owner The Acquire object that owns this item.
646 * \param URI The URI of the list file to download.
648 * \param URIDesc A long description of the list file to download.
650 * \param ShortDesc A short description of the list file to download.
652 pkgAcqDiffIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
653 IndexTarget
const Target
);
655 APT_HIDDEN
void QueueOnIMSHit() const;
658 struct APT_HIDDEN DiffInfo
{ /*{{{*/
659 /** The filename of the diff. */
662 /** The hashes of the file after the diff is applied */
663 HashStringList result_hashes
;
665 /** The hashes of the diff */
666 HashStringList patch_hashes
;
668 /** The hashes of the compressed diff */
669 HashStringList download_hashes
;
672 /** \brief An item that is responsible for fetching client-merge patches {{{
673 * that need to be applied to a given package index file.
675 * Instead of downloading and applying each patch one by one like its
676 * sister #pkgAcqIndexDiffs this class will download all patches at once
677 * and call rred with all the patches downloaded once. Rred will then
678 * merge and apply them in one go, which should be a lot faster – but is
679 * incompatible with server-based merges of patches like reprepro can do.
681 * \sa pkgAcqDiffIndex, pkgAcqIndex
683 class APT_HIDDEN pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
689 /** \brief If \b true, debugging output will be written to
694 /** \brief description of the file being downloaded. */
695 std::string Description
;
697 /** \brief information about the current patch */
698 struct DiffInfo
const patch
;
700 /** \brief list of all download items for the patches */
701 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
703 /** The current status of this patch. */
706 /** \brief The diff is currently being fetched. */
709 /** \brief The diff is currently being applied. */
712 /** \brief the work with this diff is done */
715 /** \brief something bad happened and fallback was triggered */
720 /** \brief Called when the patch file failed to be downloaded.
722 * This method will fall back to downloading the whole index file
723 * outright; its arguments are ignored.
725 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
726 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
727 pkgAcquire::MethodConfig
const * const Cnf
);
728 virtual std::string
Custom600Headers() const;
729 virtual std::string
DescURI() const {return Target
.URI
+ "Index";};
730 virtual HashStringList
GetExpectedHashes() const;
731 virtual bool HashesRequired() const;
733 /** \brief Create an index merge-diff item.
735 * \param Owner The pkgAcquire object that owns this item.
737 * \param URI The URI of the package index file being
740 * \param URIDesc A long description of this item.
742 * \param ShortDesc A brief description of this item.
744 * \param patch contains infos about the patch this item is supposed
745 * to download which were read from the index
747 * \param allPatches contains all related items so that each item can
748 * check if it was the last one to complete the download step
750 pkgAcqIndexMergeDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
751 IndexTarget
const Target
, DiffInfo
const &patch
,
752 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
755 /** \brief An item that is responsible for fetching server-merge patches {{{
756 * that need to be applied to a given package index file.
758 * After downloading and applying a single patch, this item will
759 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
760 * patches. If no patch can be found that applies to an intermediate
761 * file or if one of the patches cannot be downloaded, falls back to
762 * downloading the entire package index file using pkgAcqIndex.
764 * \sa pkgAcqDiffIndex, pkgAcqIndex
766 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
772 /** \brief Queue up the next diff download.
774 * Search for the next available diff that applies to the file
775 * that currently exists on disk, and enqueue it by calling
778 * \return \b true if an applicable diff was found, \b false
781 APT_HIDDEN
bool QueueNextDiff();
783 /** \brief Handle tasks that must be performed after the item
784 * finishes downloading.
786 * Dequeues the item and checks the resulting file's hashsums
787 * against ExpectedHashes after the last patch was applied.
788 * There is no need to check the md5/sha1 after a "normal"
789 * patch because QueueNextDiff() will check the sha1 later.
791 * \param allDone If \b true, the file was entirely reconstructed,
792 * and its md5sum is verified.
794 APT_HIDDEN
void Finish(bool const allDone
=false);
798 /** \brief If \b true, debugging output will be written to
803 /** A description of the file being downloaded. */
804 std::string Description
;
806 /** The patches that remain to be downloaded, including the patch
807 * being downloaded right now. This list should be ordered so
808 * that each diff appears before any diff that depends on it.
810 * \todo These are indexed by sha1sum; why not use some sort of
811 * dictionary instead of relying on ordering and stripping them
814 std::vector
<DiffInfo
> available_patches
;
816 /** The current status of this patch. */
819 /** \brief The diff is in an unknown state. */
822 /** \brief The diff is currently being fetched. */
825 /** \brief The diff is currently being applied. */
831 /** \brief Called when the patch file failed to be downloaded.
833 * This method will fall back to downloading the whole index file
834 * outright; its arguments are ignored.
836 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
838 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
839 pkgAcquire::MethodConfig
const * const Cnf
);
840 virtual std::string
Custom600Headers() const;
841 virtual std::string
DescURI() const {return Target
.URI
+ "IndexDiffs";};
842 virtual HashStringList
GetExpectedHashes() const;
843 virtual bool HashesRequired() const;
845 /** \brief Create an index diff item.
847 * After filling in its basic fields, this invokes Finish(true) if
848 * \a diffs is empty, or QueueNextDiff() otherwise.
850 * \param Owner The pkgAcquire object that owns this item.
852 * \param URI The URI of the package index file being
855 * \param URIDesc A long description of this item.
857 * \param ShortDesc A brief description of this item.
859 * \param diffs The remaining diffs from the index of diffs. They
860 * should be ordered so that each diff appears before any diff
861 * that depends on it.
863 pkgAcqIndexDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
864 IndexTarget
const Target
,
865 std::vector
<DiffInfo
> const &diffs
=std::vector
<DiffInfo
>());
868 /** \brief An acquire item that is responsible for fetching an index {{{
869 * file (e.g., Packages or Sources).
871 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
873 * \todo Why does pkgAcqIndex have protected members?
875 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
881 /** \brief The stages the method goes through
883 * The method first downloads the indexfile, then its decompressed (or
884 * copied) and verified
888 STAGE_DECOMPRESS_AND_VERIFY
,
892 /** \brief Handle what needs to be done when the download is done */
893 void StageDownloadDone(std::string
const &Message
,
894 HashStringList
const &Hashes
,
895 pkgAcquire::MethodConfig
const * const Cfg
);
897 /** \brief Handle what needs to be done when the decompression/copy is
900 void StageDecompressDone(std::string
const &Message
,
901 HashStringList
const &Hashes
,
902 pkgAcquire::MethodConfig
const * const Cfg
);
904 /** \brief If \b set, this partially downloaded file will be
905 * removed when the download completes.
907 std::string EraseFileName
;
909 /** \brief The compression-related file extensions that are being
910 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
912 std::string CompressionExtensions
;
914 /** \brief The actual compression extension currently used */
915 std::string CurrentCompressionExtension
;
917 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
918 void InitByHashIfNeeded();
920 /** \brief Auto select the right compression to use */
921 void AutoSelectCompression();
923 /** \brief Schedule file for verification after a IMS hit */
924 void ReverifyAfterIMS();
926 /** \brief Get the full pathname of the final file for the current URI */
927 virtual std::string
GetFinalFilename() const;
929 virtual bool TransactionState(TransactionStates
const state
);
932 // Specialized action members
933 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
934 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
935 pkgAcquire::MethodConfig
const * const Cnf
);
936 virtual std::string
Custom600Headers() const;
937 virtual std::string
DescURI() const {return Desc
.URI
;};
938 virtual std::string
GetMetaKey() const;
940 pkgAcqIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
941 IndexTarget
const Target
);
943 void Init(std::string
const &URI
, std::string
const &URIDesc
,
944 std::string
const &ShortDesc
);
947 /** \brief An item that is responsible for fetching a package file. {{{
949 * If the package file already exists in the cache, nothing will be
952 class pkgAcqArchive
: public pkgAcquire::Item
957 HashStringList ExpectedHashes
;
960 /** \brief The package version being fetched. */
961 pkgCache::VerIterator Version
;
963 /** \brief The list of sources from which to pick archives to
964 * download this package from.
966 pkgSourceList
*Sources
;
968 /** \brief A package records object, used to look up the file
969 * corresponding to each version of the package.
973 /** \brief A location in which the actual filename of the package
976 std::string
&StoreFilename
;
978 /** \brief The next file for this version to try to download. */
979 pkgCache::VerFileIterator Vf
;
981 /** \brief How many (more) times to try to find a new source from
982 * which to download this package version if it fails.
984 * Set from Acquire::Retries.
986 unsigned int Retries
;
988 /** \brief \b true if this version file is being downloaded from a
993 /** \brief Queue up the next available file for this version. */
996 /** \brief Get the full pathname of the final file for the current URI */
997 virtual std::string
GetFinalFilename() const;
1001 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1002 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
1003 pkgAcquire::MethodConfig
const * const Cnf
);
1004 virtual std::string
DescURI() const;
1005 virtual std::string
ShortDesc() const;
1006 virtual void Finished();
1007 virtual bool IsTrusted() const;
1008 virtual HashStringList
GetExpectedHashes() const;
1009 virtual bool HashesRequired() const;
1011 /** \brief Create a new pkgAcqArchive.
1013 * \param Owner The pkgAcquire object with which this item is
1016 * \param Sources The sources from which to download version
1019 * \param Recs A package records object, used to look up the file
1020 * corresponding to each version of the package.
1022 * \param Version The package version to download.
1024 * \param[out] StoreFilename A location in which the actual filename of
1025 * the package should be stored. It will be set to a guessed
1026 * basename in the constructor, and filled in with a fully
1027 * qualified filename once the download finishes.
1029 pkgAcqArchive(pkgAcquire
* const Owner
,pkgSourceList
* const Sources
,
1030 pkgRecords
* const Recs
,pkgCache::VerIterator
const &Version
,
1031 std::string
&StoreFilename
);
1034 /** \brief Retrieve an arbitrary file to the current directory. {{{
1036 * The file is retrieved even if it is accessed via a URL type that
1037 * normally is a NOP, such as "file". If the download fails, the
1038 * partial file is renamed to get a ".FAILED" extension.
1040 class pkgAcqFile
: public pkgAcquire::Item
1044 /** \brief How many times to retry the download, set from
1047 unsigned int Retries
;
1049 /** \brief Should this file be considered a index file */
1052 HashStringList
const ExpectedHashes
;
1054 virtual HashStringList
GetExpectedHashes() const;
1055 virtual bool HashesRequired() const;
1057 // Specialized action members
1058 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1059 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1060 pkgAcquire::MethodConfig
const * const Cnf
);
1061 virtual std::string
DescURI() const {return Desc
.URI
;};
1062 virtual std::string
Custom600Headers() const;
1064 /** \brief Create a new pkgAcqFile object.
1066 * \param Owner The pkgAcquire object with which this object is
1069 * \param URI The URI to download.
1071 * \param Hashes The hashsums of the file to download, if they are known;
1072 * otherwise empty list.
1074 * \param Size The size of the file to download, if it is known;
1077 * \param Desc A description of the file being downloaded.
1079 * \param ShortDesc A brief description of the file being
1082 * \param DestDir The directory the file should be downloaded into.
1084 * \param DestFilename The filename+path the file is downloaded to.
1086 * \param IsIndexFile The file is considered a IndexFile and cache-control
1087 * headers like "cache-control: max-age=0" are send
1089 * If DestFilename is empty, download to DestDir/\<basename\> if
1090 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1091 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1092 * is the absolute name to which the file should be downloaded.
1095 pkgAcqFile(pkgAcquire
* const Owner
, std::string
const &URI
, HashStringList
const &Hashes
, unsigned long long const Size
,
1096 std::string
const &Desc
, std::string
const &ShortDesc
,
1097 std::string
const &DestDir
="", std::string
const &DestFilename
="",
1098 bool const IsIndexFile
=false);