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
70 /** \brief The acquire object with which this item is associated. */
73 /** \brief Insert this item into its owner's queue.
75 * \param Item Metadata about this item (its URI and
78 void QueueURI(ItemDesc
&Item
);
80 /** \brief Remove this item from its owner's queue. */
83 /** \brief Rename a file without modifying its timestamp.
85 * Many item methods call this as their final action.
87 * \param From The file to be renamed.
89 * \param To The new name of \a From. If \a To exists it will be
92 bool Rename(std::string From
,std::string To
);
96 /** \brief The current status of this item. */
99 /** \brief The item is waiting to be downloaded. */
102 /** \brief The item is currently being downloaded. */
105 /** \brief The item has been successfully downloaded. */
108 /** \brief An error was encountered while downloading this
113 /** \brief The item was downloaded but its authenticity could
118 /** \brief The item was could not be downloaded because of
119 * a transient network error (e.g. network down)
121 StatTransientNetworkError
,
124 /** \brief Contains a textual description of the error encountered
125 * if #ItemState is #StatError or #StatAuthError.
127 std::string ErrorText
;
129 /** \brief The size of the object to fetch. */
130 unsigned long long FileSize
;
132 /** \brief How much of the object was already fetched. */
133 unsigned long long PartialSize
;
135 /** \brief If not \b NULL, contains the name of a subprocess that
136 * is operating on this object (for instance, "gzip" or "gpgv").
138 APT_DEPRECATED
const char *Mode
;
140 /** \brief contains the name of the subprocess that is operating on this object
141 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
142 * as it can manage the lifetime of included string properly. */
143 std::string ActiveSubprocess
;
145 /** \brief A client-supplied unique identifier.
147 * This field is initalized to 0; it is meant to be filled in by
148 * clients that wish to use it to uniquely identify items.
150 * \todo it's unused in apt itself
154 /** \brief If \b true, the entire object has been successfully fetched.
156 * Subclasses should set this to \b true when appropriate.
160 /** \brief If \b true, the URI of this object is "local".
162 * The only effect of this field is to exclude the object from the
163 * download progress indicator's overall statistics.
166 std::string UsedMirror
;
168 /** \brief The number of fetch queues into which this item has been
171 * There is one queue for each source from which an item could be
176 unsigned int QueueCounter
;
178 /** \brief TransactionManager */
179 pkgAcqMetaBase
*TransactionManager
;
181 /** \brief The number of additional fetch items that are expected
182 * once this item is done.
184 * Some items like pkgAcqMeta{Index,Sig} will queue additional
185 * items. This variable can be set by the methods if it knows
186 * in advance how many items to expect to get a more accurate
189 unsigned int ExpectedAdditionalItems
;
191 /** \brief The name of the file into which the retrieved object
194 std::string DestFile
;
196 /** \brief storge name until a transaction is finished */
197 std::string PartialFile
;
199 /** \brief Invoked by the acquire worker when the object couldn't
202 * This is a branch of the continuation of the fetch process.
204 * \param Message An RFC822-formatted message from the acquire
205 * method describing what went wrong. Use LookupTag() to parse
208 * \param Cnf The method via which the worker tried to fetch this object.
212 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
214 /** \brief Invoked by the acquire worker when the object was
215 * fetched successfully.
217 * Note that the object might \e not have been written to
218 * DestFile; check for the presence of an Alt-Filename entry in
219 * Message to find the file to which it was really written.
221 * Done is often used to switch from one stage of the processing
222 * to the next (e.g. fetching, unpacking, copying). It is one
223 * branch of the continuation of the fetch process.
225 * \param Message Data from the acquire method. Use LookupTag()
227 * \param Size The size of the object that was fetched.
228 * \param Hashes The HashSums of the object that was fetched.
229 * \param Cnf The method via which the object was fetched.
233 virtual void Done(std::string Message
, unsigned long long Size
, HashStringList
const &Hashes
,
234 pkgAcquire::MethodConfig
*Cnf
);
236 /** \brief Invoked when the worker starts to fetch this object.
238 * \param Message RFC822-formatted data from the worker process.
239 * Use LookupTag() to parse it.
241 * \param Size The size of the object being fetched.
245 virtual void Start(std::string Message
,unsigned long long Size
);
247 /** \brief Custom headers to be sent to the fetch process.
249 * \return a string containing RFC822-style headers that are to be
250 * inserted into the 600 URI Acquire message sent to the fetch
251 * subprocess. The headers are inserted after a newline-less
252 * line, so they should (if nonempty) have a leading newline and
253 * no trailing newline.
255 virtual std::string
Custom600Headers() const {return std::string();};
257 /** \brief A "descriptive" URI-like string.
259 * \return a URI that should be used to describe what is being fetched.
261 virtual std::string
DescURI() = 0;
262 /** \brief Short item description.
264 * \return a brief description of the object being fetched.
266 virtual std::string
ShortDesc() {return DescURI();}
268 /** \brief Invoked by the worker when the download is completely done. */
269 virtual void Finished() {};
273 * \return the HashSums of this object, if applicable; otherwise, an
276 HashStringList
HashSums() const {return ExpectedHashes
;};
277 std::string
HashSum() const {HashStringList
const hashes
= HashSums(); HashString
const * const hs
= hashes
.find(NULL
); return hs
!= NULL
? hs
->toStr() : ""; };
279 /** \return the acquire process with which this item is associated. */
280 pkgAcquire
*GetOwner() const {return Owner
;};
282 /** \return \b true if this object is being fetched from a trusted source. */
283 virtual bool IsTrusted() const {return false;};
285 /** \brief Report mirror problem
287 * This allows reporting mirror failures back to a centralized
288 * server. The apt-report-mirror-failure script is called for this
290 * \param FailCode A short failure string that is send
292 void ReportMirrorFailure(std::string FailCode
);
294 /** \brief Set the name of the current active subprocess
296 * See also #ActiveSubprocess
298 void SetActiveSubprocess(const std::string
&subprocess
);
300 /** \brief Initialize an item.
302 * Adds the item to the list of items known to the acquire
303 * process, but does not place it into any fetch queues (you must
304 * manually invoke QueueURI() to do so).
306 * \param Owner The new owner of this item.
307 * \param ExpectedHashes of the file represented by this item
309 Item(pkgAcquire
*Owner
,
310 HashStringList
const &ExpectedHashes
=HashStringList(),
311 pkgAcqMetaBase
*TransactionManager
=NULL
);
313 /** \brief Remove this item from its owner's queue by invoking
314 * pkgAcquire::Remove.
320 enum RenameOnErrorState
{
329 /** \brief Rename failed file and set error
331 * \param state respresenting the error we encountered
333 bool RenameOnError(RenameOnErrorState
const state
);
335 /** \brief The HashSums of the item is supposed to have than done */
336 HashStringList ExpectedHashes
;
338 /** \brief The item that is currently being downloaded. */
339 pkgAcquire::ItemDesc Desc
;
342 /** \brief Information about an index patch (aka diff). */ /*{{{*/
344 /** The filename of the diff. */
347 /** The hashes of the diff */
348 HashStringList result_hashes
;
350 /** The hashes of the file after the diff is applied */
351 HashStringList patch_hashes
;
353 /** The size of the file after the diff is applied */
354 unsigned long long result_size
;
356 /** The size of the diff itself */
357 unsigned long long patch_size
;
362 class pkgAcqMetaBase
: public pkgAcquire::Item
367 std::vector
<Item
*> Transaction
;
369 /** \brief A package-system-specific parser for the meta-index file. */
370 indexRecords
*MetaIndexParser
;
372 /** \brief The index files which should be looked up in the meta-index
373 * and then downloaded.
375 const std::vector
<IndexTarget
*>* IndexTargets
;
377 /** \brief If \b true, the index's signature is currently being verified.
381 // required to deal gracefully with problems caused by incorrect ims hits
384 /** \brief Starts downloading the individual index files.
386 * \param verify If \b true, only indices whose expected hashsum
387 * can be determined from the meta-index will be downloaded, and
388 * the hashsums of indices will be checked (reporting
389 * #StatAuthError if there is a mismatch). If verify is \b false,
390 * no hashsum checking will be performed.
392 void QueueIndexes(bool verify
);
394 /** \brief Called when a file is finished being retrieved.
396 * If the file was not downloaded to DestFile, a copy process is
397 * set up to copy it to DestFile; otherwise, Complete is set to \b
398 * true and the file is moved to its final location.
400 * \param Message The message block received from the fetch
403 bool CheckDownloadDone(const std::string
&Message
,
404 const std::string
&RealURI
);
406 /** \brief Queue the downloaded Signature for verification */
407 void QueueForSignatureVerify(const std::string
&MetaIndexFile
,
408 const std::string
&MetaIndexFileSignature
);
410 /** \brief get the custom600 header for all pkgAcqMeta */
411 std::string
GetCustom600Headers(const std::string
&RealURI
) const;
413 /** \brief Called when authentication succeeded.
415 * Sanity-checks the authenticated file, queues up the individual
416 * index files for download, and saves the signature in the lists
417 * directory next to the authenticated list file.
419 * \param Message The message block received from the fetch
422 bool CheckAuthDone(std::string Message
, const std::string
&RealURI
);
424 /** Check if the current item should fail at this point */
425 bool CheckStopAuthentication(const std::string
&RealURI
,
426 const std::string
&Message
);
428 /** \brief Check that the release file is a release file for the
429 * correct distribution.
431 * \return \b true if no fatal errors were encountered.
433 bool VerifyVendor(std::string Message
, const std::string
&RealURI
);
438 void AbortTransaction();
439 bool TransactionHasError() APT_PURE
;
440 void CommitTransaction();
442 /** \brief Stage (queue) a copy action when the transaction is commited
444 void TransactionStageCopy(Item
*I
,
445 const std::string
&From
,
446 const std::string
&To
);
447 /** \brief Stage (queue) a removal action when the transaction is commited
449 void TransactionStageRemoval(Item
*I
, const std::string
&FinalFile
);
451 pkgAcqMetaBase(pkgAcquire
*Owner
,
452 const std::vector
<IndexTarget
*>* IndexTargets
,
453 indexRecords
* MetaIndexParser
,
454 HashStringList
const &ExpectedHashes
=HashStringList(),
455 pkgAcqMetaBase
*TransactionManager
=NULL
)
456 : Item(Owner
, ExpectedHashes
, TransactionManager
),
457 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
),
458 AuthPass(false), IMSHit(false) {};
461 /** \brief An acquire item that downloads the detached signature {{{
462 * of a meta-index (Release) file, then queues up the release
465 * \todo Why protected members?
467 * \sa pkgAcqMetaIndex
469 class pkgAcqMetaSig
: public pkgAcqMetaBase
475 /** \brief The URI of the signature file. Unlike Desc.URI, this is
476 * never modified; it is used to determine the file that is being
481 /** \brief The file we need to verify */
482 std::string MetaIndexFile
;
484 /** \brief The file we use to verify the MetaIndexFile with */
485 std::string MetaIndexFileSignature
;
487 /** \brief Long URI description used in the acquire system */
490 /** \brief Short URI description used in the acquire system */
491 std::string ShortDesc
;
495 // Specialized action members
496 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
497 virtual void Done(std::string Message
,unsigned long long Size
,
498 HashStringList
const &Hashes
,
499 pkgAcquire::MethodConfig
*Cnf
);
500 virtual std::string
Custom600Headers() const;
501 virtual std::string
DescURI() {return RealURI
; };
503 /** \brief Create a new pkgAcqMetaSig. */
504 pkgAcqMetaSig(pkgAcquire
*Owner
,
505 pkgAcqMetaBase
*TransactionManager
,
506 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
507 std::string MetaIndexFile
,
508 const std::vector
<IndexTarget
*>* IndexTargets
,
509 indexRecords
* MetaIndexParser
);
510 virtual ~pkgAcqMetaSig();
514 /** \brief An item that is responsible for downloading the meta-index {{{
515 * file (i.e., Release) itself and verifying its signature.
517 * Once the download and verification are complete, the downloads of
518 * the individual index files are queued up using pkgAcqDiffIndex.
519 * If the meta-index file had a valid signature, the expected hashsums
520 * of the index files will be the md5sums listed in the meta-index;
521 * otherwise, the expected hashsums will be "" (causing the
522 * authentication of the index files to be bypassed).
524 class pkgAcqMetaIndex
: public pkgAcqMetaBase
529 /** \brief The URI that is actually being downloaded; never
530 * modified by pkgAcqMetaIndex.
535 std::string ShortDesc
;
537 /** \brief The URI of the meta-index file for the detached signature */
538 std::string MetaIndexSigURI
;
540 /** \brief A "URI-style" description of the meta-index file */
541 std::string MetaIndexSigURIDesc
;
543 /** \brief A brief description of the meta-index file */
544 std::string MetaIndexSigShortDesc
;
546 /** \brief delayed constructor */
547 void Init(std::string URIDesc
, std::string ShortDesc
);
551 // Specialized action members
552 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
553 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
554 pkgAcquire::MethodConfig
*Cnf
);
555 virtual std::string
Custom600Headers() const;
556 virtual std::string
DescURI() {return RealURI
; };
557 virtual void Finished();
559 /** \brief Create a new pkgAcqMetaIndex. */
560 pkgAcqMetaIndex(pkgAcquire
*Owner
,
561 pkgAcqMetaBase
*TransactionManager
,
562 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
563 std::string MetaIndexSigURI
, std::string MetaIndexSigURIDesc
, std::string MetaIndexSigShortDesc
,
564 const std::vector
<IndexTarget
*>* IndexTargets
,
565 indexRecords
* MetaIndexParser
);
568 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
569 class pkgAcqMetaClearSig
: public pkgAcqMetaIndex
573 /** \brief The URI of the meta-index file for the detached signature */
574 std::string MetaIndexURI
;
576 /** \brief A "URI-style" description of the meta-index file */
577 std::string MetaIndexURIDesc
;
579 /** \brief A brief description of the meta-index file */
580 std::string MetaIndexShortDesc
;
582 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
583 std::string MetaSigURI
;
585 /** \brief A "URI-style" description of the meta-signature file */
586 std::string MetaSigURIDesc
;
588 /** \brief A brief description of the meta-signature file */
589 std::string MetaSigShortDesc
;
592 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
593 virtual std::string
Custom600Headers() const;
594 virtual void Done(std::string Message
,unsigned long long Size
,
595 HashStringList
const &Hashes
,
596 pkgAcquire::MethodConfig
*Cnf
);
598 /** \brief Create a new pkgAcqMetaClearSig. */
599 pkgAcqMetaClearSig(pkgAcquire
*Owner
,
600 std::string
const &URI
, std::string
const &URIDesc
, std::string
const &ShortDesc
,
601 std::string
const &MetaIndexURI
, std::string
const &MetaIndexURIDesc
, std::string
const &MetaIndexShortDesc
,
602 std::string
const &MetaSigURI
, std::string
const &MetaSigURIDesc
, std::string
const &MetaSigShortDesc
,
603 const std::vector
<IndexTarget
*>* IndexTargets
,
604 indexRecords
* MetaIndexParser
);
605 virtual ~pkgAcqMetaClearSig();
610 /** \brief Common base class for all classes that deal with fetching {{{
613 class pkgAcqBaseIndex
: public pkgAcquire::Item
618 /** \brief Pointer to the IndexTarget data
620 const struct IndexTarget
* Target
;
622 /** \brief Pointer to the indexRecords parser */
623 indexRecords
*MetaIndexParser
;
625 /** \brief The MetaIndex Key */
628 /** \brief The URI of the index file to recreate at our end (either
629 * by downloading it or by applying partial patches).
633 bool VerifyHashByMetaKey(HashStringList
const &Hashes
);
635 pkgAcqBaseIndex(pkgAcquire
*Owner
,
636 pkgAcqMetaBase
*TransactionManager
,
637 struct IndexTarget
const * const Target
,
638 HashStringList
const &ExpectedHashes
,
639 indexRecords
*MetaIndexParser
)
640 : Item(Owner
, ExpectedHashes
, TransactionManager
), Target(Target
),
641 MetaIndexParser(MetaIndexParser
) {};
644 /** \brief An item that is responsible for fetching an index file of {{{
645 * package list diffs and starting the package list's download.
647 * This item downloads the Index file and parses it, then enqueues
648 * additional downloads of either the individual patches (using
649 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
651 * \sa pkgAcqIndexDiffs, pkgAcqIndex
653 class pkgAcqDiffIndex
: public pkgAcqBaseIndex
658 /** \brief If \b true, debugging information will be written to std::clog. */
661 /** \brief The index file which will be patched to generate the new
664 std::string CurrentPackagesFile
;
666 /** \brief A description of the Packages file (stored in
667 * pkgAcquire::ItemDesc::Description).
669 std::string Description
;
671 /** \brief If the copy step of the packages file is done
673 bool PackagesFileReadyInPartial
;
676 // Specialized action members
677 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
678 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
679 pkgAcquire::MethodConfig
*Cnf
);
680 virtual std::string
DescURI() {return RealURI
+ "Index";};
681 virtual std::string
Custom600Headers() const;
683 /** \brief Parse the Index file for a set of Packages diffs.
685 * Parses the Index file and creates additional download items as
688 * \param IndexDiffFile The name of the Index file.
690 * \return \b true if the Index file was successfully parsed, \b
693 bool ParseDiffIndex(std::string IndexDiffFile
);
696 /** \brief Create a new pkgAcqDiffIndex.
698 * \param Owner The Acquire object that owns this item.
700 * \param URI The URI of the list file to download.
702 * \param URIDesc A long description of the list file to download.
704 * \param ShortDesc A short description of the list file to download.
706 * \param ExpectedHashes The list file's hashsums which are expected.
708 pkgAcqDiffIndex(pkgAcquire
*Owner
,
709 pkgAcqMetaBase
*TransactionManager
,
710 struct IndexTarget
const * const Target
,
711 HashStringList
const &ExpectedHashes
,
712 indexRecords
*MetaIndexParser
);
715 /** \brief An item that is responsible for fetching client-merge patches {{{
716 * that need to be applied to a given package index file.
718 * Instead of downloading and applying each patch one by one like its
719 * sister #pkgAcqIndexDiffs this class will download all patches at once
720 * and call rred with all the patches downloaded once. Rred will then
721 * merge and apply them in one go, which should be a lot faster – but is
722 * incompatible with server-based merges of patches like reprepro can do.
724 * \sa pkgAcqDiffIndex, pkgAcqIndex
726 class pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
732 /** \brief If \b true, debugging output will be written to
737 /** \brief description of the file being downloaded. */
738 std::string Description
;
740 /** \brief information about the current patch */
741 struct DiffInfo
const patch
;
743 /** \brief list of all download items for the patches */
744 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
746 /** The current status of this patch. */
749 /** \brief The diff is currently being fetched. */
752 /** \brief The diff is currently being applied. */
755 /** \brief the work with this diff is done */
758 /** \brief something bad happened and fallback was triggered */
763 /** \brief Called when the patch file failed to be downloaded.
765 * This method will fall back to downloading the whole index file
766 * outright; its arguments are ignored.
768 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
769 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
770 pkgAcquire::MethodConfig
*Cnf
);
771 virtual std::string
DescURI() {return RealURI
+ "Index";};
773 /** \brief Create an index merge-diff item.
775 * \param Owner The pkgAcquire object that owns this item.
777 * \param URI The URI of the package index file being
780 * \param URIDesc A long description of this item.
782 * \param ShortDesc A brief description of this item.
784 * \param ExpectedHashes The expected md5sum of the completely
785 * reconstructed package index file; the index file will be tested
786 * against this value when it is entirely reconstructed.
788 * \param patch contains infos about the patch this item is supposed
789 * to download which were read from the index
791 * \param allPatches contains all related items so that each item can
792 * check if it was the last one to complete the download step
794 pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
795 pkgAcqMetaBase
*TransactionManager
,
796 struct IndexTarget
const * const Target
,
797 HashStringList
const &ExpectedHash
,
798 indexRecords
*MetaIndexParser
,
799 DiffInfo
const &patch
,
800 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
803 /** \brief An item that is responsible for fetching server-merge patches {{{
804 * that need to be applied to a given package index file.
806 * After downloading and applying a single patch, this item will
807 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
808 * patches. If no patch can be found that applies to an intermediate
809 * file or if one of the patches cannot be downloaded, falls back to
810 * downloading the entire package index file using pkgAcqIndex.
812 * \sa pkgAcqDiffIndex, pkgAcqIndex
814 class pkgAcqIndexDiffs
: public pkgAcqBaseIndex
820 /** \brief Queue up the next diff download.
822 * Search for the next available diff that applies to the file
823 * that currently exists on disk, and enqueue it by calling
826 * \return \b true if an applicable diff was found, \b false
829 APT_HIDDEN
bool QueueNextDiff();
831 /** \brief Handle tasks that must be performed after the item
832 * finishes downloading.
834 * Dequeues the item and checks the resulting file's hashsums
835 * against ExpectedHashes after the last patch was applied.
836 * There is no need to check the md5/sha1 after a "normal"
837 * patch because QueueNextDiff() will check the sha1 later.
839 * \param allDone If \b true, the file was entirely reconstructed,
840 * and its md5sum is verified.
842 APT_HIDDEN
void Finish(bool allDone
=false);
846 /** \brief If \b true, debugging output will be written to
851 /** A description of the file being downloaded. */
852 std::string Description
;
854 /** The patches that remain to be downloaded, including the patch
855 * being downloaded right now. This list should be ordered so
856 * that each diff appears before any diff that depends on it.
858 * \todo These are indexed by sha1sum; why not use some sort of
859 * dictionary instead of relying on ordering and stripping them
862 std::vector
<DiffInfo
> available_patches
;
864 /** The current status of this patch. */
867 /** \brief The diff is in an unknown state. */
870 /** \brief The diff is currently being fetched. */
873 /** \brief The diff is currently being uncompressed. */
874 StateUnzipDiff
, // FIXME: No longer used
876 /** \brief The diff is currently being applied. */
882 /** \brief Called when the patch file failed to be downloaded.
884 * This method will fall back to downloading the whole index file
885 * outright; its arguments are ignored.
887 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
889 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
890 pkgAcquire::MethodConfig
*Cnf
);
891 virtual std::string
DescURI() {return RealURI
+ "IndexDiffs";};
893 /** \brief Create an index diff item.
895 * After filling in its basic fields, this invokes Finish(true) if
896 * \a diffs is empty, or QueueNextDiff() otherwise.
898 * \param Owner The pkgAcquire object that owns this item.
900 * \param URI The URI of the package index file being
903 * \param URIDesc A long description of this item.
905 * \param ShortDesc A brief description of this item.
907 * \param ExpectedHashes The expected hashsums of the completely
908 * reconstructed package index file; the index file will be tested
909 * against this value when it is entirely reconstructed.
911 * \param diffs The remaining diffs from the index of diffs. They
912 * should be ordered so that each diff appears before any diff
913 * that depends on it.
915 pkgAcqIndexDiffs(pkgAcquire
*Owner
,
916 pkgAcqMetaBase
*TransactionManager
,
917 struct IndexTarget
const * const Target
,
918 HashStringList
const &ExpectedHash
,
919 indexRecords
*MetaIndexParser
,
920 std::vector
<DiffInfo
> diffs
=std::vector
<DiffInfo
>());
923 /** \brief An acquire item that is responsible for fetching an index {{{
924 * file (e.g., Packages or Sources).
926 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
928 * \todo Why does pkgAcqIndex have protected members?
930 class pkgAcqIndex
: public pkgAcqBaseIndex
936 /** \brief The stages the method goes through
938 * The method first downloads the indexfile, then its decompressed (or
939 * copied) and verified
943 STAGE_DECOMPRESS_AND_VERIFY
,
947 /** \brief Handle what needs to be done when the download is done */
948 void StageDownloadDone(std::string Message
,
949 HashStringList
const &Hashes
,
950 pkgAcquire::MethodConfig
*Cfg
);
952 /** \brief Handle what needs to be done when the decompression/copy is
955 void StageDecompressDone(std::string Message
,
956 HashStringList
const &Hashes
,
957 pkgAcquire::MethodConfig
*Cfg
);
959 /** \brief If \b set, this partially downloaded file will be
960 * removed when the download completes.
962 std::string EraseFileName
;
964 /** \brief The compression-related file extensions that are being
965 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
967 std::string CompressionExtensions
;
969 /** \brief The actual compression extension currently used */
970 std::string CurrentCompressionExtension
;
972 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
973 void InitByHashIfNeeded(const std::string MetaKey
);
975 /** \brief Auto select the right compression to use */
976 void AutoSelectCompression();
978 /** \brief Get the full pathname of the final file for the current URI
980 std::string
GetFinalFilename() const;
982 /** \brief Schedule file for verification after a IMS hit */
983 void ReverifyAfterIMS();
985 /** \brief Validate the downloaded index file */
986 bool ValidateFile(const std::string
&FileName
);
990 // Specialized action members
991 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
992 virtual void Done(std::string Message
,unsigned long long Size
,
993 HashStringList
const &Hashes
,
994 pkgAcquire::MethodConfig
*Cnf
);
995 virtual std::string
Custom600Headers() const;
996 virtual std::string
DescURI() {return Desc
.URI
;};
998 /** \brief Create a pkgAcqIndex.
1000 * \param Owner The pkgAcquire object with which this item is
1003 * \param URI The URI of the index file that is to be downloaded.
1005 * \param URIDesc A "URI-style" description of this index file.
1007 * \param ShortDesc A brief description of this index file.
1009 * \param ExpectedHashes The expected hashsum of this index file.
1011 * \param compressExt The compression-related extension with which
1012 * this index file should be downloaded, or "" to autodetect
1013 * Compression types can be set with config Acquire::CompressionTypes,
1014 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1015 * fallback is ".gz" or none.
1017 pkgAcqIndex(pkgAcquire
*Owner
,std::string URI
,std::string URIDesc
,
1018 std::string ShortDesc
, HashStringList
const &ExpectedHashes
);
1019 pkgAcqIndex(pkgAcquire
*Owner
, pkgAcqMetaBase
*TransactionManager
,
1020 IndexTarget
const * const Target
,
1021 HashStringList
const &ExpectedHash
,
1022 indexRecords
*MetaIndexParser
);
1024 void Init(std::string
const &URI
, std::string
const &URIDesc
,
1025 std::string
const &ShortDesc
);
1028 /** \brief An acquire item that is responsible for fetching a {{{
1029 * translated index file.
1031 * The only difference from pkgAcqIndex is that transient failures
1032 * are suppressed: no error occurs if the translated index file is
1035 class pkgAcqIndexTrans
: public pkgAcqIndex
1041 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1042 virtual std::string
Custom600Headers() const;
1044 /** \brief Create a pkgAcqIndexTrans.
1046 * \param Owner The pkgAcquire object with which this item is
1049 * \param URI The URI of the index file that is to be downloaded.
1051 * \param URIDesc A "URI-style" description of this index file.
1053 * \param ShortDesc A brief description of this index file.
1055 pkgAcqIndexTrans(pkgAcquire
*Owner
,
1056 std::string URI
,std::string URIDesc
,
1057 std::string ShortDesc
);
1058 pkgAcqIndexTrans(pkgAcquire
*Owner
,
1059 pkgAcqMetaBase
*TransactionManager
,
1060 IndexTarget
const * const Target
,
1061 HashStringList
const &ExpectedHashes
,
1062 indexRecords
*MetaIndexParser
);
1065 /** \brief Information about an index file. */ /*{{{*/
1071 /** \brief A URI from which the index file can be downloaded. */
1074 /** \brief A description of the index file. */
1075 std::string Description
;
1077 /** \brief A shorter description of the index file. */
1078 std::string ShortDesc
;
1080 /** \brief The key by which this index file should be
1081 * looked up within the meta signature file.
1083 std::string MetaKey
;
1085 virtual bool IsOptional() const {
1090 /** \brief Information about an optional index file. */ /*{{{*/
1091 class OptionalIndexTarget
: public IndexTarget
1095 virtual bool IsOptional() const {
1100 /** \brief An item that is responsible for fetching a package file. {{{
1102 * If the package file already exists in the cache, nothing will be
1105 class pkgAcqArchive
: public pkgAcquire::Item
1110 /** \brief The package version being fetched. */
1111 pkgCache::VerIterator Version
;
1113 /** \brief The list of sources from which to pick archives to
1114 * download this package from.
1116 pkgSourceList
*Sources
;
1118 /** \brief A package records object, used to look up the file
1119 * corresponding to each version of the package.
1123 /** \brief A location in which the actual filename of the package
1126 std::string
&StoreFilename
;
1128 /** \brief The next file for this version to try to download. */
1129 pkgCache::VerFileIterator Vf
;
1131 /** \brief How many (more) times to try to find a new source from
1132 * which to download this package version if it fails.
1134 * Set from Acquire::Retries.
1136 unsigned int Retries
;
1138 /** \brief \b true if this version file is being downloaded from a
1143 /** \brief Queue up the next available file for this version. */
1148 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1149 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
1150 pkgAcquire::MethodConfig
*Cnf
);
1151 virtual std::string
DescURI() {return Desc
.URI
;};
1152 virtual std::string
ShortDesc() {return Desc
.ShortDesc
;};
1153 virtual void Finished();
1154 virtual bool IsTrusted() const;
1156 /** \brief Create a new pkgAcqArchive.
1158 * \param Owner The pkgAcquire object with which this item is
1161 * \param Sources The sources from which to download version
1164 * \param Recs A package records object, used to look up the file
1165 * corresponding to each version of the package.
1167 * \param Version The package version to download.
1169 * \param[out] StoreFilename A location in which the actual filename of
1170 * the package should be stored. It will be set to a guessed
1171 * basename in the constructor, and filled in with a fully
1172 * qualified filename once the download finishes.
1174 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1175 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1176 std::string
&StoreFilename
);
1179 /** \brief Retrieve an arbitrary file to the current directory. {{{
1181 * The file is retrieved even if it is accessed via a URL type that
1182 * normally is a NOP, such as "file". If the download fails, the
1183 * partial file is renamed to get a ".FAILED" extension.
1185 class pkgAcqFile
: public pkgAcquire::Item
1189 /** \brief How many times to retry the download, set from
1192 unsigned int Retries
;
1194 /** \brief Should this file be considered a index file */
1199 // Specialized action members
1200 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1201 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &CalcHashes
,
1202 pkgAcquire::MethodConfig
*Cnf
);
1203 virtual std::string
DescURI() {return Desc
.URI
;};
1204 virtual std::string
Custom600Headers() const;
1206 /** \brief Create a new pkgAcqFile object.
1208 * \param Owner The pkgAcquire object with which this object is
1211 * \param URI The URI to download.
1213 * \param Hashes The hashsums of the file to download, if they are known;
1214 * otherwise empty list.
1216 * \param Size The size of the file to download, if it is known;
1219 * \param Desc A description of the file being downloaded.
1221 * \param ShortDesc A brief description of the file being
1224 * \param DestDir The directory the file should be downloaded into.
1226 * \param DestFilename The filename+path the file is downloaded to.
1228 * \param IsIndexFile The file is considered a IndexFile and cache-control
1229 * headers like "cache-control: max-age=0" are send
1231 * If DestFilename is empty, download to DestDir/\<basename\> if
1232 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1233 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1234 * is the absolute name to which the file should be downloaded.
1237 pkgAcqFile(pkgAcquire
*Owner
, std::string URI
, HashStringList
const &Hashes
, unsigned long long Size
,
1238 std::string Desc
, std::string ShortDesc
,
1239 const std::string
&DestDir
="", const std::string
&DestFilename
="",
1240 bool IsIndexFile
=false);