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
);
96 /** \brief Get the full pathname of the final file for the current URI */
97 virtual std::string
GetFinalFilename() const;
101 /** \brief The current status of this item. */
104 /** \brief The item is waiting to be downloaded. */
107 /** \brief The item is currently being downloaded. */
110 /** \brief The item has been successfully downloaded. */
113 /** \brief An error was encountered while downloading this
118 /** \brief The item was downloaded but its authenticity could
123 /** \brief The item was could not be downloaded because of
124 * a transient network error (e.g. network down)
126 StatTransientNetworkError
,
129 /** \brief Contains a textual description of the error encountered
130 * if #ItemState is #StatError or #StatAuthError.
132 std::string ErrorText
;
134 /** \brief The size of the object to fetch. */
135 unsigned long long FileSize
;
137 /** \brief How much of the object was already fetched. */
138 unsigned long long PartialSize
;
140 /** \brief If not \b NULL, contains the name of a subprocess that
141 * is operating on this object (for instance, "gzip" or "gpgv").
143 APT_DEPRECATED
const char *Mode
;
145 /** \brief contains the name of the subprocess that is operating on this object
146 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
147 * as it can manage the lifetime of included string properly. */
148 std::string ActiveSubprocess
;
150 /** \brief A client-supplied unique identifier.
152 * This field is initalized to 0; it is meant to be filled in by
153 * clients that wish to use it to uniquely identify items.
155 * \todo it's unused in apt itself
159 /** \brief If \b true, the entire object has been successfully fetched.
161 * Subclasses should set this to \b true when appropriate.
165 /** \brief If \b true, the URI of this object is "local".
167 * The only effect of this field is to exclude the object from the
168 * download progress indicator's overall statistics.
171 std::string UsedMirror
;
173 /** \brief The number of fetch queues into which this item has been
176 * There is one queue for each source from which an item could be
181 unsigned int QueueCounter
;
183 /** \brief TransactionManager */
184 pkgAcqMetaBase
*TransactionManager
;
186 /** \brief The number of additional fetch items that are expected
187 * once this item is done.
189 * Some items like pkgAcqMeta{Index,Sig} will queue additional
190 * items. This variable can be set by the methods if it knows
191 * in advance how many items to expect to get a more accurate
194 unsigned int ExpectedAdditionalItems
;
196 /** \brief The name of the file into which the retrieved object
199 std::string DestFile
;
201 /** \brief storge name until a transaction is finished */
202 std::string PartialFile
;
204 /** \brief Invoked by the acquire worker when the object couldn't
207 * This is a branch of the continuation of the fetch process.
209 * \param Message An RFC822-formatted message from the acquire
210 * method describing what went wrong. Use LookupTag() to parse
213 * \param Cnf The method via which the worker tried to fetch this object.
217 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
219 /** \brief Invoked by the acquire worker when the object was
220 * fetched successfully.
222 * Note that the object might \e not have been written to
223 * DestFile; check for the presence of an Alt-Filename entry in
224 * Message to find the file to which it was really written.
226 * Done is often used to switch from one stage of the processing
227 * to the next (e.g. fetching, unpacking, copying). It is one
228 * branch of the continuation of the fetch process.
230 * \param Message Data from the acquire method. Use LookupTag()
232 * \param Size The size of the object that was fetched.
233 * \param Hashes The HashSums of the object that was fetched.
234 * \param Cnf The method via which the object was fetched.
238 virtual void Done(std::string Message
, unsigned long long Size
, HashStringList
const &Hashes
,
239 pkgAcquire::MethodConfig
*Cnf
);
241 /** \brief Invoked when the worker starts to fetch this object.
243 * \param Message RFC822-formatted data from the worker process.
244 * Use LookupTag() to parse it.
246 * \param Size The size of the object being fetched.
250 virtual void Start(std::string Message
,unsigned long long Size
);
252 /** \brief Custom headers to be sent to the fetch process.
254 * \return a string containing RFC822-style headers that are to be
255 * inserted into the 600 URI Acquire message sent to the fetch
256 * subprocess. The headers are inserted after a newline-less
257 * line, so they should (if nonempty) have a leading newline and
258 * no trailing newline.
260 #if APT_PKG_ABI >= 413
261 virtual std::string
Custom600Headers() const {return std::string();};
263 virtual std::string
Custom600Headers() {return std::string();};
266 /** \brief A "descriptive" URI-like string.
268 * \return a URI that should be used to describe what is being fetched.
270 virtual std::string
DescURI() = 0;
271 /** \brief Short item description.
273 * \return a brief description of the object being fetched.
275 virtual std::string
ShortDesc() {return DescURI();}
277 /** \brief Invoked by the worker when the download is completely done. */
278 virtual void Finished() {};
282 * \return the HashSums of this object, if applicable; otherwise, an
285 HashStringList
HashSums() const {return ExpectedHashes
;};
286 std::string
HashSum() const {HashStringList
const hashes
= HashSums(); HashString
const * const hs
= hashes
.find(NULL
); return hs
!= NULL
? hs
->toStr() : ""; };
288 /** \return the acquire process with which this item is associated. */
289 pkgAcquire
*GetOwner() const {return Owner
;};
290 #if APT_PKG_ABI < 413
291 pkgAcquire
*GetOwner() {return Owner
;};
294 /** \return \b true if this object is being fetched from a trusted source. */
295 #if APT_PKG_ABI >= 413
296 virtual bool IsTrusted() const {return false;};
298 virtual bool IsTrusted() {return false;};
301 /** \brief Report mirror problem
303 * This allows reporting mirror failures back to a centralized
304 * server. The apt-report-mirror-failure script is called for this
306 * \param FailCode A short failure string that is send
308 void ReportMirrorFailure(std::string FailCode
);
310 /** \brief Set the name of the current active subprocess
312 * See also #ActiveSubprocess
314 void SetActiveSubprocess(const std::string
&subprocess
);
316 /** \brief Initialize an item.
318 * Adds the item to the list of items known to the acquire
319 * process, but does not place it into any fetch queues (you must
320 * manually invoke QueueURI() to do so).
322 * \param Owner The new owner of this item.
323 * \param ExpectedHashes of the file represented by this item
325 Item(pkgAcquire
*Owner
,
326 HashStringList
const &ExpectedHashes
=HashStringList(),
327 pkgAcqMetaBase
*TransactionManager
=NULL
);
329 /** \brief Remove this item from its owner's queue by invoking
330 * pkgAcquire::Remove.
336 enum RenameOnErrorState
{
345 /** \brief Rename failed file and set error
347 * \param state respresenting the error we encountered
349 bool RenameOnError(RenameOnErrorState
const state
);
351 /** \brief The HashSums of the item is supposed to have than done */
352 HashStringList ExpectedHashes
;
354 /** \brief The item that is currently being downloaded. */
355 pkgAcquire::ItemDesc Desc
;
358 /** \brief Information about an index patch (aka diff). */ /*{{{*/
359 struct APT_HIDDEN DiffInfo
{
360 /** The filename of the diff. */
363 /** The hashes of the diff */
364 HashStringList result_hashes
;
366 /** The hashes of the file after the diff is applied */
367 HashStringList patch_hashes
;
369 /** The size of the file after the diff is applied */
370 unsigned long long result_size
;
372 /** The size of the diff itself */
373 unsigned long long patch_size
;
376 class pkgAcqMetaBase
: public pkgAcquire::Item
/*{{{*/
381 std::vector
<Item
*> Transaction
;
383 /** \brief A package-system-specific parser for the meta-index file. */
384 indexRecords
*MetaIndexParser
;
386 /** \brief The index files which should be looked up in the meta-index
387 * and then downloaded.
389 const std::vector
<IndexTarget
*>* IndexTargets
;
391 /** \brief If \b true, the index's signature is currently being verified.
395 // required to deal gracefully with problems caused by incorrect ims hits
398 /** \brief The URI of the signature file. Unlike Desc.URI, this is
399 * never modified; it is used to determine the file that is being
404 /** \brief Starts downloading the individual index files.
406 * \param verify If \b true, only indices whose expected hashsum
407 * can be determined from the meta-index will be downloaded, and
408 * the hashsums of indices will be checked (reporting
409 * #StatAuthError if there is a mismatch). If verify is \b false,
410 * no hashsum checking will be performed.
412 void QueueIndexes(bool verify
);
414 /** \brief Called when a file is finished being retrieved.
416 * If the file was not downloaded to DestFile, a copy process is
417 * set up to copy it to DestFile; otherwise, Complete is set to \b
418 * true and the file is moved to its final location.
420 * \param Message The message block received from the fetch
423 bool CheckDownloadDone(const std::string
&Message
);
425 /** \brief Queue the downloaded Signature for verification */
426 void QueueForSignatureVerify(const std::string
&MetaIndexFile
,
427 const std::string
&MetaIndexFileSignature
);
429 #if APT_PKG_ABI >= 413
430 virtual std::string
Custom600Headers() const;
432 virtual std::string
Custom600Headers();
435 /** \brief Called when authentication succeeded.
437 * Sanity-checks the authenticated file, queues up the individual
438 * index files for download, and saves the signature in the lists
439 * directory next to the authenticated list file.
441 * \param Message The message block received from the fetch
444 bool CheckAuthDone(std::string Message
);
446 /** Check if the current item should fail at this point */
447 bool CheckStopAuthentication(const std::string
&Message
);
449 /** \brief Check that the release file is a release file for the
450 * correct distribution.
452 * \return \b true if no fatal errors were encountered.
454 bool VerifyVendor(std::string Message
);
456 /** \brief Get the full pathname of the final file for the current URI */
457 virtual std::string
GetFinalFilename() const;
460 virtual std::string
DescURI() {return RealURI
; };
464 void AbortTransaction();
465 bool TransactionHasError() APT_PURE
;
466 void CommitTransaction();
468 /** \brief Stage (queue) a copy action when the transaction is committed
470 void TransactionStageCopy(Item
*I
,
471 const std::string
&From
,
472 const std::string
&To
);
473 /** \brief Stage (queue) a removal action when the transaction is committed
475 void TransactionStageRemoval(Item
*I
, const std::string
&FinalFile
);
477 pkgAcqMetaBase(pkgAcquire
*Owner
,
478 const std::vector
<IndexTarget
*>* IndexTargets
,
479 indexRecords
* MetaIndexParser
,
480 std::string
const &RealURI
,
481 HashStringList
const &ExpectedHashes
=HashStringList(),
482 pkgAcqMetaBase
*TransactionManager
=NULL
)
483 : Item(Owner
, ExpectedHashes
, TransactionManager
),
484 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
),
485 AuthPass(false), IMSHit(false), RealURI(RealURI
) {};
488 /** \brief An acquire item that downloads the detached signature {{{
489 * of a meta-index (Release) file, then queues up the release
492 * \todo Why protected members?
494 * \sa pkgAcqMetaIndex
496 class APT_HIDDEN pkgAcqMetaSig
: public pkgAcqMetaBase
502 /** \brief The file we need to verify */
503 std::string MetaIndexFile
;
505 /** \brief The file we use to verify the MetaIndexFile with */
506 std::string MetaIndexFileSignature
;
508 /** \brief Long URI description used in the acquire system */
511 /** \brief Short URI description used in the acquire system */
512 std::string ShortDesc
;
516 // Specialized action members
517 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
518 virtual void Done(std::string Message
,unsigned long long Size
,
519 HashStringList
const &Hashes
,
520 pkgAcquire::MethodConfig
*Cnf
);
522 /** \brief Create a new pkgAcqMetaSig. */
523 pkgAcqMetaSig(pkgAcquire
*Owner
,
524 pkgAcqMetaBase
*TransactionManager
,
525 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
526 std::string MetaIndexFile
,
527 const std::vector
<IndexTarget
*>* IndexTargets
,
528 indexRecords
* MetaIndexParser
);
529 virtual ~pkgAcqMetaSig();
532 /** \brief An item that is responsible for downloading the meta-index {{{
533 * file (i.e., Release) itself and verifying its signature.
535 * Once the download and verification are complete, the downloads of
536 * the individual index files are queued up using pkgAcqDiffIndex.
537 * If the meta-index file had a valid signature, the expected hashsums
538 * of the index files will be the md5sums listed in the meta-index;
539 * otherwise, the expected hashsums will be "" (causing the
540 * authentication of the index files to be bypassed).
542 class APT_HIDDEN pkgAcqMetaIndex
: public pkgAcqMetaBase
548 std::string ShortDesc
;
550 /** \brief The URI of the meta-index file for the detached signature */
551 std::string MetaIndexSigURI
;
553 /** \brief A "URI-style" description of the meta-index file */
554 std::string MetaIndexSigURIDesc
;
556 /** \brief A brief description of the meta-index file */
557 std::string MetaIndexSigShortDesc
;
559 /** \brief delayed constructor */
560 void Init(std::string URIDesc
, std::string ShortDesc
);
564 // Specialized action members
565 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
566 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
567 pkgAcquire::MethodConfig
*Cnf
);
568 virtual void Finished();
570 /** \brief Create a new pkgAcqMetaIndex. */
571 pkgAcqMetaIndex(pkgAcquire
*Owner
,
572 pkgAcqMetaBase
*TransactionManager
,
573 std::string URI
,std::string URIDesc
, std::string ShortDesc
,
574 std::string MetaIndexSigURI
, std::string MetaIndexSigURIDesc
, std::string MetaIndexSigShortDesc
,
575 const std::vector
<IndexTarget
*>* IndexTargets
,
576 indexRecords
* MetaIndexParser
);
579 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
580 class APT_HIDDEN pkgAcqMetaClearSig
: public pkgAcqMetaIndex
584 /** \brief The URI of the meta-index file for the detached signature */
585 std::string MetaIndexURI
;
587 /** \brief A "URI-style" description of the meta-index file */
588 std::string MetaIndexURIDesc
;
590 /** \brief A brief description of the meta-index file */
591 std::string MetaIndexShortDesc
;
593 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
594 std::string MetaSigURI
;
596 /** \brief A "URI-style" description of the meta-signature file */
597 std::string MetaSigURIDesc
;
599 /** \brief A brief description of the meta-signature file */
600 std::string MetaSigShortDesc
;
603 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
604 #if APT_PKG_ABI >= 413
605 virtual std::string
Custom600Headers() const;
607 virtual std::string
Custom600Headers();
609 virtual void Done(std::string Message
,unsigned long long Size
,
610 HashStringList
const &Hashes
,
611 pkgAcquire::MethodConfig
*Cnf
);
613 /** \brief Create a new pkgAcqMetaClearSig. */
614 pkgAcqMetaClearSig(pkgAcquire
*Owner
,
615 std::string
const &URI
, std::string
const &URIDesc
, std::string
const &ShortDesc
,
616 std::string
const &MetaIndexURI
, std::string
const &MetaIndexURIDesc
, std::string
const &MetaIndexShortDesc
,
617 std::string
const &MetaSigURI
, std::string
const &MetaSigURIDesc
, std::string
const &MetaSigShortDesc
,
618 const std::vector
<IndexTarget
*>* IndexTargets
,
619 indexRecords
* MetaIndexParser
);
620 virtual ~pkgAcqMetaClearSig();
623 /** \brief Common base class for all classes that deal with fetching {{{
626 class pkgAcqBaseIndex
: public pkgAcquire::Item
631 /** \brief Pointer to the IndexTarget data
633 const struct IndexTarget
* Target
;
635 /** \brief Pointer to the indexRecords parser */
636 indexRecords
*MetaIndexParser
;
638 /** \brief The MetaIndex Key */
641 /** \brief The URI of the index file to recreate at our end (either
642 * by downloading it or by applying partial patches).
646 bool VerifyHashByMetaKey(HashStringList
const &Hashes
);
648 /** \brief Get the full pathname of the final file for the current URI */
649 virtual std::string
GetFinalFilename() const;
651 pkgAcqBaseIndex(pkgAcquire
*Owner
,
652 pkgAcqMetaBase
*TransactionManager
,
653 struct IndexTarget
const * const Target
,
654 HashStringList
const &ExpectedHashes
,
655 indexRecords
*MetaIndexParser
)
656 : Item(Owner
, ExpectedHashes
, TransactionManager
), Target(Target
),
657 MetaIndexParser(MetaIndexParser
) {};
660 /** \brief An item that is responsible for fetching an index file of {{{
661 * package list diffs and starting the package list's download.
663 * This item downloads the Index file and parses it, then enqueues
664 * additional downloads of either the individual patches (using
665 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
667 * \sa pkgAcqIndexDiffs, pkgAcqIndex
669 class APT_HIDDEN pkgAcqDiffIndex
: public pkgAcqBaseIndex
674 /** \brief If \b true, debugging information will be written to std::clog. */
677 /** \brief The index file which will be patched to generate the new
680 std::string CurrentPackagesFile
;
682 /** \brief A description of the Packages file (stored in
683 * pkgAcquire::ItemDesc::Description).
685 std::string Description
;
687 /** \brief If the copy step of the packages file is done
689 bool PackagesFileReadyInPartial
;
691 /** \brief Get the full pathname of the final file for the current URI */
692 virtual std::string
GetFinalFilename() const;
695 // Specialized action members
696 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
697 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
698 pkgAcquire::MethodConfig
*Cnf
);
699 virtual std::string
DescURI() {return RealURI
+ "Index";};
700 #if APT_PKG_ABI >= 413
701 virtual std::string
Custom600Headers() const;
703 virtual std::string
Custom600Headers();
706 /** \brief Parse the Index file for a set of Packages diffs.
708 * Parses the Index file and creates additional download items as
711 * \param IndexDiffFile The name of the Index file.
713 * \return \b true if the Index file was successfully parsed, \b
716 bool ParseDiffIndex(std::string IndexDiffFile
);
719 /** \brief Create a new pkgAcqDiffIndex.
721 * \param Owner The Acquire object that owns this item.
723 * \param URI The URI of the list file to download.
725 * \param URIDesc A long description of the list file to download.
727 * \param ShortDesc A short description of the list file to download.
729 * \param ExpectedHashes The list file's hashsums which are expected.
731 pkgAcqDiffIndex(pkgAcquire
*Owner
,
732 pkgAcqMetaBase
*TransactionManager
,
733 struct IndexTarget
const * const Target
,
734 HashStringList
const &ExpectedHashes
,
735 indexRecords
*MetaIndexParser
);
738 /** \brief An item that is responsible for fetching client-merge patches {{{
739 * that need to be applied to a given package index file.
741 * Instead of downloading and applying each patch one by one like its
742 * sister #pkgAcqIndexDiffs this class will download all patches at once
743 * and call rred with all the patches downloaded once. Rred will then
744 * merge and apply them in one go, which should be a lot faster – but is
745 * incompatible with server-based merges of patches like reprepro can do.
747 * \sa pkgAcqDiffIndex, pkgAcqIndex
749 class APT_HIDDEN pkgAcqIndexMergeDiffs
: public pkgAcqBaseIndex
755 /** \brief If \b true, debugging output will be written to
760 /** \brief description of the file being downloaded. */
761 std::string Description
;
763 /** \brief information about the current patch */
764 struct DiffInfo
const patch
;
766 /** \brief list of all download items for the patches */
767 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
;
769 /** The current status of this patch. */
772 /** \brief The diff is currently being fetched. */
775 /** \brief The diff is currently being applied. */
778 /** \brief the work with this diff is done */
781 /** \brief something bad happened and fallback was triggered */
786 /** \brief Called when the patch file failed to be downloaded.
788 * This method will fall back to downloading the whole index file
789 * outright; its arguments are ignored.
791 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
792 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
793 pkgAcquire::MethodConfig
*Cnf
);
794 virtual std::string
DescURI() {return RealURI
+ "Index";};
796 /** \brief Create an index merge-diff item.
798 * \param Owner The pkgAcquire object that owns this item.
800 * \param URI The URI of the package index file being
803 * \param URIDesc A long description of this item.
805 * \param ShortDesc A brief description of this item.
807 * \param ExpectedHashes The expected md5sum of the completely
808 * reconstructed package index file; the index file will be tested
809 * against this value when it is entirely reconstructed.
811 * \param patch contains infos about the patch this item is supposed
812 * to download which were read from the index
814 * \param allPatches contains all related items so that each item can
815 * check if it was the last one to complete the download step
817 pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
818 pkgAcqMetaBase
*TransactionManager
,
819 struct IndexTarget
const * const Target
,
820 HashStringList
const &ExpectedHash
,
821 indexRecords
*MetaIndexParser
,
822 DiffInfo
const &patch
,
823 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
);
826 /** \brief An item that is responsible for fetching server-merge patches {{{
827 * that need to be applied to a given package index file.
829 * After downloading and applying a single patch, this item will
830 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
831 * patches. If no patch can be found that applies to an intermediate
832 * file or if one of the patches cannot be downloaded, falls back to
833 * downloading the entire package index file using pkgAcqIndex.
835 * \sa pkgAcqDiffIndex, pkgAcqIndex
837 class APT_HIDDEN pkgAcqIndexDiffs
: public pkgAcqBaseIndex
843 /** \brief Queue up the next diff download.
845 * Search for the next available diff that applies to the file
846 * that currently exists on disk, and enqueue it by calling
849 * \return \b true if an applicable diff was found, \b false
852 APT_HIDDEN
bool QueueNextDiff();
854 /** \brief Handle tasks that must be performed after the item
855 * finishes downloading.
857 * Dequeues the item and checks the resulting file's hashsums
858 * against ExpectedHashes after the last patch was applied.
859 * There is no need to check the md5/sha1 after a "normal"
860 * patch because QueueNextDiff() will check the sha1 later.
862 * \param allDone If \b true, the file was entirely reconstructed,
863 * and its md5sum is verified.
865 APT_HIDDEN
void Finish(bool allDone
=false);
869 /** \brief If \b true, debugging output will be written to
874 /** A description of the file being downloaded. */
875 std::string Description
;
877 /** The patches that remain to be downloaded, including the patch
878 * being downloaded right now. This list should be ordered so
879 * that each diff appears before any diff that depends on it.
881 * \todo These are indexed by sha1sum; why not use some sort of
882 * dictionary instead of relying on ordering and stripping them
885 std::vector
<DiffInfo
> available_patches
;
887 /** The current status of this patch. */
890 /** \brief The diff is in an unknown state. */
893 /** \brief The diff is currently being fetched. */
896 /** \brief The diff is currently being uncompressed. */
897 StateUnzipDiff
, // FIXME: No longer used
899 /** \brief The diff is currently being applied. */
905 /** \brief Called when the patch file failed to be downloaded.
907 * This method will fall back to downloading the whole index file
908 * outright; its arguments are ignored.
910 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
912 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
913 pkgAcquire::MethodConfig
*Cnf
);
914 virtual std::string
DescURI() {return RealURI
+ "IndexDiffs";};
916 /** \brief Create an index diff item.
918 * After filling in its basic fields, this invokes Finish(true) if
919 * \a diffs is empty, or QueueNextDiff() otherwise.
921 * \param Owner The pkgAcquire object that owns this item.
923 * \param URI The URI of the package index file being
926 * \param URIDesc A long description of this item.
928 * \param ShortDesc A brief description of this item.
930 * \param ExpectedHashes The expected hashsums of the completely
931 * reconstructed package index file; the index file will be tested
932 * against this value when it is entirely reconstructed.
934 * \param diffs The remaining diffs from the index of diffs. They
935 * should be ordered so that each diff appears before any diff
936 * that depends on it.
938 pkgAcqIndexDiffs(pkgAcquire
*Owner
,
939 pkgAcqMetaBase
*TransactionManager
,
940 struct IndexTarget
const * const Target
,
941 HashStringList
const &ExpectedHash
,
942 indexRecords
*MetaIndexParser
,
943 std::vector
<DiffInfo
> diffs
=std::vector
<DiffInfo
>());
946 /** \brief An acquire item that is responsible for fetching an index {{{
947 * file (e.g., Packages or Sources).
949 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
951 * \todo Why does pkgAcqIndex have protected members?
953 class APT_HIDDEN pkgAcqIndex
: public pkgAcqBaseIndex
959 /** \brief The stages the method goes through
961 * The method first downloads the indexfile, then its decompressed (or
962 * copied) and verified
966 STAGE_DECOMPRESS_AND_VERIFY
,
970 /** \brief Handle what needs to be done when the download is done */
971 void StageDownloadDone(std::string Message
,
972 HashStringList
const &Hashes
,
973 pkgAcquire::MethodConfig
*Cfg
);
975 /** \brief Handle what needs to be done when the decompression/copy is
978 void StageDecompressDone(std::string Message
,
979 HashStringList
const &Hashes
,
980 pkgAcquire::MethodConfig
*Cfg
);
982 /** \brief If \b set, this partially downloaded file will be
983 * removed when the download completes.
985 std::string EraseFileName
;
987 /** \brief The compression-related file extensions that are being
988 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
990 std::string CompressionExtensions
;
992 /** \brief The actual compression extension currently used */
993 std::string CurrentCompressionExtension
;
995 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
996 void InitByHashIfNeeded(const std::string MetaKey
);
998 /** \brief Auto select the right compression to use */
999 void AutoSelectCompression();
1001 /** \brief Schedule file for verification after a IMS hit */
1002 void ReverifyAfterIMS();
1004 /** \brief Validate the downloaded index file */
1005 bool ValidateFile(const std::string
&FileName
);
1007 /** \brief Get the full pathname of the final file for the current URI */
1008 virtual std::string
GetFinalFilename() const;
1012 // Specialized action members
1013 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1014 virtual void Done(std::string Message
,unsigned long long Size
,
1015 HashStringList
const &Hashes
,
1016 pkgAcquire::MethodConfig
*Cnf
);
1017 #if APT_PKG_ABI >= 413
1018 virtual std::string
Custom600Headers() const;
1020 virtual std::string
Custom600Headers();
1022 virtual std::string
DescURI() {return Desc
.URI
;};
1024 /** \brief Create a pkgAcqIndex.
1026 * \param Owner The pkgAcquire object with which this item is
1029 * \param URI The URI of the index file that is to be downloaded.
1031 * \param URIDesc A "URI-style" description of this index file.
1033 * \param ShortDesc A brief description of this index file.
1035 * \param ExpectedHashes The expected hashsum of this index file.
1037 * \param compressExt The compression-related extension with which
1038 * this index file should be downloaded, or "" to autodetect
1039 * Compression types can be set with config Acquire::CompressionTypes,
1040 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1041 * fallback is ".gz" or none.
1043 pkgAcqIndex(pkgAcquire
*Owner
,std::string URI
,std::string URIDesc
,
1044 std::string ShortDesc
, HashStringList
const &ExpectedHashes
);
1045 pkgAcqIndex(pkgAcquire
*Owner
, pkgAcqMetaBase
*TransactionManager
,
1046 IndexTarget
const * const Target
,
1047 HashStringList
const &ExpectedHash
,
1048 indexRecords
*MetaIndexParser
);
1050 void Init(std::string
const &URI
, std::string
const &URIDesc
,
1051 std::string
const &ShortDesc
);
1054 /** \brief Information about an index file. */ /*{{{*/
1055 class APT_HIDDEN IndexTarget
1060 /** \brief A URI from which the index file can be downloaded. */
1063 /** \brief A description of the index file. */
1064 std::string Description
;
1066 /** \brief A shorter description of the index file. */
1067 std::string ShortDesc
;
1069 /** \brief The key by which this index file should be
1070 * looked up within the meta signature file.
1072 std::string MetaKey
;
1074 virtual bool IsOptional() const {
1079 /** \brief Information about an optional index file. */ /*{{{*/
1080 class APT_HIDDEN OptionalIndexTarget
: public IndexTarget
1084 virtual bool IsOptional() const {
1089 /** \brief An item that is responsible for fetching a package file. {{{
1091 * If the package file already exists in the cache, nothing will be
1094 class pkgAcqArchive
: public pkgAcquire::Item
1099 /** \brief The package version being fetched. */
1100 pkgCache::VerIterator Version
;
1102 /** \brief The list of sources from which to pick archives to
1103 * download this package from.
1105 pkgSourceList
*Sources
;
1107 /** \brief A package records object, used to look up the file
1108 * corresponding to each version of the package.
1112 /** \brief A location in which the actual filename of the package
1115 std::string
&StoreFilename
;
1117 /** \brief The next file for this version to try to download. */
1118 pkgCache::VerFileIterator Vf
;
1120 /** \brief How many (more) times to try to find a new source from
1121 * which to download this package version if it fails.
1123 * Set from Acquire::Retries.
1125 unsigned int Retries
;
1127 /** \brief \b true if this version file is being downloaded from a
1132 /** \brief Queue up the next available file for this version. */
1135 /** \brief Get the full pathname of the final file for the current URI */
1136 virtual std::string
GetFinalFilename() const;
1140 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1141 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &Hashes
,
1142 pkgAcquire::MethodConfig
*Cnf
);
1143 virtual std::string
DescURI() {return Desc
.URI
;};
1144 virtual std::string
ShortDesc() {return Desc
.ShortDesc
;};
1145 virtual void Finished();
1146 #if APT_PKG_ABI >= 413
1147 virtual bool IsTrusted() const;
1149 virtual bool IsTrusted();
1152 /** \brief Create a new pkgAcqArchive.
1154 * \param Owner The pkgAcquire object with which this item is
1157 * \param Sources The sources from which to download version
1160 * \param Recs A package records object, used to look up the file
1161 * corresponding to each version of the package.
1163 * \param Version The package version to download.
1165 * \param[out] StoreFilename A location in which the actual filename of
1166 * the package should be stored. It will be set to a guessed
1167 * basename in the constructor, and filled in with a fully
1168 * qualified filename once the download finishes.
1170 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1171 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1172 std::string
&StoreFilename
);
1175 /** \brief Retrieve an arbitrary file to the current directory. {{{
1177 * The file is retrieved even if it is accessed via a URL type that
1178 * normally is a NOP, such as "file". If the download fails, the
1179 * partial file is renamed to get a ".FAILED" extension.
1181 class pkgAcqFile
: public pkgAcquire::Item
1185 /** \brief How many times to retry the download, set from
1188 unsigned int Retries
;
1190 /** \brief Should this file be considered a index file */
1195 // Specialized action members
1196 virtual void Failed(std::string Message
,pkgAcquire::MethodConfig
*Cnf
);
1197 virtual void Done(std::string Message
,unsigned long long Size
, HashStringList
const &CalcHashes
,
1198 pkgAcquire::MethodConfig
*Cnf
);
1199 virtual std::string
DescURI() {return Desc
.URI
;};
1200 #if APT_PKG_ABI >= 413
1201 virtual std::string
Custom600Headers() const;
1203 virtual std::string
Custom600Headers();
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);