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 virtual std::string
Custom600Headers() const {return std::string();};
259 /** \brief A "descriptive" URI-like string.
261 * \return a URI that should be used to describe what is being fetched.
263 virtual std::string
DescURI() = 0;
264 /** \brief Short item description.
266 * \return a brief description of the object being fetched.
268 virtual std::string
ShortDesc() {return DescURI();}
270 /** \brief Invoked by the worker when the download is completely done. */
271 virtual void Finished() {};
275 * \return the HashSums of this object, if applicable; otherwise, an
278 HashStringList
HashSums() const {return ExpectedHashes
;};
279 std::string
HashSum() const {HashStringList
const hashes
= HashSums(); HashString
const * const hs
= hashes
.find(NULL
); return hs
!= NULL
? hs
->toStr() : ""; };
281 /** \return the acquire process with which this item is associated. */
282 pkgAcquire
*GetOwner() const {return Owner
;};
284 /** \return \b true if this object is being fetched from a trusted source. */
285 virtual bool IsTrusted() const {return false;};
287 /** \brief Report mirror problem
289 * This allows reporting mirror failures back to a centralized
290 * server. The apt-report-mirror-failure script is called for this
292 * \param FailCode A short failure string that is send
294 void ReportMirrorFailure(std::string FailCode
);
296 /** \brief Set the name of the current active subprocess
298 * See also #ActiveSubprocess
300 void SetActiveSubprocess(const std::string
&subprocess
);
302 /** \brief Initialize an item.
304 * Adds the item to the list of items known to the acquire
305 * process, but does not place it into any fetch queues (you must
306 * manually invoke QueueURI() to do so).
308 * \param Owner The new owner of this item.
309 * \param ExpectedHashes of the file represented by this item
311 Item(pkgAcquire
*Owner
,
312 HashStringList
const &ExpectedHashes
=HashStringList(),
313 pkgAcqMetaBase
*TransactionManager
=NULL
);
315 /** \brief Remove this item from its owner's queue by invoking
316 * pkgAcquire::Remove.
322 enum RenameOnErrorState
{
331 /** \brief Rename failed file and set error
333 * \param state respresenting the error we encountered
335 bool RenameOnError(RenameOnErrorState
const state
);
337 /** \brief The HashSums of the item is supposed to have than done */
338 HashStringList ExpectedHashes
;
340 /** \brief The item that is currently being downloaded. */
341 pkgAcquire::ItemDesc Desc
;
344 /** \brief Information about an index patch (aka diff). */ /*{{{*/
346 /** The filename of the diff. */
349 /** The hashes of the diff */
350 HashStringList result_hashes
;
352 /** The hashes of the file after the diff is applied */
353 HashStringList patch_hashes
;
355 /** The size of the file after the diff is applied */
356 unsigned long long result_size
;
358 /** The size of the diff itself */
359 unsigned long long patch_size
;
364 class pkgAcqMetaBase
: public pkgAcquire::Item
369 std::vector
<Item
*> Transaction
;
371 /** \brief A package-system-specific parser for the meta-index file. */
372 indexRecords
*MetaIndexParser
;
374 /** \brief The index files which should be looked up in the meta-index
375 * and then downloaded.
377 const std::vector
<IndexTarget
*>* IndexTargets
;
379 /** \brief If \b true, the index's signature is currently being verified.
383 // required to deal gracefully with problems caused by incorrect ims hits
386 /** \brief Starts downloading the individual index files.
388 * \param verify If \b true, only indices whose expected hashsum
389 * can be determined from the meta-index will be downloaded, and
390 * the hashsums of indices will be checked (reporting
391 * #StatAuthError if there is a mismatch). If verify is \b false,
392 * no hashsum checking will be performed.
394 void QueueIndexes(bool verify
);
396 /** \brief Called when a file is finished being retrieved.
398 * If the file was not downloaded to DestFile, a copy process is
399 * set up to copy it to DestFile; otherwise, Complete is set to \b
400 * true and the file is moved to its final location.
402 * \param Message The message block received from the fetch
405 bool CheckDownloadDone(const std::string
&Message
,
406 const std::string
&RealURI
);
408 /** \brief Queue the downloaded Signature for verification */
409 void QueueForSignatureVerify(const std::string
&MetaIndexFile
,
410 const std::string
&MetaIndexFileSignature
);
412 /** \brief get the custom600 header for all pkgAcqMeta */
413 std::string
GetCustom600Headers(const std::string
&RealURI
) const;
415 /** \brief Called when authentication succeeded.
417 * Sanity-checks the authenticated file, queues up the individual
418 * index files for download, and saves the signature in the lists
419 * directory next to the authenticated list file.
421 * \param Message The message block received from the fetch
424 bool CheckAuthDone(std::string Message
, const std::string
&RealURI
);
426 /** Check if the current item should fail at this point */
427 bool CheckStopAuthentication(const std::string
&RealURI
,
428 const std::string
&Message
);
430 /** \brief Check that the release file is a release file for the
431 * correct distribution.
433 * \return \b true if no fatal errors were encountered.
435 bool VerifyVendor(std::string Message
, const std::string
&RealURI
);
440 void AbortTransaction();
441 bool TransactionHasError() APT_PURE
;
442 void CommitTransaction();
444 /** \brief Stage (queue) a copy action when the transaction is commited
446 void TransactionStageCopy(Item
*I
,
447 const std::string
&From
,
448 const std::string
&To
);
449 /** \brief Stage (queue) a removal action when the transaction is commited
451 void TransactionStageRemoval(Item
*I
, const std::string
&FinalFile
);
453 pkgAcqMetaBase(pkgAcquire
*Owner
,
454 const std::vector
<IndexTarget
*>* IndexTargets
,
455 indexRecords
* MetaIndexParser
,
456 HashStringList
const &ExpectedHashes
=HashStringList(),
457 pkgAcqMetaBase
*TransactionManager
=NULL
)
458 : Item(Owner
, ExpectedHashes
, TransactionManager
),
459 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
),
460 AuthPass(false), IMSHit(false) {};
463 /** \brief An acquire item that downloads the detached signature {{{
464 * of a meta-index (Release) file, then queues up the release
467 * \todo Why protected members?
469 * \sa pkgAcqMetaIndex
471 class pkgAcqMetaSig
: public pkgAcqMetaBase
477 /** \brief The URI of the signature file. Unlike Desc.URI, this is
478 * never modified; it is used to determine the file that is being
483 /** \brief The file we need to verify */
484 std::string MetaIndexFile
;
486 /** \brief The file we use to verify the MetaIndexFile with */
487 std::string MetaIndexFileSignature
;
489 /** \brief Long URI description used in the acquire system */
492 /** \brief Short URI description used in the acquire system */
493 std::string ShortDesc
;
497 // Specialized action members
498 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
499 virtual void Done(std::string Message
,unsigned long long Size
,
500 HashStringList
const &Hashes
,
501 pkgAcquire::MethodConfig
*Cnf
);
502 virtual std::string
Custom600Headers() const;
503 virtual std::string
DescURI() {return RealURI
; };
505 /** \brief Create a new pkgAcqMetaSig. */
506 pkgAcqMetaSig(pkgAcquire
*Owner
,
507 pkgAcqMetaBase
*TransactionManager
,
508 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
509 std::string MetaIndexFile
,
510 const std::vector
<IndexTarget
*>* IndexTargets
,
511 indexRecords
* MetaIndexParser
);
512 virtual ~pkgAcqMetaSig();
516 /** \brief An item that is responsible for downloading the meta-index {{{
517 * file (i.e., Release) itself and verifying its signature.
519 * Once the download and verification are complete, the downloads of
520 * the individual index files are queued up using pkgAcqDiffIndex.
521 * If the meta-index file had a valid signature, the expected hashsums
522 * of the index files will be the md5sums listed in the meta-index;
523 * otherwise, the expected hashsums will be "" (causing the
524 * authentication of the index files to be bypassed).
526 class pkgAcqMetaIndex
: public pkgAcqMetaBase
531 /** \brief The URI that is actually being downloaded; never
532 * modified by pkgAcqMetaIndex.
537 std::string ShortDesc
;
539 /** \brief The URI of the meta-index file for the detached signature */
540 std::string MetaIndexSigURI
;
542 /** \brief A "URI-style" description of the meta-index file */
543 std::string MetaIndexSigURIDesc
;
545 /** \brief A brief description of the meta-index file */
546 std::string MetaIndexSigShortDesc
;
548 /** \brief delayed constructor */
549 void Init(std::string URIDesc
, std::string ShortDesc
);
553 // Specialized action members
554 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
555 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
556 pkgAcquire::MethodConfig
*Cnf
);
557 virtual std::string
Custom600Headers() const;
558 virtual std::string
DescURI() {return RealURI
; };
559 virtual void Finished();
561 /** \brief Create a new pkgAcqMetaIndex. */
562 pkgAcqMetaIndex(pkgAcquire
*Owner
,
563 pkgAcqMetaBase
*TransactionManager
,
564 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
565 std::string MetaIndexSigURI
, std::string MetaIndexSigURIDesc
, std::string MetaIndexSigShortDesc
,
566 const std::vector
<IndexTarget
*>* IndexTargets
,
567 indexRecords
* MetaIndexParser
);
570 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
571 class pkgAcqMetaClearSig
: public pkgAcqMetaIndex
575 /** \brief The URI of the meta-index file for the detached signature */
576 std::string MetaIndexURI
;
578 /** \brief A "URI-style" description of the meta-index file */
579 std::string MetaIndexURIDesc
;
581 /** \brief A brief description of the meta-index file */
582 std::string MetaIndexShortDesc
;
584 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
585 std::string MetaSigURI
;
587 /** \brief A "URI-style" description of the meta-signature file */
588 std::string MetaSigURIDesc
;
590 /** \brief A brief description of the meta-signature file */
591 std::string MetaSigShortDesc
;
594 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
595 virtual std::string
Custom600Headers() const;
596 virtual void Done(std::string Message
,unsigned long long Size
,
597 HashStringList
const &Hashes
,
598 pkgAcquire::MethodConfig
*Cnf
);
600 /** \brief Create a new pkgAcqMetaClearSig. */
601 pkgAcqMetaClearSig(pkgAcquire
*Owner
,
602 std::string
const &URI
, std::string
const &URIDesc
, std::string
const &ShortDesc
,
603 std::string
const &MetaIndexURI
, std::string
const &MetaIndexURIDesc
, std::string
const &MetaIndexShortDesc
,
604 std::string
const &MetaSigURI
, std::string
const &MetaSigURIDesc
, std::string
const &MetaSigShortDesc
,
605 const std::vector
<IndexTarget
*>* IndexTargets
,
606 indexRecords
* MetaIndexParser
);
607 virtual ~pkgAcqMetaClearSig();
612 /** \brief Common base class for all classes that deal with fetching {{{
615 class pkgAcqBaseIndex
: public pkgAcquire::Item
620 /** \brief Pointer to the IndexTarget data
622 const struct IndexTarget
* Target
;
624 /** \brief Pointer to the indexRecords parser */
625 indexRecords
*MetaIndexParser
;
627 /** \brief The MetaIndex Key */
630 /** \brief The URI of the index file to recreate at our end (either
631 * by downloading it or by applying partial patches).
635 bool VerifyHashByMetaKey(HashStringList
const &Hashes
);
637 pkgAcqBaseIndex(pkgAcquire
*Owner
,
638 pkgAcqMetaBase
*TransactionManager
,
639 struct IndexTarget
const * const Target
,
640 HashStringList
const &ExpectedHashes
,
641 indexRecords
*MetaIndexParser
)
642 : Item(Owner
, ExpectedHashes
, TransactionManager
), Target(Target
),
643 MetaIndexParser(MetaIndexParser
) {};
646 /** \brief An item that is responsible for fetching an index file of {{{
647 * package list diffs and starting the package list's download.
649 * This item downloads the Index file and parses it, then enqueues
650 * additional downloads of either the individual patches (using
651 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
653 * \sa pkgAcqIndexDiffs, pkgAcqIndex
655 class pkgAcqDiffIndex
: public pkgAcqBaseIndex
660 /** \brief If \b true, debugging information will be written to std::clog. */
663 /** \brief The index file which will be patched to generate the new
666 std::string CurrentPackagesFile
;
668 /** \brief A description of the Packages file (stored in
669 * pkgAcquire::ItemDesc::Description).
671 std::string Description
;
673 /** \brief If the copy step of the packages file is done
675 bool PackagesFileReadyInPartial
;
678 // Specialized action members
679 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
680 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
681 pkgAcquire::MethodConfig
*Cnf
);
682 virtual std::string
DescURI() {return RealURI
+ "Index";};
683 virtual std::string
Custom600Headers() const;
685 /** \brief Parse the Index file for a set of Packages diffs.
687 * Parses the Index file and creates additional download items as
690 * \param IndexDiffFile The name of the Index file.
692 * \return \b true if the Index file was successfully parsed, \b
695 bool ParseDiffIndex(std::string IndexDiffFile
);
698 /** \brief Create a new pkgAcqDiffIndex.
700 * \param Owner The Acquire object that owns this item.
702 * \param URI The URI of the list file to download.
704 * \param URIDesc A long description of the list file to download.
706 * \param ShortDesc A short description of the list file to download.
708 * \param ExpectedHashes The list file's hashsums which are expected.
710 pkgAcqDiffIndex(pkgAcquire
*Owner
,
711 pkgAcqMetaBase
*TransactionManager
,
712 struct IndexTarget
const * const Target
,
713 HashStringList
const &ExpectedHashes
,
714 indexRecords
*MetaIndexParser
);
717 /** \brief An item that is responsible for fetching client-merge patches {{{
718 * that need to be applied to a given package index file.
720 * Instead of downloading and applying each patch one by one like its
721 * sister #pkgAcqIndexDiffs this class will download all patches at once
722 * and call rred with all the patches downloaded once. Rred will then
723 * merge and apply them in one go, which should be a lot faster – but is
724 * incompatible with server-based merges of patches like reprepro can do.
726 * \sa pkgAcqDiffIndex, pkgAcqIndex
728 class pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
734 /** \brief If \b true, debugging output will be written to
739 /** \brief description of the file being downloaded. */
740 std::string Description
;
742 /** \brief information about the current patch */
743 struct DiffInfo
const patch
;
745 /** \brief list of all download items for the patches */
746 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
748 /** The current status of this patch. */
751 /** \brief The diff is currently being fetched. */
754 /** \brief The diff is currently being applied. */
757 /** \brief the work with this diff is done */
760 /** \brief something bad happened and fallback was triggered */
765 /** \brief Called when the patch file failed to be downloaded.
767 * This method will fall back to downloading the whole index file
768 * outright; its arguments are ignored.
770 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
771 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
772 pkgAcquire::MethodConfig
*Cnf
);
773 virtual std::string
DescURI() {return RealURI
+ "Index";};
775 /** \brief Create an index merge-diff item.
777 * \param Owner The pkgAcquire object that owns this item.
779 * \param URI The URI of the package index file being
782 * \param URIDesc A long description of this item.
784 * \param ShortDesc A brief description of this item.
786 * \param ExpectedHashes The expected md5sum of the completely
787 * reconstructed package index file; the index file will be tested
788 * against this value when it is entirely reconstructed.
790 * \param patch contains infos about the patch this item is supposed
791 * to download which were read from the index
793 * \param allPatches contains all related items so that each item can
794 * check if it was the last one to complete the download step
796 pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
797 pkgAcqMetaBase
*TransactionManager
,
798 struct IndexTarget
const * const Target
,
799 HashStringList
const &ExpectedHash
,
800 indexRecords
*MetaIndexParser
,
801 DiffInfo
const &patch
,
802 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
805 /** \brief An item that is responsible for fetching server-merge patches {{{
806 * that need to be applied to a given package index file.
808 * After downloading and applying a single patch, this item will
809 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
810 * patches. If no patch can be found that applies to an intermediate
811 * file or if one of the patches cannot be downloaded, falls back to
812 * downloading the entire package index file using pkgAcqIndex.
814 * \sa pkgAcqDiffIndex, pkgAcqIndex
816 class pkgAcqIndexDiffs
: public pkgAcqBaseIndex
822 /** \brief Queue up the next diff download.
824 * Search for the next available diff that applies to the file
825 * that currently exists on disk, and enqueue it by calling
828 * \return \b true if an applicable diff was found, \b false
831 APT_HIDDEN
bool QueueNextDiff();
833 /** \brief Handle tasks that must be performed after the item
834 * finishes downloading.
836 * Dequeues the item and checks the resulting file's hashsums
837 * against ExpectedHashes after the last patch was applied.
838 * There is no need to check the md5/sha1 after a "normal"
839 * patch because QueueNextDiff() will check the sha1 later.
841 * \param allDone If \b true, the file was entirely reconstructed,
842 * and its md5sum is verified.
844 APT_HIDDEN
void Finish(bool allDone
=false);
848 /** \brief If \b true, debugging output will be written to
853 /** A description of the file being downloaded. */
854 std::string Description
;
856 /** The patches that remain to be downloaded, including the patch
857 * being downloaded right now. This list should be ordered so
858 * that each diff appears before any diff that depends on it.
860 * \todo These are indexed by sha1sum; why not use some sort of
861 * dictionary instead of relying on ordering and stripping them
864 std::vector
<DiffInfo
> available_patches
;
866 /** The current status of this patch. */
869 /** \brief The diff is in an unknown state. */
872 /** \brief The diff is currently being fetched. */
875 /** \brief The diff is currently being uncompressed. */
876 StateUnzipDiff
, // FIXME: No longer used
878 /** \brief The diff is currently being applied. */
884 /** \brief Called when the patch file failed to be downloaded.
886 * This method will fall back to downloading the whole index file
887 * outright; its arguments are ignored.
889 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
891 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
892 pkgAcquire::MethodConfig
*Cnf
);
893 virtual std::string
DescURI() {return RealURI
+ "IndexDiffs";};
895 /** \brief Create an index diff item.
897 * After filling in its basic fields, this invokes Finish(true) if
898 * \a diffs is empty, or QueueNextDiff() otherwise.
900 * \param Owner The pkgAcquire object that owns this item.
902 * \param URI The URI of the package index file being
905 * \param URIDesc A long description of this item.
907 * \param ShortDesc A brief description of this item.
909 * \param ExpectedHashes The expected hashsums of the completely
910 * reconstructed package index file; the index file will be tested
911 * against this value when it is entirely reconstructed.
913 * \param diffs The remaining diffs from the index of diffs. They
914 * should be ordered so that each diff appears before any diff
915 * that depends on it.
917 pkgAcqIndexDiffs(pkgAcquire
*Owner
,
918 pkgAcqMetaBase
*TransactionManager
,
919 struct IndexTarget
const * const Target
,
920 HashStringList
const &ExpectedHash
,
921 indexRecords
*MetaIndexParser
,
922 std::vector
<DiffInfo
> diffs
=std::vector
<DiffInfo
>());
925 /** \brief An acquire item that is responsible for fetching an index {{{
926 * file (e.g., Packages or Sources).
928 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
930 * \todo Why does pkgAcqIndex have protected members?
932 class pkgAcqIndex
: public pkgAcqBaseIndex
938 /** \brief The stages the method goes through
940 * The method first downloads the indexfile, then its decompressed (or
941 * copied) and verified
945 STAGE_DECOMPRESS_AND_VERIFY
,
949 /** \brief Handle what needs to be done when the download is done */
950 void StageDownloadDone(std::string Message
,
951 HashStringList
const &Hashes
,
952 pkgAcquire::MethodConfig
*Cfg
);
954 /** \brief Handle what needs to be done when the decompression/copy is
957 void StageDecompressDone(std::string Message
,
958 HashStringList
const &Hashes
,
959 pkgAcquire::MethodConfig
*Cfg
);
961 /** \brief If \b set, this partially downloaded file will be
962 * removed when the download completes.
964 std::string EraseFileName
;
966 /** \brief The compression-related file extensions that are being
967 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
969 std::string CompressionExtensions
;
971 /** \brief The actual compression extension currently used */
972 std::string CurrentCompressionExtension
;
974 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
975 void InitByHashIfNeeded(const std::string MetaKey
);
977 /** \brief Auto select the right compression to use */
978 void AutoSelectCompression();
980 /** \brief Get the full pathname of the final file for the current URI
982 std::string
GetFinalFilename() const;
984 /** \brief Schedule file for verification after a IMS hit */
985 void ReverifyAfterIMS();
987 /** \brief Validate the downloaded index file */
988 bool ValidateFile(const std::string
&FileName
);
992 // Specialized action members
993 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
994 virtual void Done(std::string Message
,unsigned long long Size
,
995 HashStringList
const &Hashes
,
996 pkgAcquire::MethodConfig
*Cnf
);
997 virtual std::string
Custom600Headers() const;
998 virtual std::string
DescURI() {return Desc
.URI
;};
1000 /** \brief Create a pkgAcqIndex.
1002 * \param Owner The pkgAcquire object with which this item is
1005 * \param URI The URI of the index file that is to be downloaded.
1007 * \param URIDesc A "URI-style" description of this index file.
1009 * \param ShortDesc A brief description of this index file.
1011 * \param ExpectedHashes The expected hashsum of this index file.
1013 * \param compressExt The compression-related extension with which
1014 * this index file should be downloaded, or "" to autodetect
1015 * Compression types can be set with config Acquire::CompressionTypes,
1016 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1017 * fallback is ".gz" or none.
1019 pkgAcqIndex(pkgAcquire
*Owner
,std::string URI
,std::string URIDesc
,
1020 std::string ShortDesc
, HashStringList
const &ExpectedHashes
);
1021 pkgAcqIndex(pkgAcquire
*Owner
, pkgAcqMetaBase
*TransactionManager
,
1022 IndexTarget
const * const Target
,
1023 HashStringList
const &ExpectedHash
,
1024 indexRecords
*MetaIndexParser
);
1026 void Init(std::string
const &URI
, std::string
const &URIDesc
,
1027 std::string
const &ShortDesc
);
1030 /** \brief Information about an index file. */ /*{{{*/
1036 /** \brief A URI from which the index file can be downloaded. */
1039 /** \brief A description of the index file. */
1040 std::string Description
;
1042 /** \brief A shorter description of the index file. */
1043 std::string ShortDesc
;
1045 /** \brief The key by which this index file should be
1046 * looked up within the meta signature file.
1048 std::string MetaKey
;
1050 virtual bool IsOptional() const {
1055 /** \brief Information about an optional index file. */ /*{{{*/
1056 class OptionalIndexTarget
: public IndexTarget
1060 virtual bool IsOptional() const {
1065 /** \brief An item that is responsible for fetching a package file. {{{
1067 * If the package file already exists in the cache, nothing will be
1070 class pkgAcqArchive
: public pkgAcquire::Item
1075 /** \brief The package version being fetched. */
1076 pkgCache::VerIterator Version
;
1078 /** \brief The list of sources from which to pick archives to
1079 * download this package from.
1081 pkgSourceList
*Sources
;
1083 /** \brief A package records object, used to look up the file
1084 * corresponding to each version of the package.
1088 /** \brief A location in which the actual filename of the package
1091 std::string
&StoreFilename
;
1093 /** \brief The next file for this version to try to download. */
1094 pkgCache::VerFileIterator Vf
;
1096 /** \brief How many (more) times to try to find a new source from
1097 * which to download this package version if it fails.
1099 * Set from Acquire::Retries.
1101 unsigned int Retries
;
1103 /** \brief \b true if this version file is being downloaded from a
1108 /** \brief Queue up the next available file for this version. */
1113 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1114 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
1115 pkgAcquire::MethodConfig
*Cnf
);
1116 virtual std::string
DescURI() {return Desc
.URI
;};
1117 virtual std::string
ShortDesc() {return Desc
.ShortDesc
;};
1118 virtual void Finished();
1119 virtual bool IsTrusted() const;
1121 /** \brief Create a new pkgAcqArchive.
1123 * \param Owner The pkgAcquire object with which this item is
1126 * \param Sources The sources from which to download version
1129 * \param Recs A package records object, used to look up the file
1130 * corresponding to each version of the package.
1132 * \param Version The package version to download.
1134 * \param[out] StoreFilename A location in which the actual filename of
1135 * the package should be stored. It will be set to a guessed
1136 * basename in the constructor, and filled in with a fully
1137 * qualified filename once the download finishes.
1139 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1140 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1141 std::string
&StoreFilename
);
1144 /** \brief Retrieve an arbitrary file to the current directory. {{{
1146 * The file is retrieved even if it is accessed via a URL type that
1147 * normally is a NOP, such as "file". If the download fails, the
1148 * partial file is renamed to get a ".FAILED" extension.
1150 class pkgAcqFile
: public pkgAcquire::Item
1154 /** \brief How many times to retry the download, set from
1157 unsigned int Retries
;
1159 /** \brief Should this file be considered a index file */
1164 // Specialized action members
1165 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1166 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &CalcHashes
,
1167 pkgAcquire::MethodConfig
*Cnf
);
1168 virtual std::string
DescURI() {return Desc
.URI
;};
1169 virtual std::string
Custom600Headers() const;
1171 /** \brief Create a new pkgAcqFile object.
1173 * \param Owner The pkgAcquire object with which this object is
1176 * \param URI The URI to download.
1178 * \param Hashes The hashsums of the file to download, if they are known;
1179 * otherwise empty list.
1181 * \param Size The size of the file to download, if it is known;
1184 * \param Desc A description of the file being downloaded.
1186 * \param ShortDesc A brief description of the file being
1189 * \param DestDir The directory the file should be downloaded into.
1191 * \param DestFilename The filename+path the file is downloaded to.
1193 * \param IsIndexFile The file is considered a IndexFile and cache-control
1194 * headers like "cache-control: max-age=0" are send
1196 * If DestFilename is empty, download to DestDir/\<basename\> if
1197 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1198 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1199 * is the absolute name to which the file should be downloaded.
1202 pkgAcqFile(pkgAcquire
*Owner
, std::string URI
, HashStringList
const &Hashes
, unsigned long long Size
,
1203 std::string Desc
, std::string ShortDesc
,
1204 const std::string
&DestDir
="", const std::string
&DestFilename
="",
1205 bool IsIndexFile
=false);