1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 Acquire Item - Item to acquire
7 When an item is instantiated it will add it self to the local list in
8 the Owner Acquire class. Derived classes will then call QueueURI to
9 register all the URI's they wish to fetch at the initial moment.
11 Three item classes are provided to provide functionality for
12 downloading of Index, Translation and Packages files.
14 A Archive class is provided for downloading .deb files. It does Hash
15 checking and source location as well as a retry algorithm.
17 ##################################################################### */
19 #ifndef PKGLIB_ACQUIRE_ITEM_H
20 #define PKGLIB_ACQUIRE_ITEM_H
22 #include <apt-pkg/acquire.h>
23 #include <apt-pkg/indexfile.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/sourcelist.h>
35 #include <apt-pkg/pkgrecords.h>
38 /** \addtogroup acquire
41 * \file acquire-item.h
46 class pkgAcqMetaClearSig
;
47 class pkgAcqIndexMergeDiffs
;
50 class pkgAcquire::Item
: public WeakPointable
/*{{{*/
51 /** \brief Represents the process by which a pkgAcquire object should
52 * retrieve a file or a collection of files.
54 * By convention, Item subclasses should insert themselves into the
55 * acquire queue when they are created by calling QueueURI(), and
56 * remove themselves by calling Dequeue() when either Done() or
57 * Failed() is invoked. Item objects are also responsible for
58 * notifying the download progress indicator (accessible via
59 * #Owner->Log) of their status.
66 /** \brief The current status of this item. */
69 /** \brief The item is waiting to be downloaded. */
72 /** \brief The item is currently being downloaded. */
75 /** \brief The item has been successfully downloaded. */
78 /** \brief An error was encountered while downloading this
83 /** \brief The item was downloaded but its authenticity could
88 /** \brief The item was could not be downloaded because of
89 * a transient network error (e.g. network down)
91 StatTransientNetworkError
,
94 /** \brief Contains a textual description of the error encountered
95 * if #ItemState is #StatError or #StatAuthError.
97 std::string ErrorText
;
99 /** \brief The size of the object to fetch. */
100 unsigned long long FileSize
;
102 /** \brief How much of the object was already fetched. */
103 unsigned long long PartialSize
;
105 /** \brief If not \b NULL, contains the name of a subprocess that
106 * is operating on this object (for instance, "gzip" or "gpgv").
108 APT_DEPRECATED_MSG("Use the std::string member ActiveSubprocess instead") const char *Mode
;
110 /** \brief contains the name of the subprocess that is operating on this object
111 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
112 * as it can manage the lifetime of included string properly. */
113 std::string ActiveSubprocess
;
115 /** \brief A client-supplied unique identifier.
117 * This field is initalized to 0; it is meant to be filled in by
118 * clients that wish to use it to uniquely identify items.
120 * APT progress reporting will store an ID there as shown in "Get:42 …"
124 /** \brief If \b true, the entire object has been successfully fetched.
126 * Subclasses should set this to \b true when appropriate.
130 /** \brief If \b true, the URI of this object is "local".
132 * The only effect of this field is to exclude the object from the
133 * download progress indicator's overall statistics.
137 std::string UsedMirror
;
139 /** \brief The number of fetch queues into which this item has been
142 * There is one queue for each source from which an item could be
147 unsigned int QueueCounter
;
149 /** \brief The number of additional fetch items that are expected
150 * once this item is done.
152 * Some items like pkgAcqMeta{Index,Sig} will queue additional
153 * items. This variable can be set by the methods if it knows
154 * in advance how many items to expect to get a more accurate
157 unsigned int ExpectedAdditionalItems
;
159 /** \brief The name of the file into which the retrieved object
162 std::string DestFile
;
164 /** \brief Invoked by the acquire worker when the object couldn't
167 * This is a branch of the continuation of the fetch process.
169 * \param Message An RFC822-formatted message from the acquire
170 * method describing what went wrong. Use LookupTag() to parse
173 * \param Cnf The method via which the worker tried to fetch this object.
177 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
);
179 /** \brief Invoked by the acquire worker to check if the successfully
180 * fetched object is also the objected we wanted to have.
182 * Note that the object might \e not have been written to
183 * DestFile; check for the presence of an Alt-Filename entry in
184 * Message to find the file to which it was really written.
186 * This is called before Done is called and can prevent it by returning
187 * \b false which will result in Failed being called instead.
189 * You should prefer to use this method over calling Failed() from Done()
190 * as this has e.g. the wrong progress reporting.
192 * \param Message Data from the acquire method. Use LookupTag()
194 * \param Cnf The method via which the object was fetched.
198 virtual bool VerifyDone(std::string
const &Message
,
199 pkgAcquire::MethodConfig
const * const Cnf
);
201 /** \brief Invoked by the acquire worker when the object was
202 * fetched successfully.
204 * Note that the object might \e not have been written to
205 * DestFile; check for the presence of an Alt-Filename entry in
206 * Message to find the file to which it was really written.
208 * Done is often used to switch from one stage of the processing
209 * to the next (e.g. fetching, unpacking, copying). It is one
210 * branch of the continuation of the fetch process.
212 * \param Message Data from the acquire method. Use LookupTag()
214 * \param Hashes The HashSums of the object that was fetched.
215 * \param Cnf The method via which the object was fetched.
219 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
220 pkgAcquire::MethodConfig
const * const Cnf
);
222 /** \brief Invoked when the worker starts to fetch this object.
224 * \param Message RFC822-formatted data from the worker process.
225 * Use LookupTag() to parse it.
227 * \param Hashes The expected hashes of the object being fetched.
231 virtual void Start(std::string
const &Message
, unsigned long long const Size
);
233 /** \brief Custom headers to be sent to the fetch process.
235 * \return a string containing RFC822-style headers that are to be
236 * inserted into the 600 URI Acquire message sent to the fetch
237 * subprocess. The headers are inserted after a newline-less
238 * line, so they should (if nonempty) have a leading newline and
239 * no trailing newline.
241 virtual std::string
Custom600Headers() const;
243 /** \brief A "descriptive" URI-like string.
245 * \return a URI that should be used to describe what is being fetched.
247 virtual std::string
DescURI() const = 0;
248 /** \brief Short item description.
250 * \return a brief description of the object being fetched.
252 virtual std::string
ShortDesc() const;
254 /** \brief Invoked by the worker when the download is completely done. */
255 virtual void Finished();
257 /** \return HashSums the DestFile is supposed to have in this stage */
258 virtual HashStringList
GetExpectedHashes() const = 0;
259 /** \return the 'best' hash for display proposes like --print-uris */
260 std::string
HashSum() const;
262 /** \return if having no hashes is a hard failure or not
264 * Idealy this is always \b true for every subclass, but thanks to
265 * historical grow we don't have hashes for all files in all cases
266 * in all steps, so it is slightly more complicated than it should be.
268 virtual bool HashesRequired() const { return true; }
270 /** \return the acquire process with which this item is associated. */
271 pkgAcquire
*GetOwner() const;
272 pkgAcquire::ItemDesc
&GetItemDesc();
274 /** \return \b true if this object is being fetched from a trusted source. */
275 virtual bool IsTrusted() const;
277 /** \brief Report mirror problem
279 * This allows reporting mirror failures back to a centralized
280 * server. The apt-report-mirror-failure script is called for this
282 * \param FailCode A short failure string that is send
284 APT_DEPRECATED_MSG("Item::Failed does this for you") void ReportMirrorFailure(std::string
const &FailCode
);
286 /** \brief Set the name of the current active subprocess
288 * See also #ActiveSubprocess
290 void SetActiveSubprocess(std::string
const &subprocess
);
292 /** \brief Initialize an item.
294 * Adds the item to the list of items known to the acquire
295 * process, but does not place it into any fetch queues (you must
296 * manually invoke QueueURI() to do so).
298 * \param Owner The new owner of this item.
300 explicit Item(pkgAcquire
* const Owner
);
302 /** \brief Remove this item from its owner's queue by invoking
303 * pkgAcquire::Remove.
308 /** \brief The acquire object with which this item is associated. */
309 pkgAcquire
* const Owner
;
311 /** \brief The item that is currently being downloaded. */
312 pkgAcquire::ItemDesc Desc
;
314 enum RenameOnErrorState
{
324 /** \brief Rename failed file and set error
326 * \param state respresenting the error we encountered
328 bool RenameOnError(RenameOnErrorState
const state
);
330 /** \brief Insert this item into its owner's queue.
332 * The method is designed to check if the request would end
333 * in an IMSHit and if it determines that it would, it isn't
334 * queueing the Item and instead sets it to completion instantly.
336 * \param Item Metadata about this item (its URI and
338 * \return true if the item was inserted, false if IMSHit was detected
340 virtual bool QueueURI(ItemDesc
&Item
);
342 /** \brief Remove this item from its owner's queue. */
345 /** \brief Rename a file without modifying its timestamp.
347 * Many item methods call this as their final action.
349 * \param From The file to be renamed.
351 * \param To The new name of \a From. If \a To exists it will be
352 * overwritten. If \a From and \a To are equal nothing happens.
354 bool Rename(std::string
const &From
, std::string
const &To
);
356 /** \brief Get the full pathname of the final file for the current URI */
357 virtual std::string
GetFinalFilename() const;
362 friend class pkgAcqMetaBase
;
363 friend class pkgAcqMetaClearSig
;
366 class APT_HIDDEN pkgAcqTransactionItem
: public pkgAcquire::Item
/*{{{*/
367 /** \brief baseclass for the indexes files to manage them all together */
371 IndexTarget
const Target
;
372 HashStringList
GetExpectedHashesFor(std::string
const &MetaKey
) const;
374 bool QueueURI(pkgAcquire::ItemDesc
&Item
) APT_OVERRIDE
;
377 /** \brief storge name until a transaction is finished */
378 std::string PartialFile
;
380 /** \brief TransactionManager */
381 pkgAcqMetaClearSig
* const TransactionManager
;
383 enum TransactionStates
{
388 virtual bool TransactionState(TransactionStates
const state
);
390 virtual std::string
DescURI() const APT_OVERRIDE
{ return Target
.URI
; }
391 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
;
392 virtual std::string
GetMetaKey() const;
393 virtual bool HashesRequired() const APT_OVERRIDE
;
396 pkgAcqTransactionItem(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
, IndexTarget
const &Target
) APT_NONNULL(2, 3);
397 virtual ~pkgAcqTransactionItem();
399 friend class pkgAcqMetaBase
;
400 friend class pkgAcqMetaClearSig
;
403 class APT_HIDDEN pkgAcqMetaBase
: public pkgAcqTransactionItem
/*{{{*/
404 /** \brief the manager of a transaction */
408 std::vector
<pkgAcqTransactionItem
*> Transaction
;
410 /** \brief The index files which should be looked up in the meta-index
411 * and then downloaded.
413 std::vector
<IndexTarget
> IndexTargets
;
415 /** \brief If \b true, the index's signature is currently being verified.
419 /** \brief Called when a file is finished being retrieved.
421 * If the file was not downloaded to DestFile, a copy process is
422 * set up to copy it to DestFile; otherwise, Complete is set to \b
423 * true and the file is moved to its final location.
425 * \param Message The message block received from the fetch
428 bool CheckDownloadDone(pkgAcqTransactionItem
* const I
, const std::string
&Message
, HashStringList
const &Hashes
) const;
430 /** \brief Queue the downloaded Signature for verification */
431 void QueueForSignatureVerify(pkgAcqTransactionItem
* const I
, std::string
const &File
, std::string
const &Signature
);
433 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
435 /** \brief Called when authentication succeeded.
437 * Sanity-checks the authenticated file, queues up the individual
438 * index files for download, and saves the signature in the lists
439 * directory next to the authenticated list file.
441 * \param Message The message block received from the fetch
444 bool CheckAuthDone(std::string
const &Message
);
446 /** Check if the current item should fail at this point */
447 bool CheckStopAuthentication(pkgAcquire::Item
* const I
, const std::string
&Message
);
449 /** \brief Check that the release file is a release file for the
450 * correct distribution.
452 * \return \b true if no fatal errors were encountered.
454 bool VerifyVendor(std::string
const &Message
);
456 virtual bool TransactionState(TransactionStates
const state
) APT_OVERRIDE
;
459 // This refers more to the Transaction-Manager than the actual file
461 TransactionStates State
;
464 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
) APT_OVERRIDE
;
465 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
;
466 virtual bool HashesRequired() const APT_OVERRIDE
;
469 void Add(pkgAcqTransactionItem
* const I
);
470 void AbortTransaction();
471 bool TransactionHasError() const;
472 void CommitTransaction();
474 /** \brief Stage (queue) a copy action when the transaction is committed
476 void TransactionStageCopy(pkgAcqTransactionItem
* const I
,
477 const std::string
&From
,
478 const std::string
&To
);
479 /** \brief Stage (queue) a removal action when the transaction is committed
481 void TransactionStageRemoval(pkgAcqTransactionItem
* const I
, const std::string
&FinalFile
);
483 /** \brief Get the full pathname of the final file for the current URI */
484 virtual std::string
GetFinalFilename() const APT_OVERRIDE
;
486 pkgAcqMetaBase(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
487 std::vector
<IndexTarget
> const &IndexTargets
,
488 IndexTarget
const &DataTarget
) APT_NONNULL(2, 3);
489 virtual ~pkgAcqMetaBase();
492 /** \brief An item that is responsible for downloading the meta-index {{{
493 * file (i.e., Release) itself and verifying its signature.
495 * Once the download and verification are complete, the downloads of
496 * the individual index files are queued up using pkgAcqDiffIndex.
497 * If the meta-index file had a valid signature, the expected hashsums
498 * of the index files will be the md5sums listed in the meta-index;
499 * otherwise, the expected hashsums will be "" (causing the
500 * authentication of the index files to be bypassed).
502 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
506 IndexTarget
const DetachedSigTarget
;
508 /** \brief delayed constructor */
509 void Init(std::string
const &URIDesc
, std::string
const &ShortDesc
);
512 virtual std::string
DescURI() const APT_OVERRIDE
;
514 // Specialized action members
515 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
516 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
517 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
519 /** \brief Create a new pkgAcqMetaIndex. */
520 pkgAcqMetaIndex(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
521 IndexTarget
const &DataTarget
, IndexTarget
const &DetachedSigTarget
,
522 std::vector
<IndexTarget
> const &IndexTargets
) APT_NONNULL(2, 3);
523 virtual ~pkgAcqMetaIndex();
525 friend class pkgAcqMetaSig
;
528 /** \brief An acquire item that downloads the detached signature {{{
529 * of a meta-index (Release) file, then queues up the release
532 * \todo Why protected members?
534 * \sa pkgAcqMetaIndex
536 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqTransactionItem
540 pkgAcqMetaIndex
* const MetaIndex
;
542 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
543 std::string MetaIndexFileSignature
;
547 /** \brief Get the full pathname of the final file for the current URI */
548 virtual std::string
GetFinalFilename() const APT_OVERRIDE
;
551 virtual bool HashesRequired() const APT_OVERRIDE
{ return false; }
553 // Specialized action members
554 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
555 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
556 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
557 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
559 /** \brief Create a new pkgAcqMetaSig. */
560 pkgAcqMetaSig(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
561 IndexTarget
const &Target
, pkgAcqMetaIndex
* const MetaIndex
) APT_NONNULL(2, 3, 5);
562 virtual ~pkgAcqMetaSig();
565 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
566 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
570 IndexTarget
const ClearsignedTarget
;
571 IndexTarget
const DetachedDataTarget
;
574 /** \brief A package-system-specific parser for the meta-index file. */
575 metaIndex
*MetaIndexParser
;
576 metaIndex
*LastMetaIndexParser
;
578 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
579 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
580 virtual bool VerifyDone(std::string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
581 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
582 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
583 virtual void Finished() APT_OVERRIDE
;
585 /** \brief Starts downloading the individual index files.
587 * \param verify If \b true, only indices whose expected hashsum
588 * can be determined from the meta-index will be downloaded, and
589 * the hashsums of indices will be checked (reporting
590 * #StatAuthError if there is a mismatch). If verify is \b false,
591 * no hashsum checking will be performed.
593 void QueueIndexes(bool const verify
);
595 /** \brief Create a new pkgAcqMetaClearSig. */
596 pkgAcqMetaClearSig(pkgAcquire
* const Owner
,
597 IndexTarget
const &ClearsignedTarget
,
598 IndexTarget
const &DetachedDataTarget
,
599 IndexTarget
const &DetachedSigTarget
,
600 std::vector
<IndexTarget
> const &IndexTargets
,
601 metaIndex
* const MetaIndexParser
);
602 virtual ~pkgAcqMetaClearSig();
605 /** \brief Common base class for all classes that deal with fetching indexes {{{*/
606 class APT_HIDDEN pkgAcqBaseIndex
: public pkgAcqTransactionItem
611 /** \brief Get the full pathname of the final file for the current URI */
612 virtual std::string
GetFinalFilename() const APT_OVERRIDE
;
613 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
615 pkgAcqBaseIndex(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
616 IndexTarget
const &Target
) APT_NONNULL(2, 3);
617 virtual ~pkgAcqBaseIndex();
620 /** \brief An item that is responsible for fetching an index file of {{{
621 * package list diffs and starting the package list's download.
623 * This item downloads the Index file and parses it, then enqueues
624 * additional downloads of either the individual patches (using
625 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
627 * \sa pkgAcqIndexDiffs, pkgAcqIndex
629 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
632 std::vector
<pkgAcqIndexMergeDiffs
*> * diffs
;
635 /** \brief If \b true, debugging information will be written to std::clog. */
638 /** \brief A description of the Packages file (stored in
639 * pkgAcquire::ItemDesc::Description).
641 std::string Description
;
643 /** \brief Get the full pathname of the final file for the current URI */
644 virtual std::string
GetFinalFilename() const APT_OVERRIDE
;
646 virtual bool QueueURI(pkgAcquire::ItemDesc
&Item
) APT_OVERRIDE
;
648 virtual bool TransactionState(TransactionStates
const state
) APT_OVERRIDE
;
650 // Specialized action members
651 virtual void Failed(std::string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
652 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
653 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
654 virtual std::string
DescURI() const APT_OVERRIDE
{return Target
.URI
+ "Index";};
655 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
656 virtual std::string
GetMetaKey() const APT_OVERRIDE
;
658 /** \brief Parse the Index file for a set of Packages diffs.
660 * Parses the Index file and creates additional download items as
663 * \param IndexDiffFile The name of the Index file.
665 * \return \b true if the Index file was successfully parsed, \b
668 bool ParseDiffIndex(std::string
const &IndexDiffFile
);
670 /** \brief Create a new pkgAcqDiffIndex.
672 * \param Owner The Acquire object that owns this item.
674 * \param URI The URI of the list file to download.
676 * \param URIDesc A long description of the list file to download.
678 * \param ShortDesc A short description of the list file to download.
680 pkgAcqDiffIndex(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
681 IndexTarget
const &Target
) APT_NONNULL(2, 3);
682 virtual ~pkgAcqDiffIndex();
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
) APT_OVERRIDE
;
755 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
756 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
757 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
758 virtual std::string
DescURI() const APT_OVERRIDE
{return Target
.URI
+ "Index";};
759 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
;
760 virtual bool HashesRequired() const APT_OVERRIDE
;
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
, pkgAcqMetaClearSig
* const TransactionManager
,
780 IndexTarget
const &Target
, DiffInfo
const &patch
,
781 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
) APT_NONNULL(2, 3, 6);
782 virtual ~pkgAcqIndexMergeDiffs();
785 /** \brief An item that is responsible for fetching server-merge patches {{{
786 * that need to be applied to a given package index file.
788 * After downloading and applying a single patch, this item will
789 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
790 * patches. If no patch can be found that applies to an intermediate
791 * file or if one of the patches cannot be downloaded, falls back to
792 * downloading the entire package index file using pkgAcqIndex.
794 * \sa pkgAcqDiffIndex, pkgAcqIndex
796 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
802 /** \brief Queue up the next diff download.
804 * Search for the next available diff that applies to the file
805 * that currently exists on disk, and enqueue it by calling
808 * \return \b true if an applicable diff was found, \b false
811 APT_HIDDEN
bool QueueNextDiff();
813 /** \brief Handle tasks that must be performed after the item
814 * finishes downloading.
816 * Dequeues the item and checks the resulting file's hashsums
817 * against ExpectedHashes after the last patch was applied.
818 * There is no need to check the md5/sha1 after a "normal"
819 * patch because QueueNextDiff() will check the sha1 later.
821 * \param allDone If \b true, the file was entirely reconstructed,
822 * and its md5sum is verified.
824 APT_HIDDEN
void Finish(bool const allDone
=false);
828 /** \brief If \b true, debugging output will be written to
833 /** A description of the file being downloaded. */
834 std::string Description
;
836 /** The patches that remain to be downloaded, including the patch
837 * being downloaded right now. This list should be ordered so
838 * that each diff appears before any diff that depends on it.
840 * \todo These are indexed by sha1sum; why not use some sort of
841 * dictionary instead of relying on ordering and stripping them
844 std::vector
<DiffInfo
> available_patches
;
846 /** The current status of this patch. */
849 /** \brief The diff is currently being fetched. */
852 /** \brief The diff is currently being applied. */
858 /** \brief Called when the patch file failed to be downloaded.
860 * This method will fall back to downloading the whole index file
861 * outright; its arguments are ignored.
863 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
865 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
866 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
867 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
868 virtual std::string
DescURI() const APT_OVERRIDE
{return Target
.URI
+ "IndexDiffs";};
869 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
;
870 virtual bool HashesRequired() const APT_OVERRIDE
;
872 /** \brief Create an index diff item.
874 * After filling in its basic fields, this invokes Finish(true) if
875 * \a diffs is empty, or QueueNextDiff() otherwise.
877 * \param Owner The pkgAcquire object that owns this item.
879 * \param URI The URI of the package index file being
882 * \param URIDesc A long description of this item.
884 * \param ShortDesc A brief description of this item.
886 * \param diffs The remaining diffs from the index of diffs. They
887 * should be ordered so that each diff appears before any diff
888 * that depends on it.
890 pkgAcqIndexDiffs(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
891 IndexTarget
const &Target
,
892 std::vector
<DiffInfo
> const &diffs
=std::vector
<DiffInfo
>()) APT_NONNULL(2, 3);
893 virtual ~pkgAcqIndexDiffs();
896 /** \brief An acquire item that is responsible for fetching an index {{{
897 * file (e.g., Packages or Sources).
899 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
901 * \todo Why does pkgAcqIndex have protected members?
903 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
909 /** \brief The stages the method goes through
911 * The method first downloads the indexfile, then its decompressed (or
912 * copied) and verified
916 STAGE_DECOMPRESS_AND_VERIFY
,
920 /** \brief Handle what needs to be done when the download is done */
921 void StageDownloadDone(std::string
const &Message
);
923 /** \brief Handle what needs to be done when the decompression/copy is
926 void StageDecompressDone();
928 /** \brief If \b set, this partially downloaded file will be
929 * removed when the download completes.
931 std::string EraseFileName
;
933 /** \brief The compression-related file extensions that are being
934 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
936 std::string CompressionExtensions
;
938 /** \brief The actual compression extension currently used */
939 std::string CurrentCompressionExtension
;
941 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
942 void InitByHashIfNeeded();
944 /** \brief Get the full pathname of the final file for the current URI */
945 virtual std::string
GetFinalFilename() const APT_OVERRIDE
;
947 virtual bool TransactionState(TransactionStates
const state
) APT_OVERRIDE
;
950 // Specialized action members
951 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
952 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
953 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
954 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
955 virtual std::string
DescURI() const APT_OVERRIDE
{return Desc
.URI
;};
956 virtual std::string
GetMetaKey() const APT_OVERRIDE
;
958 pkgAcqIndex(pkgAcquire
* const Owner
, pkgAcqMetaClearSig
* const TransactionManager
,
959 IndexTarget
const &Target
) APT_NONNULL(2, 3);
960 virtual ~pkgAcqIndex();
963 APT_HIDDEN
void Init(std::string
const &URI
, std::string
const &URIDesc
,
964 std::string
const &ShortDesc
);
967 /** \brief An item that is responsible for fetching a package file. {{{
969 * If the package file already exists in the cache, nothing will be
972 class pkgAcqArchive
: public pkgAcquire::Item
977 HashStringList ExpectedHashes
;
980 /** \brief The package version being fetched. */
981 pkgCache::VerIterator Version
;
983 /** \brief The list of sources from which to pick archives to
984 * download this package from.
986 pkgSourceList
*Sources
;
988 /** \brief A package records object, used to look up the file
989 * corresponding to each version of the package.
993 /** \brief A location in which the actual filename of the package
996 std::string
&StoreFilename
;
998 /** \brief The next file for this version to try to download. */
999 pkgCache::VerFileIterator Vf
;
1001 /** \brief How many (more) times to try to find a new source from
1002 * which to download this package version if it fails.
1004 * Set from Acquire::Retries.
1006 unsigned int Retries
;
1008 /** \brief \b true if this version file is being downloaded from a
1013 /** \brief Queue up the next available file for this version. */
1016 /** \brief Get the full pathname of the final file for the current URI */
1017 virtual std::string
GetFinalFilename() const APT_OVERRIDE
;
1021 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
1022 virtual void Done(std::string
const &Message
, HashStringList
const &Hashes
,
1023 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
1024 virtual std::string
DescURI() const APT_OVERRIDE
;
1025 virtual std::string
ShortDesc() const APT_OVERRIDE
;
1026 virtual void Finished() APT_OVERRIDE
;
1027 virtual bool IsTrusted() const APT_OVERRIDE
;
1028 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
;
1029 virtual bool HashesRequired() const APT_OVERRIDE
;
1031 /** \brief Create a new pkgAcqArchive.
1033 * \param Owner The pkgAcquire object with which this item is
1036 * \param Sources The sources from which to download version
1039 * \param Recs A package records object, used to look up the file
1040 * corresponding to each version of the package.
1042 * \param Version The package version to download.
1044 * \param[out] StoreFilename A location in which the actual filename of
1045 * the package should be stored. It will be set to a guessed
1046 * basename in the constructor, and filled in with a fully
1047 * qualified filename once the download finishes.
1049 pkgAcqArchive(pkgAcquire
* const Owner
,pkgSourceList
* const Sources
,
1050 pkgRecords
* const Recs
,pkgCache::VerIterator
const &Version
,
1051 std::string
&StoreFilename
);
1052 virtual ~pkgAcqArchive();
1055 /** \brief Retrieve the changelog for the given version {{{
1057 * Downloads the changelog to a temporary file it will also remove again
1058 * while it is deconstructed or downloads it to a named location.
1060 class pkgAcqChangelog
: public pkgAcquire::Item
1064 std::string TemporaryDirectory
;
1065 std::string
const SrcName
;
1066 std::string
const SrcVersion
;
1069 // we will never have hashes for changelogs.
1070 // If you need verified ones, download the deb and extract the changelog.
1071 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
{ return HashStringList(); }
1072 virtual bool HashesRequired() const APT_OVERRIDE
{ return false; }
1074 // Specialized action members
1075 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
1076 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1077 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
1078 virtual std::string
DescURI() const APT_OVERRIDE
{return Desc
.URI
;};
1080 /** returns the URI to the changelog of this version
1082 * @param Ver is the version to get the changelog for
1083 * @return the URI which will be used to acquire the changelog
1085 static std::string
URI(pkgCache::VerIterator
const &Ver
);
1087 /** returns the URI to the changelog of this version
1089 * \param Rls is the Release file the package comes from
1090 * \param Component in which the package resides, can be empty
1091 * \param SrcName is the source package name
1092 * \param SrcVersion is the source package version
1093 * @return the URI which will be used to acquire the changelog
1095 static std::string
URI(pkgCache::RlsFileIterator
const &Rls
,
1096 char const * const Component
, char const * const SrcName
,
1097 char const * const SrcVersion
);
1099 /** returns the URI to the changelog of this version
1101 * \param Template URI where @CHANGEPATH@ has to be filled in
1102 * \param Component in which the package resides, can be empty
1103 * \param SrcName is the source package name
1104 * \param SrcVersion is the source package version
1105 * @return the URI which will be used to acquire the changelog
1107 static std::string
URI(std::string
const &Template
,
1108 char const * const Component
, char const * const SrcName
,
1109 char const * const SrcVersion
);
1111 /** returns the URI template for this release file
1113 * \param Rls is a Release file
1114 * @return the URI template to use for this release file
1116 static std::string
URITemplate(pkgCache::RlsFileIterator
const &Rls
);
1118 /** \brief Create a new pkgAcqChangelog object.
1120 * \param Owner The pkgAcquire object with which this object is
1122 * \param Ver is the version to get the changelog for
1123 * \param DestDir The directory the file should be downloaded into.
1124 * Will be an autocreated (and cleaned up) temporary directory if not set.
1125 * \param DestFilename The filename the file should have in #DestDir
1126 * Defaults to sourcepackagename.changelog if not set.
1128 pkgAcqChangelog(pkgAcquire
* const Owner
, pkgCache::VerIterator
const &Ver
,
1129 std::string
const &DestDir
="", std::string
const &DestFilename
="");
1131 /** \brief Create a new pkgAcqChangelog object.
1133 * \param Owner The pkgAcquire object with which this object is
1135 * \param Rls is the Release file the package comes from
1136 * \param Component in which the package resides, can be empty
1137 * \param SrcName is the source package name
1138 * \param SrcVersion is the source package version
1139 * \param DestDir The directory the file should be downloaded into.
1140 * Will be an autocreated (and cleaned up) temporary directory if not set.
1141 * \param DestFilename The filename the file should have in #DestDir
1142 * Defaults to sourcepackagename.changelog if not set.
1144 pkgAcqChangelog(pkgAcquire
* const Owner
, pkgCache::RlsFileIterator
const &Rls
,
1145 char const * const Component
, char const * const SrcName
, char const * const SrcVersion
,
1146 std::string
const &DestDir
="", std::string
const &DestFilename
="");
1148 /** \brief Create a new pkgAcqChangelog object.
1150 * \param Owner The pkgAcquire object with which this object is
1152 * \param URI is to be used to get the changelog
1153 * \param SrcName is the source package name
1154 * \param SrcVersion is the source package version
1155 * \param DestDir The directory the file should be downloaded into.
1156 * Will be an autocreated (and cleaned up) temporary directory if not set.
1157 * \param DestFilename The filename the file should have in #DestDir
1158 * Defaults to sourcepackagename.changelog if not set.
1160 pkgAcqChangelog(pkgAcquire
* const Owner
, std::string
const &URI
,
1161 char const * const SrcName
, char const * const SrcVersion
,
1162 std::string
const &DestDir
="", std::string
const &DestFilename
="");
1164 virtual ~pkgAcqChangelog();
1167 APT_HIDDEN
void Init(std::string
const &DestDir
, std::string
const &DestFilename
);
1170 /** \brief Retrieve an arbitrary file to the current directory. {{{
1172 * The file is retrieved even if it is accessed via a URL type that
1173 * normally is a NOP, such as "file". If the download fails, the
1174 * partial file is renamed to get a ".FAILED" extension.
1176 class pkgAcqFile
: public pkgAcquire::Item
1180 /** \brief How many times to retry the download, set from
1183 unsigned int Retries
;
1185 /** \brief Should this file be considered a index file */
1188 HashStringList
const ExpectedHashes
;
1190 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
;
1191 virtual bool HashesRequired() const APT_OVERRIDE
;
1193 // Specialized action members
1194 virtual void Failed(std::string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
1195 virtual void Done(std::string
const &Message
, HashStringList
const &CalcHashes
,
1196 pkgAcquire::MethodConfig
const * const Cnf
) APT_OVERRIDE
;
1197 virtual std::string
DescURI() const APT_OVERRIDE
{return Desc
.URI
;};
1198 virtual std::string
Custom600Headers() const APT_OVERRIDE
;
1200 /** \brief Create a new pkgAcqFile object.
1202 * \param Owner The pkgAcquire object with which this object is
1205 * \param URI The URI to download.
1207 * \param Hashes The hashsums of the file to download, if they are known;
1208 * otherwise empty list.
1210 * \param Size The size of the file to download, if it is known;
1213 * \param Desc A description of the file being downloaded.
1215 * \param ShortDesc A brief description of the file being
1218 * \param DestDir The directory the file should be downloaded into.
1220 * \param DestFilename The filename+path the file is downloaded to.
1222 * \param IsIndexFile The file is considered a IndexFile and cache-control
1223 * headers like "cache-control: max-age=0" are send
1225 * If DestFilename is empty, download to DestDir/\<basename\> if
1226 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1227 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1228 * is the absolute name to which the file should be downloaded.
1231 pkgAcqFile(pkgAcquire
* const Owner
, std::string
const &URI
, HashStringList
const &Hashes
, unsigned long long const Size
,
1232 std::string
const &Desc
, std::string
const &ShortDesc
,
1233 std::string
const &DestDir
="", std::string
const &DestFilename
="",
1234 bool const IsIndexFile
=false);
1235 virtual ~pkgAcqFile();