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
{
328 /** \brief Rename failed file and set error
330 * \param state respresenting the error we encountered
332 bool RenameOnError(RenameOnErrorState
const state
);
334 /** \brief The HashSums of the item is supposed to have than done */
335 HashStringList ExpectedHashes
;
337 /** \brief The item that is currently being downloaded. */
338 pkgAcquire::ItemDesc Desc
;
341 /** \brief Information about an index patch (aka diff). */ /*{{{*/
343 /** The filename of the diff. */
346 /** The hashes of the diff */
347 HashStringList result_hashes
;
349 /** The hashes of the file after the diff is applied */
350 HashStringList patch_hashes
;
352 /** The size of the file after the diff is applied */
353 unsigned long long result_size
;
355 /** The size of the diff itself */
356 unsigned long long patch_size
;
361 class pkgAcqMetaBase
: public pkgAcquire::Item
366 std::vector
<Item
*> Transaction
;
368 /** \brief A package-system-specific parser for the meta-index file. */
369 indexRecords
*MetaIndexParser
;
371 /** \brief The index files which should be looked up in the meta-index
372 * and then downloaded.
374 const std::vector
<IndexTarget
*>* IndexTargets
;
376 /** \brief If \b true, the index's signature is currently being verified.
380 // required to deal gracefully with problems caused by incorrect ims hits
383 /** \brief Starts downloading the individual index files.
385 * \param verify If \b true, only indices whose expected hashsum
386 * can be determined from the meta-index will be downloaded, and
387 * the hashsums of indices will be checked (reporting
388 * #StatAuthError if there is a mismatch). If verify is \b false,
389 * no hashsum checking will be performed.
391 void QueueIndexes(bool verify
);
393 /** \brief Called when a file is finished being retrieved.
395 * If the file was not downloaded to DestFile, a copy process is
396 * set up to copy it to DestFile; otherwise, Complete is set to \b
397 * true and the file is moved to its final location.
399 * \param Message The message block received from the fetch
402 bool CheckDownloadDone(const std::string
&Message
,
403 const std::string
&RealURI
);
405 /** \brief Queue the downloaded Signature for verification */
406 void QueueForSignatureVerify(const std::string
&MetaIndexFile
,
407 const std::string
&MetaIndexFileSignature
);
409 /** \brief get the custom600 header for all pkgAcqMeta */
410 std::string
GetCustom600Headers(const std::string
&RealURI
) const;
412 /** \brief Called when authentication succeeded.
414 * Sanity-checks the authenticated file, queues up the individual
415 * index files for download, and saves the signature in the lists
416 * directory next to the authenticated list file.
418 * \param Message The message block received from the fetch
421 bool CheckAuthDone(std::string Message
, const std::string
&RealURI
);
423 /** Check if the current item should fail at this point */
424 bool CheckStopAuthentication(const std::string
&RealURI
,
425 const std::string
&Message
);
427 /** \brief Check that the release file is a release file for the
428 * correct distribution.
430 * \return \b true if no fatal errors were encountered.
432 bool VerifyVendor(std::string Message
, const std::string
&RealURI
);
437 void AbortTransaction();
438 bool TransactionHasError() APT_PURE
;
439 void CommitTransaction();
441 /** \brief Stage (queue) a copy action when the transaction is commited
443 void TransactionStageCopy(Item
*I
,
444 const std::string
&From
,
445 const std::string
&To
);
446 /** \brief Stage (queue) a removal action when the transaction is commited
448 void TransactionStageRemoval(Item
*I
, const std::string
&FinalFile
);
450 pkgAcqMetaBase(pkgAcquire
*Owner
,
451 const std::vector
<IndexTarget
*>* IndexTargets
,
452 indexRecords
* MetaIndexParser
,
453 HashStringList
const &ExpectedHashes
=HashStringList(),
454 pkgAcqMetaBase
*TransactionManager
=NULL
)
455 : Item(Owner
, ExpectedHashes
, TransactionManager
),
456 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
),
457 AuthPass(false), IMSHit(false) {};
460 /** \brief An acquire item that downloads the detached signature {{{
461 * of a meta-index (Release) file, then queues up the release
464 * \todo Why protected members?
466 * \sa pkgAcqMetaIndex
468 class pkgAcqMetaSig
: public pkgAcqMetaBase
474 /** \brief The URI of the signature file. Unlike Desc.URI, this is
475 * never modified; it is used to determine the file that is being
480 /** \brief The file we need to verify */
481 std::string MetaIndexFile
;
483 /** \brief The file we use to verify the MetaIndexFile with */
484 std::string MetaIndexFileSignature
;
486 /** \brief Long URI description used in the acquire system */
489 /** \brief Short URI description used in the acquire system */
490 std::string ShortDesc
;
494 // Specialized action members
495 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
496 virtual void Done(std::string Message
,unsigned long long Size
,
497 HashStringList
const &Hashes
,
498 pkgAcquire::MethodConfig
*Cnf
);
499 virtual std::string
Custom600Headers() const;
500 virtual std::string
DescURI() {return RealURI
; };
502 /** \brief Create a new pkgAcqMetaSig. */
503 pkgAcqMetaSig(pkgAcquire
*Owner
,
504 pkgAcqMetaBase
*TransactionManager
,
505 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
506 std::string MetaIndexFile
,
507 const std::vector
<IndexTarget
*>* IndexTargets
,
508 indexRecords
* MetaIndexParser
);
509 virtual ~pkgAcqMetaSig();
513 /** \brief An item that is responsible for downloading the meta-index {{{
514 * file (i.e., Release) itself and verifying its signature.
516 * Once the download and verification are complete, the downloads of
517 * the individual index files are queued up using pkgAcqDiffIndex.
518 * If the meta-index file had a valid signature, the expected hashsums
519 * of the index files will be the md5sums listed in the meta-index;
520 * otherwise, the expected hashsums will be "" (causing the
521 * authentication of the index files to be bypassed).
523 class pkgAcqMetaIndex
: public pkgAcqMetaBase
528 /** \brief The URI that is actually being downloaded; never
529 * modified by pkgAcqMetaIndex.
534 std::string ShortDesc
;
536 /** \brief The URI of the meta-index file for the detached signature */
537 std::string MetaIndexSigURI
;
539 /** \brief A "URI-style" description of the meta-index file */
540 std::string MetaIndexSigURIDesc
;
542 /** \brief A brief description of the meta-index file */
543 std::string MetaIndexSigShortDesc
;
545 /** \brief delayed constructor */
546 void Init(std::string URIDesc
, std::string ShortDesc
);
550 // Specialized action members
551 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
552 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
553 pkgAcquire::MethodConfig
*Cnf
);
554 virtual std::string
Custom600Headers() const;
555 virtual std::string
DescURI() {return RealURI
; };
556 virtual void Finished();
558 /** \brief Create a new pkgAcqMetaIndex. */
559 pkgAcqMetaIndex(pkgAcquire
*Owner
,
560 pkgAcqMetaBase
*TransactionManager
,
561 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
562 std::string MetaIndexSigURI
, std::string MetaIndexSigURIDesc
, std::string MetaIndexSigShortDesc
,
563 const std::vector
<IndexTarget
*>* IndexTargets
,
564 indexRecords
* MetaIndexParser
);
567 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
568 class pkgAcqMetaClearSig
: public pkgAcqMetaIndex
572 /** \brief The URI of the meta-index file for the detached signature */
573 std::string MetaIndexURI
;
575 /** \brief A "URI-style" description of the meta-index file */
576 std::string MetaIndexURIDesc
;
578 /** \brief A brief description of the meta-index file */
579 std::string MetaIndexShortDesc
;
581 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
582 std::string MetaSigURI
;
584 /** \brief A "URI-style" description of the meta-signature file */
585 std::string MetaSigURIDesc
;
587 /** \brief A brief description of the meta-signature file */
588 std::string MetaSigShortDesc
;
591 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
592 virtual std::string
Custom600Headers() const;
593 virtual void Done(std::string Message
,unsigned long long Size
,
594 HashStringList
const &Hashes
,
595 pkgAcquire::MethodConfig
*Cnf
);
597 /** \brief Create a new pkgAcqMetaClearSig. */
598 pkgAcqMetaClearSig(pkgAcquire
*Owner
,
599 std::string
const &URI
, std::string
const &URIDesc
, std::string
const &ShortDesc
,
600 std::string
const &MetaIndexURI
, std::string
const &MetaIndexURIDesc
, std::string
const &MetaIndexShortDesc
,
601 std::string
const &MetaSigURI
, std::string
const &MetaSigURIDesc
, std::string
const &MetaSigShortDesc
,
602 const std::vector
<IndexTarget
*>* IndexTargets
,
603 indexRecords
* MetaIndexParser
);
604 virtual ~pkgAcqMetaClearSig();
609 /** \brief Common base class for all classes that deal with fetching {{{
612 class pkgAcqBaseIndex
: public pkgAcquire::Item
617 /** \brief Pointer to the IndexTarget data
619 const struct IndexTarget
* Target
;
621 /** \brief Pointer to the indexRecords parser */
622 indexRecords
*MetaIndexParser
;
624 /** \brief The MetaIndex Key */
627 /** \brief The URI of the index file to recreate at our end (either
628 * by downloading it or by applying partial patches).
632 bool VerifyHashByMetaKey(HashStringList
const &Hashes
);
634 pkgAcqBaseIndex(pkgAcquire
*Owner
,
635 pkgAcqMetaBase
*TransactionManager
,
636 struct IndexTarget
const * const Target
,
637 HashStringList
const &ExpectedHashes
,
638 indexRecords
*MetaIndexParser
)
639 : Item(Owner
, ExpectedHashes
, TransactionManager
), Target(Target
),
640 MetaIndexParser(MetaIndexParser
) {};
643 /** \brief An item that is responsible for fetching an index file of {{{
644 * package list diffs and starting the package list's download.
646 * This item downloads the Index file and parses it, then enqueues
647 * additional downloads of either the individual patches (using
648 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
650 * \sa pkgAcqIndexDiffs, pkgAcqIndex
652 class pkgAcqDiffIndex
: public pkgAcqBaseIndex
657 /** \brief If \b true, debugging information will be written to std::clog. */
660 /** \brief The index file which will be patched to generate the new
663 std::string CurrentPackagesFile
;
665 /** \brief A description of the Packages file (stored in
666 * pkgAcquire::ItemDesc::Description).
668 std::string Description
;
670 /** \brief If the copy step of the packages file is done
672 bool PackagesFileReadyInPartial
;
675 // Specialized action members
676 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
677 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
678 pkgAcquire::MethodConfig
*Cnf
);
679 virtual std::string
DescURI() {return RealURI
+ "Index";};
680 virtual std::string
Custom600Headers() const;
682 /** \brief Parse the Index file for a set of Packages diffs.
684 * Parses the Index file and creates additional download items as
687 * \param IndexDiffFile The name of the Index file.
689 * \return \b true if the Index file was successfully parsed, \b
692 bool ParseDiffIndex(std::string IndexDiffFile
);
695 /** \brief Create a new pkgAcqDiffIndex.
697 * \param Owner The Acquire object that owns this item.
699 * \param URI The URI of the list file to download.
701 * \param URIDesc A long description of the list file to download.
703 * \param ShortDesc A short description of the list file to download.
705 * \param ExpectedHashes The list file's hashsums which are expected.
707 pkgAcqDiffIndex(pkgAcquire
*Owner
,
708 pkgAcqMetaBase
*TransactionManager
,
709 struct IndexTarget
const * const Target
,
710 HashStringList
const &ExpectedHashes
,
711 indexRecords
*MetaIndexParser
);
714 /** \brief An item that is responsible for fetching client-merge patches {{{
715 * that need to be applied to a given package index file.
717 * Instead of downloading and applying each patch one by one like its
718 * sister #pkgAcqIndexDiffs this class will download all patches at once
719 * and call rred with all the patches downloaded once. Rred will then
720 * merge and apply them in one go, which should be a lot faster – but is
721 * incompatible with server-based merges of patches like reprepro can do.
723 * \sa pkgAcqDiffIndex, pkgAcqIndex
725 class pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
731 /** \brief If \b true, debugging output will be written to
736 /** \brief description of the file being downloaded. */
737 std::string Description
;
739 /** \brief information about the current patch */
740 struct DiffInfo
const patch
;
742 /** \brief list of all download items for the patches */
743 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
745 /** The current status of this patch. */
748 /** \brief The diff is currently being fetched. */
751 /** \brief The diff is currently being applied. */
754 /** \brief the work with this diff is done */
757 /** \brief something bad happened and fallback was triggered */
762 /** \brief Called when the patch file failed to be downloaded.
764 * This method will fall back to downloading the whole index file
765 * outright; its arguments are ignored.
767 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
768 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
769 pkgAcquire::MethodConfig
*Cnf
);
770 virtual std::string
DescURI() {return RealURI
+ "Index";};
772 /** \brief Create an index merge-diff item.
774 * \param Owner The pkgAcquire object that owns this item.
776 * \param URI The URI of the package index file being
779 * \param URIDesc A long description of this item.
781 * \param ShortDesc A brief description of this item.
783 * \param ExpectedHashes The expected md5sum of the completely
784 * reconstructed package index file; the index file will be tested
785 * against this value when it is entirely reconstructed.
787 * \param patch contains infos about the patch this item is supposed
788 * to download which were read from the index
790 * \param allPatches contains all related items so that each item can
791 * check if it was the last one to complete the download step
793 pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
794 pkgAcqMetaBase
*TransactionManager
,
795 struct IndexTarget
const * const Target
,
796 HashStringList
const &ExpectedHash
,
797 indexRecords
*MetaIndexParser
,
798 DiffInfo
const &patch
,
799 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
802 /** \brief An item that is responsible for fetching server-merge patches {{{
803 * that need to be applied to a given package index file.
805 * After downloading and applying a single patch, this item will
806 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
807 * patches. If no patch can be found that applies to an intermediate
808 * file or if one of the patches cannot be downloaded, falls back to
809 * downloading the entire package index file using pkgAcqIndex.
811 * \sa pkgAcqDiffIndex, pkgAcqIndex
813 class pkgAcqIndexDiffs
: public pkgAcqBaseIndex
819 /** \brief Queue up the next diff download.
821 * Search for the next available diff that applies to the file
822 * that currently exists on disk, and enqueue it by calling
825 * \return \b true if an applicable diff was found, \b false
828 APT_HIDDEN
bool QueueNextDiff();
830 /** \brief Handle tasks that must be performed after the item
831 * finishes downloading.
833 * Dequeues the item and checks the resulting file's hashsums
834 * against ExpectedHashes after the last patch was applied.
835 * There is no need to check the md5/sha1 after a "normal"
836 * patch because QueueNextDiff() will check the sha1 later.
838 * \param allDone If \b true, the file was entirely reconstructed,
839 * and its md5sum is verified.
841 APT_HIDDEN
void Finish(bool allDone
=false);
845 /** \brief If \b true, debugging output will be written to
850 /** A description of the file being downloaded. */
851 std::string Description
;
853 /** The patches that remain to be downloaded, including the patch
854 * being downloaded right now. This list should be ordered so
855 * that each diff appears before any diff that depends on it.
857 * \todo These are indexed by sha1sum; why not use some sort of
858 * dictionary instead of relying on ordering and stripping them
861 std::vector
<DiffInfo
> available_patches
;
863 /** The current status of this patch. */
866 /** \brief The diff is in an unknown state. */
869 /** \brief The diff is currently being fetched. */
872 /** \brief The diff is currently being uncompressed. */
873 StateUnzipDiff
, // FIXME: No longer used
875 /** \brief The diff is currently being applied. */
881 /** \brief Called when the patch file failed to be downloaded.
883 * This method will fall back to downloading the whole index file
884 * outright; its arguments are ignored.
886 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
888 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
889 pkgAcquire::MethodConfig
*Cnf
);
890 virtual std::string
DescURI() {return RealURI
+ "IndexDiffs";};
892 /** \brief Create an index diff item.
894 * After filling in its basic fields, this invokes Finish(true) if
895 * \a diffs is empty, or QueueNextDiff() otherwise.
897 * \param Owner The pkgAcquire object that owns this item.
899 * \param URI The URI of the package index file being
902 * \param URIDesc A long description of this item.
904 * \param ShortDesc A brief description of this item.
906 * \param ExpectedHashes The expected hashsums of the completely
907 * reconstructed package index file; the index file will be tested
908 * against this value when it is entirely reconstructed.
910 * \param diffs The remaining diffs from the index of diffs. They
911 * should be ordered so that each diff appears before any diff
912 * that depends on it.
914 pkgAcqIndexDiffs(pkgAcquire
*Owner
,
915 pkgAcqMetaBase
*TransactionManager
,
916 struct IndexTarget
const * const Target
,
917 HashStringList
const &ExpectedHash
,
918 indexRecords
*MetaIndexParser
,
919 std::vector
<DiffInfo
> diffs
=std::vector
<DiffInfo
>());
922 /** \brief An acquire item that is responsible for fetching an index {{{
923 * file (e.g., Packages or Sources).
925 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
927 * \todo Why does pkgAcqIndex have protected members?
929 class pkgAcqIndex
: public pkgAcqBaseIndex
935 /** \brief The stages the method goes through
937 * The method first downloads the indexfile, then its decompressed (or
938 * copied) and verified
942 STAGE_DECOMPRESS_AND_VERIFY
,
946 /** \brief Handle what needs to be done when the download is done */
947 void StageDownloadDone(std::string Message
,
948 HashStringList
const &Hashes
,
949 pkgAcquire::MethodConfig
*Cfg
);
951 /** \brief Handle what needs to be done when the decompression/copy is
954 void StageDecompressDone(std::string Message
,
955 HashStringList
const &Hashes
,
956 pkgAcquire::MethodConfig
*Cfg
);
958 /** \brief If \b set, this partially downloaded file will be
959 * removed when the download completes.
961 std::string EraseFileName
;
963 /** \brief The compression-related file extensions that are being
964 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
966 std::string CompressionExtensions
;
968 /** \brief The actual compression extension currently used */
969 std::string CurrentCompressionExtension
;
971 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
972 void InitByHashIfNeeded(const std::string MetaKey
);
974 /** \brief Auto select the right compression to use */
975 void AutoSelectCompression();
977 /** \brief Get the full pathname of the final file for the current URI
979 std::string
GetFinalFilename() const;
981 /** \brief Schedule file for verification after a IMS hit */
982 void ReverifyAfterIMS();
984 /** \brief Validate the downloaded index file */
985 bool ValidateFile(const std::string
&FileName
);
989 // Specialized action members
990 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
991 virtual void Done(std::string Message
,unsigned long long Size
,
992 HashStringList
const &Hashes
,
993 pkgAcquire::MethodConfig
*Cnf
);
994 virtual std::string
Custom600Headers() const;
995 virtual std::string
DescURI() {return Desc
.URI
;};
997 /** \brief Create a pkgAcqIndex.
999 * \param Owner The pkgAcquire object with which this item is
1002 * \param URI The URI of the index file that is to be downloaded.
1004 * \param URIDesc A "URI-style" description of this index file.
1006 * \param ShortDesc A brief description of this index file.
1008 * \param ExpectedHashes The expected hashsum of this index file.
1010 * \param compressExt The compression-related extension with which
1011 * this index file should be downloaded, or "" to autodetect
1012 * Compression types can be set with config Acquire::CompressionTypes,
1013 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1014 * fallback is ".gz" or none.
1016 pkgAcqIndex(pkgAcquire
*Owner
,std::string URI
,std::string URIDesc
,
1017 std::string ShortDesc
, HashStringList
const &ExpectedHashes
);
1018 pkgAcqIndex(pkgAcquire
*Owner
, pkgAcqMetaBase
*TransactionManager
,
1019 IndexTarget
const * const Target
,
1020 HashStringList
const &ExpectedHash
,
1021 indexRecords
*MetaIndexParser
);
1023 void Init(std::string
const &URI
, std::string
const &URIDesc
,
1024 std::string
const &ShortDesc
);
1027 /** \brief An acquire item that is responsible for fetching a {{{
1028 * translated index file.
1030 * The only difference from pkgAcqIndex is that transient failures
1031 * are suppressed: no error occurs if the translated index file is
1034 class pkgAcqIndexTrans
: public pkgAcqIndex
1040 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1041 virtual std::string
Custom600Headers() const;
1043 /** \brief Create a pkgAcqIndexTrans.
1045 * \param Owner The pkgAcquire object with which this item is
1048 * \param URI The URI of the index file that is to be downloaded.
1050 * \param URIDesc A "URI-style" description of this index file.
1052 * \param ShortDesc A brief description of this index file.
1054 pkgAcqIndexTrans(pkgAcquire
*Owner
,
1055 std::string URI
,std::string URIDesc
,
1056 std::string ShortDesc
);
1057 pkgAcqIndexTrans(pkgAcquire
*Owner
,
1058 pkgAcqMetaBase
*TransactionManager
,
1059 IndexTarget
const * const Target
,
1060 HashStringList
const &ExpectedHashes
,
1061 indexRecords
*MetaIndexParser
);
1064 /** \brief Information about an index file. */ /*{{{*/
1070 /** \brief A URI from which the index file can be downloaded. */
1073 /** \brief A description of the index file. */
1074 std::string Description
;
1076 /** \brief A shorter description of the index file. */
1077 std::string ShortDesc
;
1079 /** \brief The key by which this index file should be
1080 * looked up within the meta signature file.
1082 std::string MetaKey
;
1084 virtual bool IsOptional() const {
1089 /** \brief Information about an optional index file. */ /*{{{*/
1090 class OptionalIndexTarget
: public IndexTarget
1094 virtual bool IsOptional() const {
1099 /** \brief An item that is responsible for fetching a package file. {{{
1101 * If the package file already exists in the cache, nothing will be
1104 class pkgAcqArchive
: public pkgAcquire::Item
1109 /** \brief The package version being fetched. */
1110 pkgCache::VerIterator Version
;
1112 /** \brief The list of sources from which to pick archives to
1113 * download this package from.
1115 pkgSourceList
*Sources
;
1117 /** \brief A package records object, used to look up the file
1118 * corresponding to each version of the package.
1122 /** \brief A location in which the actual filename of the package
1125 std::string
&StoreFilename
;
1127 /** \brief The next file for this version to try to download. */
1128 pkgCache::VerFileIterator Vf
;
1130 /** \brief How many (more) times to try to find a new source from
1131 * which to download this package version if it fails.
1133 * Set from Acquire::Retries.
1135 unsigned int Retries
;
1137 /** \brief \b true if this version file is being downloaded from a
1142 /** \brief Queue up the next available file for this version. */
1147 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1148 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
1149 pkgAcquire::MethodConfig
*Cnf
);
1150 virtual std::string
DescURI() {return Desc
.URI
;};
1151 virtual std::string
ShortDesc() {return Desc
.ShortDesc
;};
1152 virtual void Finished();
1153 virtual bool IsTrusted() const;
1155 /** \brief Create a new pkgAcqArchive.
1157 * \param Owner The pkgAcquire object with which this item is
1160 * \param Sources The sources from which to download version
1163 * \param Recs A package records object, used to look up the file
1164 * corresponding to each version of the package.
1166 * \param Version The package version to download.
1168 * \param[out] StoreFilename A location in which the actual filename of
1169 * the package should be stored. It will be set to a guessed
1170 * basename in the constructor, and filled in with a fully
1171 * qualified filename once the download finishes.
1173 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1174 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1175 std::string
&StoreFilename
);
1178 /** \brief Retrieve an arbitrary file to the current directory. {{{
1180 * The file is retrieved even if it is accessed via a URL type that
1181 * normally is a NOP, such as "file". If the download fails, the
1182 * partial file is renamed to get a ".FAILED" extension.
1184 class pkgAcqFile
: public pkgAcquire::Item
1188 /** \brief How many times to retry the download, set from
1191 unsigned int Retries
;
1193 /** \brief Should this file be considered a index file */
1198 // Specialized action members
1199 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1200 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &CalcHashes
,
1201 pkgAcquire::MethodConfig
*Cnf
);
1202 virtual std::string
DescURI() {return Desc
.URI
;};
1203 virtual std::string
Custom600Headers() const;
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);