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>
32 #ifndef APT_8_CLEANER_HEADERS
33 #include <apt-pkg/indexfile.h>
34 #include <apt-pkg/vendor.h>
35 #include <apt-pkg/sourcelist.h>
36 #include <apt-pkg/pkgrecords.h>
37 #include <apt-pkg/indexrecords.h>
40 /** \addtogroup acquire
43 * \file acquire-item.h
52 class APT_HIDDEN IndexTarget
/*{{{*/
53 /** \brief Information about an index file. */
56 /** \brief A URI from which the index file can be downloaded. */
57 std::string
const URI
;
59 /** \brief A description of the index file. */
60 std::string
const Description
;
62 /** \brief A shorter description of the index file. */
63 std::string
const ShortDesc
;
65 /** \brief The key by which this index file should be
66 * looked up within the meta signature file.
68 std::string
const MetaKey
;
70 virtual bool IsOptional() const {
74 IndexTarget(std::string
const &MetaKey
, std::string
const &ShortDesc
,
75 std::string
const &LongDesc
, std::string
const &URI
) :
76 URI(URI
), Description(LongDesc
), ShortDesc(ShortDesc
), MetaKey(MetaKey
) {}
79 class APT_HIDDEN OptionalIndexTarget
: public IndexTarget
/*{{{*/
80 /** \brief Information about an optional index file. */
83 virtual bool IsOptional() const {
87 OptionalIndexTarget(std::string
const &MetaKey
, std::string
const &ShortDesc
,
88 std::string
const &LongDesc
, std::string
const &URI
) :
89 IndexTarget(MetaKey
, ShortDesc
, LongDesc
, URI
) {}
92 class pkgAcquire::Item
: public WeakPointable
/*{{{*/
93 /** \brief Represents the process by which a pkgAcquire object should
94 * retrieve a file or a collection of files.
96 * By convention, Item subclasses should insert themselves into the
97 * acquire queue when they are created by calling QueueURI(), and
98 * remove themselves by calling Dequeue() when either Done() or
99 * Failed() is invoked. Item objects are also responsible for
100 * notifying the download progress indicator (accessible via
101 * #Owner->Log) of their status.
108 /** \brief The current status of this item. */
111 /** \brief The item is waiting to be downloaded. */
114 /** \brief The item is currently being downloaded. */
117 /** \brief The item has been successfully downloaded. */
120 /** \brief An error was encountered while downloading this
125 /** \brief The item was downloaded but its authenticity could
130 /** \brief The item was could not be downloaded because of
131 * a transient network error (e.g. network down)
133 StatTransientNetworkError
,
136 /** \brief Contains a textual description of the error encountered
137 * if #ItemState is #StatError or #StatAuthError.
139 std::string ErrorText
;
141 /** \brief The size of the object to fetch. */
142 unsigned long long FileSize
;
144 /** \brief How much of the object was already fetched. */
145 unsigned long long PartialSize
;
147 /** \brief If not \b NULL, contains the name of a subprocess that
148 * is operating on this object (for instance, "gzip" or "gpgv").
150 APT_DEPRECATED
const char *Mode
;
152 /** \brief contains the name of the subprocess that is operating on this object
153 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
154 * as it can manage the lifetime of included string properly. */
155 std::string ActiveSubprocess
;
157 /** \brief A client-supplied unique identifier.
159 * This field is initalized to 0; it is meant to be filled in by
160 * clients that wish to use it to uniquely identify items.
162 * APT progress reporting will store an ID there as shown in "Get:42 …"
166 /** \brief If \b true, the entire object has been successfully fetched.
168 * Subclasses should set this to \b true when appropriate.
172 /** \brief If \b true, the URI of this object is "local".
174 * The only effect of this field is to exclude the object from the
175 * download progress indicator's overall statistics.
179 std::string UsedMirror
;
181 /** \brief The number of fetch queues into which this item has been
184 * There is one queue for each source from which an item could be
189 unsigned int QueueCounter
;
191 /** \brief The number of additional fetch items that are expected
192 * once this item is done.
194 * Some items like pkgAcqMeta{Index,Sig} will queue additional
195 * items. This variable can be set by the methods if it knows
196 * in advance how many items to expect to get a more accurate
199 unsigned int ExpectedAdditionalItems
;
201 /** \brief The name of the file into which the retrieved object
204 std::string DestFile
;
206 /** \brief Invoked by the acquire worker when the object couldn't
209 * This is a branch of the continuation of the fetch process.
211 * \param Message An RFC822-formatted message from the acquire
212 * method describing what went wrong. Use LookupTag() to parse
215 * \param Cnf The method via which the worker tried to fetch this object.
219 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
221 /** \brief Invoked by the acquire worker when the object was
222 * fetched successfully.
224 * Note that the object might \e not have been written to
225 * DestFile; check for the presence of an Alt-Filename entry in
226 * Message to find the file to which it was really written.
228 * Done is often used to switch from one stage of the processing
229 * to the next (e.g. fetching, unpacking, copying). It is one
230 * branch of the continuation of the fetch process.
232 * \param Message Data from the acquire method. Use LookupTag()
234 * \param Hashes The HashSums of the object that was fetched.
235 * \param Cnf The method via which the object was fetched.
239 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
240 pkgAcquire::MethodConfig
const * const Cnf
);
242 /** \brief Invoked when the worker starts to fetch this object.
244 * \param Message RFC822-formatted data from the worker process.
245 * Use LookupTag() to parse it.
247 * \param Hashes The expected hashes of the object being fetched.
251 virtual void Start(std::string
const &Message
, unsigned long long const Size
);
253 /** \brief Custom headers to be sent to the fetch process.
255 * \return a string containing RFC822-style headers that are to be
256 * inserted into the 600 URI Acquire message sent to the fetch
257 * subprocess. The headers are inserted after a newline-less
258 * line, so they should (if nonempty) have a leading newline and
259 * no trailing newline.
261 virtual std::string
Custom600Headers() const;
263 /** \brief A "descriptive" URI-like string.
265 * \return a URI that should be used to describe what is being fetched.
267 virtual std::string
DescURI() const = 0;
268 /** \brief Short item description.
270 * \return a brief description of the object being fetched.
272 virtual std::string
ShortDesc() const;
274 /** \brief Invoked by the worker when the download is completely done. */
275 virtual void Finished();
277 /** \return HashSums the DestFile is supposed to have in this stage */
278 virtual HashStringList
GetExpectedHashes() const = 0;
279 /** \return the 'best' hash for display proposes like --print-uris */
280 std::string
HashSum() const;
282 /** \return if having no hashes is a hard failure or not
284 * Idealy this is always \b true for every subclass, but thanks to
285 * historical grow we don't have hashes for all files in all cases
286 * in all steps, so it is slightly more complicated than it should be.
288 virtual bool HashesRequired() const { return true; }
290 /** \return the acquire process with which this item is associated. */
291 pkgAcquire
*GetOwner() const;
293 /** \return \b true if this object is being fetched from a trusted source. */
294 virtual bool IsTrusted() const;
296 /** \brief Report mirror problem
298 * This allows reporting mirror failures back to a centralized
299 * server. The apt-report-mirror-failure script is called for this
301 * \param FailCode A short failure string that is send
303 void ReportMirrorFailure(std::string
const &FailCode
);
305 /** \brief Set the name of the current active subprocess
307 * See also #ActiveSubprocess
309 void SetActiveSubprocess(std::string
const &subprocess
);
311 /** \brief Initialize an item.
313 * Adds the item to the list of items known to the acquire
314 * process, but does not place it into any fetch queues (you must
315 * manually invoke QueueURI() to do so).
317 * \param Owner The new owner of this item.
319 Item(pkgAcquire
* const Owner
);
321 /** \brief Remove this item from its owner's queue by invoking
322 * pkgAcquire::Remove.
327 /** \brief The acquire object with which this item is associated. */
328 pkgAcquire
* const Owner
;
330 /** \brief The item that is currently being downloaded. */
331 pkgAcquire::ItemDesc Desc
;
333 enum RenameOnErrorState
{
343 /** \brief Rename failed file and set error
345 * \param state respresenting the error we encountered
347 bool RenameOnError(RenameOnErrorState
const state
);
349 /** \brief Insert this item into its owner's queue.
351 * The method is designed to check if the request would end
352 * in an IMSHit and if it determines that it would, it isn't
353 * queueing the Item and instead sets it to completion instantly.
355 * \param Item Metadata about this item (its URI and
357 * \return true if the item was inserted, false if IMSHit was detected
359 virtual bool QueueURI(ItemDesc
&Item
);
361 /** \brief Remove this item from its owner's queue. */
364 /** \brief Rename a file without modifying its timestamp.
366 * Many item methods call this as their final action.
368 * \param From The file to be renamed.
370 * \param To The new name of \a From. If \a To exists it will be
371 * overwritten. If \a From and \a To are equal nothing happens.
373 bool Rename(std::string
const &From
, std::string
const &To
);
375 /** \brief Get the full pathname of the final file for the current URI */
376 virtual std::string
GetFinalFilename() const;
381 friend class pkgAcqMetaBase
;
384 class APT_HIDDEN pkgAcqTransactionItem
: public pkgAcquire::Item
/*{{{*/
385 /** \brief baseclass for the indexes files to manage them all together */
388 IndexTarget
const * const Target
;
389 HashStringList
GetExpectedHashesFor(std::string
const MetaKey
) const;
391 bool QueueURI(pkgAcquire::ItemDesc
&Item
);
394 /** \brief storge name until a transaction is finished */
395 std::string PartialFile
;
397 /** \brief TransactionManager */
398 pkgAcqMetaBase
* const TransactionManager
;
400 enum TransactionStates
{
404 virtual bool TransactionState(TransactionStates
const state
);
406 virtual std::string
DescURI() const { return Target
->URI
; }
407 virtual HashStringList
GetExpectedHashes() const;
408 virtual std::string
GetMetaKey() const;
409 virtual bool HashesRequired() const;
412 pkgAcqTransactionItem(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const * const Target
);
413 virtual ~pkgAcqTransactionItem();
415 friend class pkgAcqMetaBase
;
418 class APT_HIDDEN pkgAcqMetaBase
: public pkgAcqTransactionItem
/*{{{*/
419 /** \brief the manager of a transaction */
424 std::vector
<pkgAcqTransactionItem
*> Transaction
;
426 IndexTarget
const DataTarget
;
428 /** \brief A package-system-specific parser for the meta-index file. */
429 indexRecords
*MetaIndexParser
;
430 indexRecords
*LastMetaIndexParser
;
433 /** \brief The index files which should be looked up in the meta-index
434 * and then downloaded.
436 const std::vector
<IndexTarget
*>* const IndexTargets
;
438 /** \brief If \b true, the index's signature is currently being verified.
442 /** \brief Starts downloading the individual index files.
444 * \param verify If \b true, only indices whose expected hashsum
445 * can be determined from the meta-index will be downloaded, and
446 * the hashsums of indices will be checked (reporting
447 * #StatAuthError if there is a mismatch). If verify is \b false,
448 * no hashsum checking will be performed.
450 void QueueIndexes(bool const verify
);
452 /** \brief Called when a file is finished being retrieved.
454 * If the file was not downloaded to DestFile, a copy process is
455 * set up to copy it to DestFile; otherwise, Complete is set to \b
456 * true and the file is moved to its final location.
458 * \param Message The message block received from the fetch
461 bool CheckDownloadDone(pkgAcqTransactionItem
* const I
, const std::string
&Message
, HashStringList
const &Hashes
) const;
463 /** \brief Queue the downloaded Signature for verification */
464 void QueueForSignatureVerify(pkgAcqTransactionItem
* const I
, std::string
const &File
, std::string
const &Signature
);
466 virtual std::string
Custom600Headers() const;
468 /** \brief Called when authentication succeeded.
470 * Sanity-checks the authenticated file, queues up the individual
471 * index files for download, and saves the signature in the lists
472 * directory next to the authenticated list file.
474 * \param Message The message block received from the fetch
477 bool CheckAuthDone(std::string
const &Message
);
479 /** Check if the current item should fail at this point */
480 bool CheckStopAuthentication(pkgAcquire::Item
* const I
, const std::string
&Message
);
482 /** \brief Check that the release file is a release file for the
483 * correct distribution.
485 * \return \b true if no fatal errors were encountered.
487 bool VerifyVendor(std::string
const &Message
);
489 virtual bool TransactionState(TransactionStates
const state
);
492 // This refers more to the Transaction-Manager than the actual file
495 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
496 virtual HashStringList
GetExpectedHashes() const;
497 virtual bool HashesRequired() const;
500 void Add(pkgAcqTransactionItem
* const I
);
501 void AbortTransaction();
502 bool TransactionHasError() const;
503 void CommitTransaction();
505 /** \brief Stage (queue) a copy action when the transaction is committed
507 void TransactionStageCopy(pkgAcqTransactionItem
* const I
,
508 const std::string
&From
,
509 const std::string
&To
);
510 /** \brief Stage (queue) a removal action when the transaction is committed
512 void TransactionStageRemoval(pkgAcqTransactionItem
* const I
, const std::string
&FinalFile
);
514 /** \brief Get the full pathname of the final file for the current URI */
515 virtual std::string
GetFinalFilename() const;
517 pkgAcqMetaBase(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
518 std::vector
<IndexTarget
*> const * const IndexTargets
,
519 IndexTarget
const &DataTarget
,
520 indexRecords
* const MetaIndexParser
);
523 /** \brief An item that is responsible for downloading the meta-index {{{
524 * file (i.e., Release) itself and verifying its signature.
526 * Once the download and verification are complete, the downloads of
527 * the individual index files are queued up using pkgAcqDiffIndex.
528 * If the meta-index file had a valid signature, the expected hashsums
529 * of the index files will be the md5sums listed in the meta-index;
530 * otherwise, the expected hashsums will be "" (causing the
531 * authentication of the index files to be bypassed).
533 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
538 IndexTarget
const DetachedSigTarget
;
540 /** \brief delayed constructor */
541 void Init(std::string
const &URIDesc
, std::string
const &ShortDesc
);
544 virtual std::string
DescURI() const;
546 // Specialized action members
547 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
548 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
549 pkgAcquire::MethodConfig
const * const Cnf
);
550 virtual void Finished();
552 /** \brief Create a new pkgAcqMetaIndex. */
553 pkgAcqMetaIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
554 IndexTarget
const &DataTarget
, IndexTarget
const &DetachedSigTarget
,
555 const std::vector
<IndexTarget
*>* const IndexTargets
, indexRecords
* const MetaIndexParser
);
557 friend class pkgAcqMetaSig
;
560 /** \brief An acquire item that downloads the detached signature {{{
561 * of a meta-index (Release) file, then queues up the release
564 * \todo Why protected members?
566 * \sa pkgAcqMetaIndex
568 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqTransactionItem
572 pkgAcqMetaIndex
* const MetaIndex
;
574 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
575 std::string MetaIndexFileSignature
;
579 /** \brief Get the full pathname of the final file for the current URI */
580 virtual std::string
GetFinalFilename() const;
583 virtual bool HashesRequired() const { return false; }
585 // Specialized action members
586 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
587 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
588 pkgAcquire::MethodConfig
const * const Cnf
);
590 /** \brief Create a new pkgAcqMetaSig. */
591 pkgAcqMetaSig(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const * const Target
,
592 pkgAcqMetaIndex
* const MetaIndex
);
593 virtual ~pkgAcqMetaSig();
596 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
597 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
601 IndexTarget
const ClearsignedTarget
;
602 IndexTarget
const DetachedDataTarget
;
603 IndexTarget
const DetachedSigTarget
;
606 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
607 virtual std::string
Custom600Headers() const;
608 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
609 pkgAcquire::MethodConfig
const * const Cnf
);
611 /** \brief Create a new pkgAcqMetaClearSig. */
612 pkgAcqMetaClearSig(pkgAcquire
* const Owner
,
613 IndexTarget
const &ClearsignedTarget
,
614 IndexTarget
const &DetachedDataTarget
,
615 IndexTarget
const &DetachedSigTarget
,
616 std::vector
<IndexTarget
*> const * const IndexTargets
,
617 indexRecords
* const MetaIndexParser
);
618 virtual ~pkgAcqMetaClearSig();
621 /** \brief Common base class for all classes that deal with fetching indexes {{{*/
622 class APT_HIDDEN pkgAcqBaseIndex
: public pkgAcqTransactionItem
627 /** \brief Get the full pathname of the final file for the current URI */
628 virtual std::string
GetFinalFilename() const;
630 pkgAcqBaseIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
631 IndexTarget
const * const Target
);
634 /** \brief An item that is responsible for fetching an index file of {{{
635 * package list diffs and starting the package list's download.
637 * This item downloads the Index file and parses it, then enqueues
638 * additional downloads of either the individual patches (using
639 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
641 * \sa pkgAcqIndexDiffs, pkgAcqIndex
643 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
648 /** \brief If \b true, debugging information will be written to std::clog. */
651 /** \brief A description of the Packages file (stored in
652 * pkgAcquire::ItemDesc::Description).
654 std::string Description
;
656 /** \brief Get the full pathname of the final file for the current URI */
657 virtual std::string
GetFinalFilename() const;
659 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
);
661 virtual bool TransactionState(TransactionStates
const state
);
663 // Specialized action members
664 virtual void Failed(std::string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
);
665 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
666 pkgAcquire::MethodConfig
const * const Cnf
);
667 virtual std::string
DescURI() const {return Target
->URI
+ "Index";};
668 virtual std::string
Custom600Headers() const;
669 virtual std::string
GetMetaKey() const;
671 /** \brief Parse the Index file for a set of Packages diffs.
673 * Parses the Index file and creates additional download items as
676 * \param IndexDiffFile The name of the Index file.
678 * \return \b true if the Index file was successfully parsed, \b
681 bool ParseDiffIndex(std::string
const &IndexDiffFile
);
683 /** \brief Create a new pkgAcqDiffIndex.
685 * \param Owner The Acquire object that owns this item.
687 * \param URI The URI of the list file to download.
689 * \param URIDesc A long description of the list file to download.
691 * \param ShortDesc A short description of the list file to download.
693 pkgAcqDiffIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
694 IndexTarget
const * const Target
);
696 APT_HIDDEN
void QueueOnIMSHit() const;
699 struct APT_HIDDEN DiffInfo
{ /*{{{*/
700 /** The filename of the diff. */
703 /** The hashes of the file after the diff is applied */
704 HashStringList result_hashes
;
706 /** The hashes of the diff */
707 HashStringList patch_hashes
;
709 /** The hashes of the compressed diff */
710 HashStringList download_hashes
;
713 /** \brief An item that is responsible for fetching client-merge patches {{{
714 * that need to be applied to a given package index file.
716 * Instead of downloading and applying each patch one by one like its
717 * sister #pkgAcqIndexDiffs this class will download all patches at once
718 * and call rred with all the patches downloaded once. Rred will then
719 * merge and apply them in one go, which should be a lot faster – but is
720 * incompatible with server-based merges of patches like reprepro can do.
722 * \sa pkgAcqDiffIndex, pkgAcqIndex
724 class APT_HIDDEN pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
730 /** \brief If \b true, debugging output will be written to
735 /** \brief description of the file being downloaded. */
736 std::string Description
;
738 /** \brief information about the current patch */
739 struct DiffInfo
const patch
;
741 /** \brief list of all download items for the patches */
742 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
744 /** The current status of this patch. */
747 /** \brief The diff is currently being fetched. */
750 /** \brief The diff is currently being applied. */
753 /** \brief the work with this diff is done */
756 /** \brief something bad happened and fallback was triggered */
761 /** \brief Called when the patch file failed to be downloaded.
763 * This method will fall back to downloading the whole index file
764 * outright; its arguments are ignored.
766 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
767 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
768 pkgAcquire::MethodConfig
const * const Cnf
);
769 virtual std::string
Custom600Headers() const;
770 virtual std::string
DescURI() const {return Target
->URI
+ "Index";};
771 virtual HashStringList
GetExpectedHashes() const;
772 virtual bool HashesRequired() const;
774 /** \brief Create an index merge-diff item.
776 * \param Owner The pkgAcquire object that owns this item.
778 * \param URI The URI of the package index file being
781 * \param URIDesc A long description of this item.
783 * \param ShortDesc A brief description of this item.
785 * \param patch contains infos about the patch this item is supposed
786 * to download which were read from the index
788 * \param allPatches contains all related items so that each item can
789 * check if it was the last one to complete the download step
791 pkgAcqIndexMergeDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
792 IndexTarget
const * const Target
,
793 DiffInfo
const &patch
,
794 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
797 /** \brief An item that is responsible for fetching server-merge patches {{{
798 * that need to be applied to a given package index file.
800 * After downloading and applying a single patch, this item will
801 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
802 * patches. If no patch can be found that applies to an intermediate
803 * file or if one of the patches cannot be downloaded, falls back to
804 * downloading the entire package index file using pkgAcqIndex.
806 * \sa pkgAcqDiffIndex, pkgAcqIndex
808 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
814 /** \brief Queue up the next diff download.
816 * Search for the next available diff that applies to the file
817 * that currently exists on disk, and enqueue it by calling
820 * \return \b true if an applicable diff was found, \b false
823 APT_HIDDEN
bool QueueNextDiff();
825 /** \brief Handle tasks that must be performed after the item
826 * finishes downloading.
828 * Dequeues the item and checks the resulting file's hashsums
829 * against ExpectedHashes after the last patch was applied.
830 * There is no need to check the md5/sha1 after a "normal"
831 * patch because QueueNextDiff() will check the sha1 later.
833 * \param allDone If \b true, the file was entirely reconstructed,
834 * and its md5sum is verified.
836 APT_HIDDEN
void Finish(bool const allDone
=false);
840 /** \brief If \b true, debugging output will be written to
845 /** A description of the file being downloaded. */
846 std::string Description
;
848 /** The patches that remain to be downloaded, including the patch
849 * being downloaded right now. This list should be ordered so
850 * that each diff appears before any diff that depends on it.
852 * \todo These are indexed by sha1sum; why not use some sort of
853 * dictionary instead of relying on ordering and stripping them
856 std::vector
<DiffInfo
> available_patches
;
858 /** The current status of this patch. */
861 /** \brief The diff is in an unknown state. */
864 /** \brief The diff is currently being fetched. */
867 /** \brief The diff is currently being applied. */
873 /** \brief Called when the patch file failed to be downloaded.
875 * This method will fall back to downloading the whole index file
876 * outright; its arguments are ignored.
878 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
880 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
881 pkgAcquire::MethodConfig
const * const Cnf
);
882 virtual std::string
Custom600Headers() const;
883 virtual std::string
DescURI() const {return Target
->URI
+ "IndexDiffs";};
884 virtual HashStringList
GetExpectedHashes() const;
885 virtual bool HashesRequired() const;
887 /** \brief Create an index diff item.
889 * After filling in its basic fields, this invokes Finish(true) if
890 * \a diffs is empty, or QueueNextDiff() otherwise.
892 * \param Owner The pkgAcquire object that owns this item.
894 * \param URI The URI of the package index file being
897 * \param URIDesc A long description of this item.
899 * \param ShortDesc A brief description of this item.
901 * \param diffs The remaining diffs from the index of diffs. They
902 * should be ordered so that each diff appears before any diff
903 * that depends on it.
905 pkgAcqIndexDiffs(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
906 IndexTarget
const * const Target
,
907 std::vector
<DiffInfo
> const &diffs
=std::vector
<DiffInfo
>());
910 /** \brief An acquire item that is responsible for fetching an index {{{
911 * file (e.g., Packages or Sources).
913 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
915 * \todo Why does pkgAcqIndex have protected members?
917 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
923 /** \brief The stages the method goes through
925 * The method first downloads the indexfile, then its decompressed (or
926 * copied) and verified
930 STAGE_DECOMPRESS_AND_VERIFY
,
934 /** \brief Handle what needs to be done when the download is done */
935 void StageDownloadDone(std::string
const &Message
,
936 HashStringList
const &Hashes
,
937 pkgAcquire::MethodConfig
const * const Cfg
);
939 /** \brief Handle what needs to be done when the decompression/copy is
942 void StageDecompressDone(std::string
const &Message
,
943 HashStringList
const &Hashes
,
944 pkgAcquire::MethodConfig
const * const Cfg
);
946 /** \brief If \b set, this partially downloaded file will be
947 * removed when the download completes.
949 std::string EraseFileName
;
951 /** \brief The compression-related file extensions that are being
952 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
954 std::string CompressionExtensions
;
956 /** \brief The actual compression extension currently used */
957 std::string CurrentCompressionExtension
;
959 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
960 void InitByHashIfNeeded();
962 /** \brief Auto select the right compression to use */
963 void AutoSelectCompression();
965 /** \brief Schedule file for verification after a IMS hit */
966 void ReverifyAfterIMS();
968 /** \brief Get the full pathname of the final file for the current URI */
969 virtual std::string
GetFinalFilename() const;
971 virtual bool TransactionState(TransactionStates
const state
);
974 // Specialized action members
975 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
976 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
977 pkgAcquire::MethodConfig
const * const Cnf
);
978 virtual std::string
Custom600Headers() const;
979 virtual std::string
DescURI() const {return Desc
.URI
;};
980 virtual std::string
GetMetaKey() const;
982 pkgAcqIndex(pkgAcquire
* const Owner
, pkgAcqMetaBase
* const TransactionManager
,
983 IndexTarget
const * const Target
);
985 void Init(std::string
const &URI
, std::string
const &URIDesc
,
986 std::string
const &ShortDesc
);
989 /** \brief An item that is responsible for fetching a package file. {{{
991 * If the package file already exists in the cache, nothing will be
994 class pkgAcqArchive
: public pkgAcquire::Item
999 HashStringList ExpectedHashes
;
1002 /** \brief The package version being fetched. */
1003 pkgCache::VerIterator Version
;
1005 /** \brief The list of sources from which to pick archives to
1006 * download this package from.
1008 pkgSourceList
*Sources
;
1010 /** \brief A package records object, used to look up the file
1011 * corresponding to each version of the package.
1015 /** \brief A location in which the actual filename of the package
1018 std::string
&StoreFilename
;
1020 /** \brief The next file for this version to try to download. */
1021 pkgCache::VerFileIterator Vf
;
1023 /** \brief How many (more) times to try to find a new source from
1024 * which to download this package version if it fails.
1026 * Set from Acquire::Retries.
1028 unsigned int Retries
;
1030 /** \brief \b true if this version file is being downloaded from a
1035 /** \brief Queue up the next available file for this version. */
1038 /** \brief Get the full pathname of the final file for the current URI */
1039 virtual std::string
GetFinalFilename() const;
1043 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1044 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
1045 pkgAcquire::MethodConfig
const * const Cnf
);
1046 virtual std::string
DescURI() const;
1047 virtual std::string
ShortDesc() const;
1048 virtual void Finished();
1049 virtual bool IsTrusted() const;
1050 virtual HashStringList
GetExpectedHashes() const;
1051 virtual bool HashesRequired() const;
1053 /** \brief Create a new pkgAcqArchive.
1055 * \param Owner The pkgAcquire object with which this item is
1058 * \param Sources The sources from which to download version
1061 * \param Recs A package records object, used to look up the file
1062 * corresponding to each version of the package.
1064 * \param Version The package version to download.
1066 * \param[out] StoreFilename A location in which the actual filename of
1067 * the package should be stored. It will be set to a guessed
1068 * basename in the constructor, and filled in with a fully
1069 * qualified filename once the download finishes.
1071 pkgAcqArchive(pkgAcquire
* const Owner
,pkgSourceList
* const Sources
,
1072 pkgRecords
* const Recs
,pkgCache::VerIterator
const &Version
,
1073 std::string
&StoreFilename
);
1076 /** \brief Retrieve an arbitrary file to the current directory. {{{
1078 * The file is retrieved even if it is accessed via a URL type that
1079 * normally is a NOP, such as "file". If the download fails, the
1080 * partial file is renamed to get a ".FAILED" extension.
1082 class pkgAcqFile
: public pkgAcquire::Item
1086 /** \brief How many times to retry the download, set from
1089 unsigned int Retries
;
1091 /** \brief Should this file be considered a index file */
1094 HashStringList
const ExpectedHashes
;
1096 virtual HashStringList
GetExpectedHashes() const;
1097 virtual bool HashesRequired() const;
1099 // Specialized action members
1100 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
1101 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1102 pkgAcquire::MethodConfig
const * const Cnf
);
1103 virtual std::string
DescURI() const {return Desc
.URI
;};
1104 virtual std::string
Custom600Headers() const;
1106 /** \brief Create a new pkgAcqFile object.
1108 * \param Owner The pkgAcquire object with which this object is
1111 * \param URI The URI to download.
1113 * \param Hashes The hashsums of the file to download, if they are known;
1114 * otherwise empty list.
1116 * \param Size The size of the file to download, if it is known;
1119 * \param Desc A description of the file being downloaded.
1121 * \param ShortDesc A brief description of the file being
1124 * \param DestDir The directory the file should be downloaded into.
1126 * \param DestFilename The filename+path the file is downloaded to.
1128 * \param IsIndexFile The file is considered a IndexFile and cache-control
1129 * headers like "cache-control: max-age=0" are send
1131 * If DestFilename is empty, download to DestDir/\<basename\> if
1132 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1133 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1134 * is the absolute name to which the file should be downloaded.
1137 pkgAcqFile(pkgAcquire
* const Owner
, std::string
const &URI
, HashStringList
const &Hashes
, unsigned long long const Size
,
1138 std::string
const &Desc
, std::string
const &ShortDesc
,
1139 std::string
const &DestDir
="", std::string
const &DestFilename
="",
1140 bool const IsIndexFile
=false);