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 /** \brief Represents the process by which a pkgAcquire object should {{{
53 * retrieve a file or a collection of files.
55 * By convention, Item subclasses should insert themselves into the
56 * acquire queue when they are created by calling QueueURI(), and
57 * remove themselves by calling Dequeue() when either Done() or
58 * Failed() is invoked. Item objects are also responsible for
59 * notifying the download progress indicator (accessible via
60 * #Owner->Log) of their status.
64 class pkgAcquire::Item
: public WeakPointable
66 friend class pkgAcqMetaBase
;
72 /** \brief The acquire object with which this item is associated. */
75 /** \brief Insert this item into its owner's queue.
77 * \param Item Metadata about this item (its URI and
80 void QueueURI(ItemDesc
&Item
);
82 /** \brief Remove this item from its owner's queue. */
85 /** \brief Rename a file without modifying its timestamp.
87 * Many item methods call this as their final action.
89 * \param From The file to be renamed.
91 * \param To The new name of \a From. If \a To exists it will be
94 bool Rename(std::string From
,std::string To
);
98 /** \brief The current status of this item. */
101 /** \brief The item is waiting to be downloaded. */
104 /** \brief The item is currently being downloaded. */
107 /** \brief The item has been successfully downloaded. */
110 /** \brief An error was encountered while downloading this
115 /** \brief The item was downloaded but its authenticity could
120 /** \brief The item was could not be downloaded because of
121 * a transient network error (e.g. network down)
123 StatTransientNetworkError
,
126 /** \brief Contains a textual description of the error encountered
127 * if #ItemState is #StatError or #StatAuthError.
129 std::string ErrorText
;
131 /** \brief The size of the object to fetch. */
132 unsigned long long FileSize
;
134 /** \brief How much of the object was already fetched. */
135 unsigned long long PartialSize
;
137 /** \brief If not \b NULL, contains the name of a subprocess that
138 * is operating on this object (for instance, "gzip" or "gpgv").
140 APT_DEPRECATED
const char *Mode
;
142 /** \brief contains the name of the subprocess that is operating on this object
143 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
144 * as it can manage the lifetime of included string properly. */
145 std::string ActiveSubprocess
;
147 /** \brief A client-supplied unique identifier.
149 * This field is initalized to 0; it is meant to be filled in by
150 * clients that wish to use it to uniquely identify items.
152 * \todo it's unused in apt itself
156 /** \brief If \b true, the entire object has been successfully fetched.
158 * Subclasses should set this to \b true when appropriate.
162 /** \brief If \b true, the URI of this object is "local".
164 * The only effect of this field is to exclude the object from the
165 * download progress indicator's overall statistics.
168 std::string UsedMirror
;
170 /** \brief The number of fetch queues into which this item has been
173 * There is one queue for each source from which an item could be
178 unsigned int QueueCounter
;
180 /** \brief TransactionManager */
181 pkgAcqMetaBase
*TransactionManager
;
183 /** \brief The number of additional fetch items that are expected
184 * once this item is done.
186 * Some items like pkgAcqMeta{Index,Sig} will queue additional
187 * items. This variable can be set by the methods if it knows
188 * in advance how many items to expect to get a more accurate
191 unsigned int ExpectedAdditionalItems
;
193 /** \brief The name of the file into which the retrieved object
196 std::string DestFile
;
198 /** \brief storge name until a transaction is finished */
199 std::string PartialFile
;
201 /** \brief Invoked by the acquire worker when the object couldn't
204 * This is a branch of the continuation of the fetch process.
206 * \param Message An RFC822-formatted message from the acquire
207 * method describing what went wrong. Use LookupTag() to parse
210 * \param Cnf The method via which the worker tried to fetch this object.
214 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
216 /** \brief Invoked by the acquire worker when the object was
217 * fetched successfully.
219 * Note that the object might \e not have been written to
220 * DestFile; check for the presence of an Alt-Filename entry in
221 * Message to find the file to which it was really written.
223 * Done is often used to switch from one stage of the processing
224 * to the next (e.g. fetching, unpacking, copying). It is one
225 * branch of the continuation of the fetch process.
227 * \param Message Data from the acquire method. Use LookupTag()
229 * \param Size The size of the object that was fetched.
230 * \param Hashes The HashSums of the object that was fetched.
231 * \param Cnf The method via which the object was fetched.
235 virtual void Done(std::string Message
, unsigned long long Size
, HashStringList
const &Hashes
,
236 pkgAcquire::MethodConfig
*Cnf
);
238 /** \brief Invoked when the worker starts to fetch this object.
240 * \param Message RFC822-formatted data from the worker process.
241 * Use LookupTag() to parse it.
243 * \param Size The size of the object being fetched.
247 virtual void Start(std::string Message
,unsigned long long Size
);
249 /** \brief Custom headers to be sent to the fetch process.
251 * \return a string containing RFC822-style headers that are to be
252 * inserted into the 600 URI Acquire message sent to the fetch
253 * subprocess. The headers are inserted after a newline-less
254 * line, so they should (if nonempty) have a leading newline and
255 * no trailing newline.
257 #if APT_PKG_ABI >= 413
258 virtual std::string
Custom600Headers() const {return std::string();};
260 virtual std::string
Custom600Headers() {return std::string();};
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() = 0;
268 /** \brief Short item description.
270 * \return a brief description of the object being fetched.
272 virtual std::string
ShortDesc() {return DescURI();}
274 /** \brief Invoked by the worker when the download is completely done. */
275 virtual void Finished() {};
279 * \return the HashSums of this object, if applicable; otherwise, an
282 HashStringList
HashSums() const {return ExpectedHashes
;};
283 std::string
HashSum() const {HashStringList
const hashes
= HashSums(); HashString
const * const hs
= hashes
.find(NULL
); return hs
!= NULL
? hs
->toStr() : ""; };
285 /** \return the acquire process with which this item is associated. */
286 pkgAcquire
*GetOwner() const {return Owner
;};
287 #if APT_PKG_ABI < 413
288 pkgAcquire
*GetOwner() {return Owner
;};
291 /** \return \b true if this object is being fetched from a trusted source. */
292 #if APT_PKG_ABI >= 413
293 virtual bool IsTrusted() const {return false;};
295 virtual bool IsTrusted() {return false;};
298 /** \brief Report mirror problem
300 * This allows reporting mirror failures back to a centralized
301 * server. The apt-report-mirror-failure script is called for this
303 * \param FailCode A short failure string that is send
305 void ReportMirrorFailure(std::string FailCode
);
307 /** \brief Set the name of the current active subprocess
309 * See also #ActiveSubprocess
311 void SetActiveSubprocess(const std::string
&subprocess
);
313 /** \brief Initialize an item.
315 * Adds the item to the list of items known to the acquire
316 * process, but does not place it into any fetch queues (you must
317 * manually invoke QueueURI() to do so).
319 * \param Owner The new owner of this item.
320 * \param ExpectedHashes of the file represented by this item
322 Item(pkgAcquire
*Owner
,
323 HashStringList
const &ExpectedHashes
=HashStringList(),
324 pkgAcqMetaBase
*TransactionManager
=NULL
);
326 /** \brief Remove this item from its owner's queue by invoking
327 * pkgAcquire::Remove.
333 enum RenameOnErrorState
{
342 /** \brief Rename failed file and set error
344 * \param state respresenting the error we encountered
346 bool RenameOnError(RenameOnErrorState
const state
);
348 /** \brief The HashSums of the item is supposed to have than done */
349 HashStringList ExpectedHashes
;
351 /** \brief The item that is currently being downloaded. */
352 pkgAcquire::ItemDesc Desc
;
355 /** \brief Information about an index patch (aka diff). */ /*{{{*/
356 struct APT_HIDDEN DiffInfo
{
357 /** The filename of the diff. */
360 /** The hashes of the diff */
361 HashStringList result_hashes
;
363 /** The hashes of the file after the diff is applied */
364 HashStringList patch_hashes
;
366 /** The size of the file after the diff is applied */
367 unsigned long long result_size
;
369 /** The size of the diff itself */
370 unsigned long long patch_size
;
373 class pkgAcqMetaBase
: public pkgAcquire::Item
/*{{{*/
378 std::vector
<Item
*> Transaction
;
380 /** \brief A package-system-specific parser for the meta-index file. */
381 indexRecords
*MetaIndexParser
;
383 /** \brief The index files which should be looked up in the meta-index
384 * and then downloaded.
386 const std::vector
<IndexTarget
*>* IndexTargets
;
388 /** \brief If \b true, the index's signature is currently being verified.
392 // required to deal gracefully with problems caused by incorrect ims hits
395 /** \brief Starts downloading the individual index files.
397 * \param verify If \b true, only indices whose expected hashsum
398 * can be determined from the meta-index will be downloaded, and
399 * the hashsums of indices will be checked (reporting
400 * #StatAuthError if there is a mismatch). If verify is \b false,
401 * no hashsum checking will be performed.
403 void QueueIndexes(bool verify
);
405 /** \brief Called when a file is finished being retrieved.
407 * If the file was not downloaded to DestFile, a copy process is
408 * set up to copy it to DestFile; otherwise, Complete is set to \b
409 * true and the file is moved to its final location.
411 * \param Message The message block received from the fetch
414 bool CheckDownloadDone(const std::string
&Message
,
415 const std::string
&RealURI
);
417 /** \brief Queue the downloaded Signature for verification */
418 void QueueForSignatureVerify(const std::string
&MetaIndexFile
,
419 const std::string
&MetaIndexFileSignature
);
421 /** \brief get the custom600 header for all pkgAcqMeta */
422 std::string
GetCustom600Headers(const std::string
&RealURI
) const;
424 /** \brief Called when authentication succeeded.
426 * Sanity-checks the authenticated file, queues up the individual
427 * index files for download, and saves the signature in the lists
428 * directory next to the authenticated list file.
430 * \param Message The message block received from the fetch
433 bool CheckAuthDone(std::string Message
, const std::string
&RealURI
);
435 /** Check if the current item should fail at this point */
436 bool CheckStopAuthentication(const std::string
&RealURI
,
437 const std::string
&Message
);
439 /** \brief Check that the release file is a release file for the
440 * correct distribution.
442 * \return \b true if no fatal errors were encountered.
444 bool VerifyVendor(std::string Message
, const std::string
&RealURI
);
449 void AbortTransaction();
450 bool TransactionHasError() APT_PURE
;
451 void CommitTransaction();
453 /** \brief Stage (queue) a copy action when the transaction is committed
455 void TransactionStageCopy(Item
*I
,
456 const std::string
&From
,
457 const std::string
&To
);
458 /** \brief Stage (queue) a removal action when the transaction is committed
460 void TransactionStageRemoval(Item
*I
, const std::string
&FinalFile
);
462 pkgAcqMetaBase(pkgAcquire
*Owner
,
463 const std::vector
<IndexTarget
*>* IndexTargets
,
464 indexRecords
* MetaIndexParser
,
465 HashStringList
const &ExpectedHashes
=HashStringList(),
466 pkgAcqMetaBase
*TransactionManager
=NULL
)
467 : Item(Owner
, ExpectedHashes
, TransactionManager
),
468 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
),
469 AuthPass(false), IMSHit(false) {};
472 /** \brief An acquire item that downloads the detached signature {{{
473 * of a meta-index (Release) file, then queues up the release
476 * \todo Why protected members?
478 * \sa pkgAcqMetaIndex
480 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqMetaBase
486 /** \brief The URI of the signature file. Unlike Desc.URI, this is
487 * never modified; it is used to determine the file that is being
492 /** \brief The file we need to verify */
493 std::string MetaIndexFile
;
495 /** \brief The file we use to verify the MetaIndexFile with */
496 std::string MetaIndexFileSignature
;
498 /** \brief Long URI description used in the acquire system */
501 /** \brief Short URI description used in the acquire system */
502 std::string ShortDesc
;
506 // Specialized action members
507 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
508 virtual void Done(std::string Message
,unsigned long long Size
,
509 HashStringList
const &Hashes
,
510 pkgAcquire::MethodConfig
*Cnf
);
511 #if APT_PKG_ABI >= 413
512 virtual std::string
Custom600Headers() const;
514 virtual std::string
Custom600Headers();
516 virtual std::string
DescURI() {return RealURI
; };
518 /** \brief Create a new pkgAcqMetaSig. */
519 pkgAcqMetaSig(pkgAcquire
*Owner
,
520 pkgAcqMetaBase
*TransactionManager
,
521 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
522 std::string MetaIndexFile
,
523 const std::vector
<IndexTarget
*>* IndexTargets
,
524 indexRecords
* MetaIndexParser
);
525 virtual ~pkgAcqMetaSig();
528 /** \brief An item that is responsible for downloading the meta-index {{{
529 * file (i.e., Release) itself and verifying its signature.
531 * Once the download and verification are complete, the downloads of
532 * the individual index files are queued up using pkgAcqDiffIndex.
533 * If the meta-index file had a valid signature, the expected hashsums
534 * of the index files will be the md5sums listed in the meta-index;
535 * otherwise, the expected hashsums will be "" (causing the
536 * authentication of the index files to be bypassed).
538 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
543 /** \brief The URI that is actually being downloaded; never
544 * modified by pkgAcqMetaIndex.
549 std::string ShortDesc
;
551 /** \brief The URI of the meta-index file for the detached signature */
552 std::string MetaIndexSigURI
;
554 /** \brief A "URI-style" description of the meta-index file */
555 std::string MetaIndexSigURIDesc
;
557 /** \brief A brief description of the meta-index file */
558 std::string MetaIndexSigShortDesc
;
560 /** \brief delayed constructor */
561 void Init(std::string URIDesc
, std::string ShortDesc
);
565 // Specialized action members
566 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
567 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
568 pkgAcquire::MethodConfig
*Cnf
);
569 #if APT_PKG_ABI >= 413
570 virtual std::string
Custom600Headers() const;
572 virtual std::string
Custom600Headers();
574 virtual std::string
DescURI() {return RealURI
; };
575 virtual void Finished();
577 /** \brief Create a new pkgAcqMetaIndex. */
578 pkgAcqMetaIndex(pkgAcquire
*Owner
,
579 pkgAcqMetaBase
*TransactionManager
,
580 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
581 std::string MetaIndexSigURI
, std::string MetaIndexSigURIDesc
, std::string MetaIndexSigShortDesc
,
582 const std::vector
<IndexTarget
*>* IndexTargets
,
583 indexRecords
* MetaIndexParser
);
586 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
587 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
591 /** \brief The URI of the meta-index file for the detached signature */
592 std::string MetaIndexURI
;
594 /** \brief A "URI-style" description of the meta-index file */
595 std::string MetaIndexURIDesc
;
597 /** \brief A brief description of the meta-index file */
598 std::string MetaIndexShortDesc
;
600 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
601 std::string MetaSigURI
;
603 /** \brief A "URI-style" description of the meta-signature file */
604 std::string MetaSigURIDesc
;
606 /** \brief A brief description of the meta-signature file */
607 std::string MetaSigShortDesc
;
610 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
611 #if APT_PKG_ABI >= 413
612 virtual std::string
Custom600Headers() const;
614 virtual std::string
Custom600Headers();
616 virtual void Done(std::string Message
,unsigned long long Size
,
617 HashStringList
const &Hashes
,
618 pkgAcquire::MethodConfig
*Cnf
);
620 /** \brief Create a new pkgAcqMetaClearSig. */
621 pkgAcqMetaClearSig(pkgAcquire
*Owner
,
622 std::string
const &URI
, std::string
const &URIDesc
, std::string
const &ShortDesc
,
623 std::string
const &MetaIndexURI
, std::string
const &MetaIndexURIDesc
, std::string
const &MetaIndexShortDesc
,
624 std::string
const &MetaSigURI
, std::string
const &MetaSigURIDesc
, std::string
const &MetaSigShortDesc
,
625 const std::vector
<IndexTarget
*>* IndexTargets
,
626 indexRecords
* MetaIndexParser
);
627 virtual ~pkgAcqMetaClearSig();
630 /** \brief Common base class for all classes that deal with fetching {{{
633 class pkgAcqBaseIndex
: public pkgAcquire::Item
638 /** \brief Pointer to the IndexTarget data
640 const struct IndexTarget
* Target
;
642 /** \brief Pointer to the indexRecords parser */
643 indexRecords
*MetaIndexParser
;
645 /** \brief The MetaIndex Key */
648 /** \brief The URI of the index file to recreate at our end (either
649 * by downloading it or by applying partial patches).
653 bool VerifyHashByMetaKey(HashStringList
const &Hashes
);
655 pkgAcqBaseIndex(pkgAcquire
*Owner
,
656 pkgAcqMetaBase
*TransactionManager
,
657 struct IndexTarget
const * const Target
,
658 HashStringList
const &ExpectedHashes
,
659 indexRecords
*MetaIndexParser
)
660 : Item(Owner
, ExpectedHashes
, TransactionManager
), Target(Target
),
661 MetaIndexParser(MetaIndexParser
) {};
664 /** \brief An item that is responsible for fetching an index file of {{{
665 * package list diffs and starting the package list's download.
667 * This item downloads the Index file and parses it, then enqueues
668 * additional downloads of either the individual patches (using
669 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
671 * \sa pkgAcqIndexDiffs, pkgAcqIndex
673 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
678 /** \brief If \b true, debugging information will be written to std::clog. */
681 /** \brief The index file which will be patched to generate the new
684 std::string CurrentPackagesFile
;
686 /** \brief A description of the Packages file (stored in
687 * pkgAcquire::ItemDesc::Description).
689 std::string Description
;
691 /** \brief If the copy step of the packages file is done
693 bool PackagesFileReadyInPartial
;
696 // Specialized action members
697 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
698 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
699 pkgAcquire::MethodConfig
*Cnf
);
700 virtual std::string
DescURI() {return RealURI
+ "Index";};
701 #if APT_PKG_ABI >= 413
702 virtual std::string
Custom600Headers() const;
704 virtual std::string
Custom600Headers();
707 /** \brief Parse the Index file for a set of Packages diffs.
709 * Parses the Index file and creates additional download items as
712 * \param IndexDiffFile The name of the Index file.
714 * \return \b true if the Index file was successfully parsed, \b
717 bool ParseDiffIndex(std::string IndexDiffFile
);
720 /** \brief Create a new pkgAcqDiffIndex.
722 * \param Owner The Acquire object that owns this item.
724 * \param URI The URI of the list file to download.
726 * \param URIDesc A long description of the list file to download.
728 * \param ShortDesc A short description of the list file to download.
730 * \param ExpectedHashes The list file's hashsums which are expected.
732 pkgAcqDiffIndex(pkgAcquire
*Owner
,
733 pkgAcqMetaBase
*TransactionManager
,
734 struct IndexTarget
const * const Target
,
735 HashStringList
const &ExpectedHashes
,
736 indexRecords
*MetaIndexParser
);
739 /** \brief An item that is responsible for fetching client-merge patches {{{
740 * that need to be applied to a given package index file.
742 * Instead of downloading and applying each patch one by one like its
743 * sister #pkgAcqIndexDiffs this class will download all patches at once
744 * and call rred with all the patches downloaded once. Rred will then
745 * merge and apply them in one go, which should be a lot faster – but is
746 * incompatible with server-based merges of patches like reprepro can do.
748 * \sa pkgAcqDiffIndex, pkgAcqIndex
750 class APT_HIDDEN pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
756 /** \brief If \b true, debugging output will be written to
761 /** \brief description of the file being downloaded. */
762 std::string Description
;
764 /** \brief information about the current patch */
765 struct DiffInfo
const patch
;
767 /** \brief list of all download items for the patches */
768 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
770 /** The current status of this patch. */
773 /** \brief The diff is currently being fetched. */
776 /** \brief The diff is currently being applied. */
779 /** \brief the work with this diff is done */
782 /** \brief something bad happened and fallback was triggered */
787 /** \brief Called when the patch file failed to be downloaded.
789 * This method will fall back to downloading the whole index file
790 * outright; its arguments are ignored.
792 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
793 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
794 pkgAcquire::MethodConfig
*Cnf
);
795 virtual std::string
DescURI() {return RealURI
+ "Index";};
797 /** \brief Create an index merge-diff item.
799 * \param Owner The pkgAcquire object that owns this item.
801 * \param URI The URI of the package index file being
804 * \param URIDesc A long description of this item.
806 * \param ShortDesc A brief description of this item.
808 * \param ExpectedHashes The expected md5sum of the completely
809 * reconstructed package index file; the index file will be tested
810 * against this value when it is entirely reconstructed.
812 * \param patch contains infos about the patch this item is supposed
813 * to download which were read from the index
815 * \param allPatches contains all related items so that each item can
816 * check if it was the last one to complete the download step
818 pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
819 pkgAcqMetaBase
*TransactionManager
,
820 struct IndexTarget
const * const Target
,
821 HashStringList
const &ExpectedHash
,
822 indexRecords
*MetaIndexParser
,
823 DiffInfo
const &patch
,
824 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
827 /** \brief An item that is responsible for fetching server-merge patches {{{
828 * that need to be applied to a given package index file.
830 * After downloading and applying a single patch, this item will
831 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
832 * patches. If no patch can be found that applies to an intermediate
833 * file or if one of the patches cannot be downloaded, falls back to
834 * downloading the entire package index file using pkgAcqIndex.
836 * \sa pkgAcqDiffIndex, pkgAcqIndex
838 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
844 /** \brief Queue up the next diff download.
846 * Search for the next available diff that applies to the file
847 * that currently exists on disk, and enqueue it by calling
850 * \return \b true if an applicable diff was found, \b false
853 APT_HIDDEN
bool QueueNextDiff();
855 /** \brief Handle tasks that must be performed after the item
856 * finishes downloading.
858 * Dequeues the item and checks the resulting file's hashsums
859 * against ExpectedHashes after the last patch was applied.
860 * There is no need to check the md5/sha1 after a "normal"
861 * patch because QueueNextDiff() will check the sha1 later.
863 * \param allDone If \b true, the file was entirely reconstructed,
864 * and its md5sum is verified.
866 APT_HIDDEN
void Finish(bool allDone
=false);
870 /** \brief If \b true, debugging output will be written to
875 /** A description of the file being downloaded. */
876 std::string Description
;
878 /** The patches that remain to be downloaded, including the patch
879 * being downloaded right now. This list should be ordered so
880 * that each diff appears before any diff that depends on it.
882 * \todo These are indexed by sha1sum; why not use some sort of
883 * dictionary instead of relying on ordering and stripping them
886 std::vector
<DiffInfo
> available_patches
;
888 /** The current status of this patch. */
891 /** \brief The diff is in an unknown state. */
894 /** \brief The diff is currently being fetched. */
897 /** \brief The diff is currently being uncompressed. */
898 StateUnzipDiff
, // FIXME: No longer used
900 /** \brief The diff is currently being applied. */
906 /** \brief Called when the patch file failed to be downloaded.
908 * This method will fall back to downloading the whole index file
909 * outright; its arguments are ignored.
911 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
913 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
914 pkgAcquire::MethodConfig
*Cnf
);
915 virtual std::string
DescURI() {return RealURI
+ "IndexDiffs";};
917 /** \brief Create an index diff item.
919 * After filling in its basic fields, this invokes Finish(true) if
920 * \a diffs is empty, or QueueNextDiff() otherwise.
922 * \param Owner The pkgAcquire object that owns this item.
924 * \param URI The URI of the package index file being
927 * \param URIDesc A long description of this item.
929 * \param ShortDesc A brief description of this item.
931 * \param ExpectedHashes The expected hashsums of the completely
932 * reconstructed package index file; the index file will be tested
933 * against this value when it is entirely reconstructed.
935 * \param diffs The remaining diffs from the index of diffs. They
936 * should be ordered so that each diff appears before any diff
937 * that depends on it.
939 pkgAcqIndexDiffs(pkgAcquire
*Owner
,
940 pkgAcqMetaBase
*TransactionManager
,
941 struct IndexTarget
const * const Target
,
942 HashStringList
const &ExpectedHash
,
943 indexRecords
*MetaIndexParser
,
944 std::vector
<DiffInfo
> diffs
=std::vector
<DiffInfo
>());
947 /** \brief An acquire item that is responsible for fetching an index {{{
948 * file (e.g., Packages or Sources).
950 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
952 * \todo Why does pkgAcqIndex have protected members?
954 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
960 /** \brief The stages the method goes through
962 * The method first downloads the indexfile, then its decompressed (or
963 * copied) and verified
967 STAGE_DECOMPRESS_AND_VERIFY
,
971 /** \brief Handle what needs to be done when the download is done */
972 void StageDownloadDone(std::string Message
,
973 HashStringList
const &Hashes
,
974 pkgAcquire::MethodConfig
*Cfg
);
976 /** \brief Handle what needs to be done when the decompression/copy is
979 void StageDecompressDone(std::string Message
,
980 HashStringList
const &Hashes
,
981 pkgAcquire::MethodConfig
*Cfg
);
983 /** \brief If \b set, this partially downloaded file will be
984 * removed when the download completes.
986 std::string EraseFileName
;
988 /** \brief The compression-related file extensions that are being
989 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
991 std::string CompressionExtensions
;
993 /** \brief The actual compression extension currently used */
994 std::string CurrentCompressionExtension
;
996 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
997 void InitByHashIfNeeded(const std::string MetaKey
);
999 /** \brief Auto select the right compression to use */
1000 void AutoSelectCompression();
1002 /** \brief Get the full pathname of the final file for the current URI
1004 std::string
GetFinalFilename() const;
1006 /** \brief Schedule file for verification after a IMS hit */
1007 void ReverifyAfterIMS();
1009 /** \brief Validate the downloaded index file */
1010 bool ValidateFile(const std::string
&FileName
);
1014 // Specialized action members
1015 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1016 virtual void Done(std::string Message
,unsigned long long Size
,
1017 HashStringList
const &Hashes
,
1018 pkgAcquire::MethodConfig
*Cnf
);
1019 #if APT_PKG_ABI >= 413
1020 virtual std::string
Custom600Headers() const;
1022 virtual std::string
Custom600Headers();
1024 virtual std::string
DescURI() {return Desc
.URI
;};
1026 /** \brief Create a pkgAcqIndex.
1028 * \param Owner The pkgAcquire object with which this item is
1031 * \param URI The URI of the index file that is to be downloaded.
1033 * \param URIDesc A "URI-style" description of this index file.
1035 * \param ShortDesc A brief description of this index file.
1037 * \param ExpectedHashes The expected hashsum of this index file.
1039 * \param compressExt The compression-related extension with which
1040 * this index file should be downloaded, or "" to autodetect
1041 * Compression types can be set with config Acquire::CompressionTypes,
1042 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1043 * fallback is ".gz" or none.
1045 pkgAcqIndex(pkgAcquire
*Owner
,std::string URI
,std::string URIDesc
,
1046 std::string ShortDesc
, HashStringList
const &ExpectedHashes
);
1047 pkgAcqIndex(pkgAcquire
*Owner
, pkgAcqMetaBase
*TransactionManager
,
1048 IndexTarget
const * const Target
,
1049 HashStringList
const &ExpectedHash
,
1050 indexRecords
*MetaIndexParser
);
1052 void Init(std::string
const &URI
, std::string
const &URIDesc
,
1053 std::string
const &ShortDesc
);
1056 /** \brief Information about an index file. */ /*{{{*/
1057 class APT_HIDDEN IndexTarget
1062 /** \brief A URI from which the index file can be downloaded. */
1065 /** \brief A description of the index file. */
1066 std::string Description
;
1068 /** \brief A shorter description of the index file. */
1069 std::string ShortDesc
;
1071 /** \brief The key by which this index file should be
1072 * looked up within the meta signature file.
1074 std::string MetaKey
;
1076 virtual bool IsOptional() const {
1081 /** \brief Information about an optional index file. */ /*{{{*/
1082 class APT_HIDDEN OptionalIndexTarget
: public IndexTarget
1086 virtual bool IsOptional() const {
1091 /** \brief An item that is responsible for fetching a package file. {{{
1093 * If the package file already exists in the cache, nothing will be
1096 class pkgAcqArchive
: public pkgAcquire::Item
1101 /** \brief The package version being fetched. */
1102 pkgCache::VerIterator Version
;
1104 /** \brief The list of sources from which to pick archives to
1105 * download this package from.
1107 pkgSourceList
*Sources
;
1109 /** \brief A package records object, used to look up the file
1110 * corresponding to each version of the package.
1114 /** \brief A location in which the actual filename of the package
1117 std::string
&StoreFilename
;
1119 /** \brief The next file for this version to try to download. */
1120 pkgCache::VerFileIterator Vf
;
1122 /** \brief How many (more) times to try to find a new source from
1123 * which to download this package version if it fails.
1125 * Set from Acquire::Retries.
1127 unsigned int Retries
;
1129 /** \brief \b true if this version file is being downloaded from a
1134 /** \brief Queue up the next available file for this version. */
1139 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1140 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
1141 pkgAcquire::MethodConfig
*Cnf
);
1142 virtual std::string
DescURI() {return Desc
.URI
;};
1143 virtual std::string
ShortDesc() {return Desc
.ShortDesc
;};
1144 virtual void Finished();
1145 #if APT_PKG_ABI >= 413
1146 virtual bool IsTrusted() const;
1148 virtual bool IsTrusted();
1151 /** \brief Create a new pkgAcqArchive.
1153 * \param Owner The pkgAcquire object with which this item is
1156 * \param Sources The sources from which to download version
1159 * \param Recs A package records object, used to look up the file
1160 * corresponding to each version of the package.
1162 * \param Version The package version to download.
1164 * \param[out] StoreFilename A location in which the actual filename of
1165 * the package should be stored. It will be set to a guessed
1166 * basename in the constructor, and filled in with a fully
1167 * qualified filename once the download finishes.
1169 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1170 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1171 std::string
&StoreFilename
);
1174 /** \brief Retrieve an arbitrary file to the current directory. {{{
1176 * The file is retrieved even if it is accessed via a URL type that
1177 * normally is a NOP, such as "file". If the download fails, the
1178 * partial file is renamed to get a ".FAILED" extension.
1180 class pkgAcqFile
: public pkgAcquire::Item
1184 /** \brief How many times to retry the download, set from
1187 unsigned int Retries
;
1189 /** \brief Should this file be considered a index file */
1194 // Specialized action members
1195 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1196 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &CalcHashes
,
1197 pkgAcquire::MethodConfig
*Cnf
);
1198 virtual std::string
DescURI() {return Desc
.URI
;};
1199 #if APT_PKG_ABI >= 413
1200 virtual std::string
Custom600Headers() const;
1202 virtual std::string
Custom600Headers();
1205 /** \brief Create a new pkgAcqFile object.
1207 * \param Owner The pkgAcquire object with which this object is
1210 * \param URI The URI to download.
1212 * \param Hashes The hashsums of the file to download, if they are known;
1213 * otherwise empty list.
1215 * \param Size The size of the file to download, if it is known;
1218 * \param Desc A description of the file being downloaded.
1220 * \param ShortDesc A brief description of the file being
1223 * \param DestDir The directory the file should be downloaded into.
1225 * \param DestFilename The filename+path the file is downloaded to.
1227 * \param IsIndexFile The file is considered a IndexFile and cache-control
1228 * headers like "cache-control: max-age=0" are send
1230 * If DestFilename is empty, download to DestDir/\<basename\> if
1231 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1232 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1233 * is the absolute name to which the file should be downloaded.
1236 pkgAcqFile(pkgAcquire
*Owner
, std::string URI
, HashStringList
const &Hashes
, unsigned long long Size
,
1237 std::string Desc
, std::string ShortDesc
,
1238 const std::string
&DestDir
="", const std::string
&DestFilename
="",
1239 bool IsIndexFile
=false);