]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
merge debian/sid into debian/experimental
[apt.git] / apt-pkg / acquire-item.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
4 /* ######################################################################
5
6 Acquire Item - Item to acquire
7
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.
11
12 Three item classes are provided to provide functionality for
13 downloading of Index, Translation and Packages files.
14
15 A Archive class is provided for downloading .deb files. It does Hash
16 checking and source location as well as a retry algorithm.
17
18 ##################################################################### */
19 /*}}}*/
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
22
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>
28
29 #include <string>
30 #include <vector>
31
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>
38 #endif
39
40 /** \addtogroup acquire
41 * @{
42 *
43 * \file acquire-item.h
44 */
45
46 class indexRecords;
47 class pkgRecords;
48 class pkgSourceList;
49 class IndexTarget;
50 class pkgAcqMetaBase;
51
52 /** \brief Represents the process by which a pkgAcquire object should {{{
53 * retrieve a file or a collection of files.
54 *
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.
61 *
62 * \see pkgAcquire
63 */
64 class pkgAcquire::Item : public WeakPointable
65 {
66 friend class pkgAcqMetaBase;
67
68 void *d;
69
70 protected:
71
72 /** \brief The acquire object with which this item is associated. */
73 pkgAcquire *Owner;
74
75 /** \brief Insert this item into its owner's queue.
76 *
77 * \param Item Metadata about this item (its URI and
78 * description).
79 */
80 void QueueURI(ItemDesc &Item);
81
82 /** \brief Remove this item from its owner's queue. */
83 void Dequeue();
84
85 /** \brief Rename a file without modifying its timestamp.
86 *
87 * Many item methods call this as their final action.
88 *
89 * \param From The file to be renamed.
90 *
91 * \param To The new name of \a From. If \a To exists it will be
92 * overwritten.
93 */
94 bool Rename(std::string From,std::string To);
95
96 public:
97
98 /** \brief The current status of this item. */
99 enum ItemState
100 {
101 /** \brief The item is waiting to be downloaded. */
102 StatIdle,
103
104 /** \brief The item is currently being downloaded. */
105 StatFetching,
106
107 /** \brief The item has been successfully downloaded. */
108 StatDone,
109
110 /** \brief An error was encountered while downloading this
111 * item.
112 */
113 StatError,
114
115 /** \brief The item was downloaded but its authenticity could
116 * not be verified.
117 */
118 StatAuthError,
119
120 /** \brief The item was could not be downloaded because of
121 * a transient network error (e.g. network down)
122 */
123 StatTransientNetworkError,
124 } Status;
125
126 /** \brief Contains a textual description of the error encountered
127 * if #ItemState is #StatError or #StatAuthError.
128 */
129 std::string ErrorText;
130
131 /** \brief The size of the object to fetch. */
132 unsigned long long FileSize;
133
134 /** \brief How much of the object was already fetched. */
135 unsigned long long PartialSize;
136
137 /** \brief If not \b NULL, contains the name of a subprocess that
138 * is operating on this object (for instance, "gzip" or "gpgv").
139 */
140 APT_DEPRECATED const char *Mode;
141
142 /** \brief contains the name of the subprocess that is operating on this object
143 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
144 * as it can manage the lifetime of included string properly. */
145 std::string ActiveSubprocess;
146
147 /** \brief A client-supplied unique identifier.
148 *
149 * This field is initalized to 0; it is meant to be filled in by
150 * clients that wish to use it to uniquely identify items.
151 *
152 * \todo it's unused in apt itself
153 */
154 unsigned long ID;
155
156 /** \brief If \b true, the entire object has been successfully fetched.
157 *
158 * Subclasses should set this to \b true when appropriate.
159 */
160 bool Complete;
161
162 /** \brief If \b true, the URI of this object is "local".
163 *
164 * The only effect of this field is to exclude the object from the
165 * download progress indicator's overall statistics.
166 */
167 bool Local;
168 std::string UsedMirror;
169
170 /** \brief The number of fetch queues into which this item has been
171 * inserted.
172 *
173 * There is one queue for each source from which an item could be
174 * downloaded.
175 *
176 * \sa pkgAcquire
177 */
178 unsigned int QueueCounter;
179
180 /** \brief TransactionManager */
181 pkgAcqMetaBase *TransactionManager;
182
183 /** \brief The number of additional fetch items that are expected
184 * once this item is done.
185 *
186 * Some items like pkgAcqMeta{Index,Sig} will queue additional
187 * items. This variable can be set by the methods if it knows
188 * in advance how many items to expect to get a more accurate
189 * progress.
190 */
191 unsigned int ExpectedAdditionalItems;
192
193 /** \brief The name of the file into which the retrieved object
194 * will be written.
195 */
196 std::string DestFile;
197
198 /** \brief storge name until a transaction is finished */
199 std::string PartialFile;
200
201 /** \brief Invoked by the acquire worker when the object couldn't
202 * be fetched.
203 *
204 * This is a branch of the continuation of the fetch process.
205 *
206 * \param Message An RFC822-formatted message from the acquire
207 * method describing what went wrong. Use LookupTag() to parse
208 * it.
209 *
210 * \param Cnf The method via which the worker tried to fetch this object.
211 *
212 * \sa pkgAcqMethod
213 */
214 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
215
216 /** \brief Invoked by the acquire worker when the object was
217 * fetched successfully.
218 *
219 * Note that the object might \e not have been written to
220 * DestFile; check for the presence of an Alt-Filename entry in
221 * Message to find the file to which it was really written.
222 *
223 * Done is often used to switch from one stage of the processing
224 * to the next (e.g. fetching, unpacking, copying). It is one
225 * branch of the continuation of the fetch process.
226 *
227 * \param Message Data from the acquire method. Use LookupTag()
228 * to parse it.
229 * \param Size The size of the object that was fetched.
230 * \param Hashes The HashSums of the object that was fetched.
231 * \param Cnf The method via which the object was fetched.
232 *
233 * \sa pkgAcqMethod
234 */
235 virtual void Done(std::string Message, unsigned long long Size, HashStringList const &Hashes,
236 pkgAcquire::MethodConfig *Cnf);
237
238 /** \brief Invoked when the worker starts to fetch this object.
239 *
240 * \param Message RFC822-formatted data from the worker process.
241 * Use LookupTag() to parse it.
242 *
243 * \param Size The size of the object being fetched.
244 *
245 * \sa pkgAcqMethod
246 */
247 virtual void Start(std::string Message,unsigned long long Size);
248
249 /** \brief Custom headers to be sent to the fetch process.
250 *
251 * \return a string containing RFC822-style headers that are to be
252 * inserted into the 600 URI Acquire message sent to the fetch
253 * subprocess. The headers are inserted after a newline-less
254 * line, so they should (if nonempty) have a leading newline and
255 * no trailing newline.
256 */
257 #if APT_PKG_ABI >= 413
258 virtual std::string Custom600Headers() const {return std::string();};
259 #else
260 virtual std::string Custom600Headers() {return std::string();};
261 #endif
262
263 /** \brief A "descriptive" URI-like string.
264 *
265 * \return a URI that should be used to describe what is being fetched.
266 */
267 virtual std::string DescURI() = 0;
268 /** \brief Short item description.
269 *
270 * \return a brief description of the object being fetched.
271 */
272 virtual std::string ShortDesc() {return DescURI();}
273
274 /** \brief Invoked by the worker when the download is completely done. */
275 virtual void Finished() {};
276
277 /** \brief HashSums
278 *
279 * \return the HashSums of this object, if applicable; otherwise, an
280 * empty list.
281 */
282 HashStringList HashSums() const {return ExpectedHashes;};
283 std::string HashSum() const {HashStringList const hashes = HashSums(); HashString const * const hs = hashes.find(NULL); return hs != NULL ? hs->toStr() : ""; };
284
285 /** \return the acquire process with which this item is associated. */
286 pkgAcquire *GetOwner() const {return Owner;};
287 #if APT_PKG_ABI < 413
288 pkgAcquire *GetOwner() {return Owner;};
289 #endif
290
291 /** \return \b true if this object is being fetched from a trusted source. */
292 #if APT_PKG_ABI >= 413
293 virtual bool IsTrusted() const {return false;};
294 #else
295 virtual bool IsTrusted() {return false;};
296 #endif
297
298 /** \brief Report mirror problem
299 *
300 * This allows reporting mirror failures back to a centralized
301 * server. The apt-report-mirror-failure script is called for this
302 *
303 * \param FailCode A short failure string that is send
304 */
305 void ReportMirrorFailure(std::string FailCode);
306
307 /** \brief Set the name of the current active subprocess
308 *
309 * See also #ActiveSubprocess
310 */
311 void SetActiveSubprocess(const std::string &subprocess);
312
313 /** \brief Initialize an item.
314 *
315 * Adds the item to the list of items known to the acquire
316 * process, but does not place it into any fetch queues (you must
317 * manually invoke QueueURI() to do so).
318 *
319 * \param Owner The new owner of this item.
320 * \param ExpectedHashes of the file represented by this item
321 */
322 Item(pkgAcquire *Owner,
323 HashStringList const &ExpectedHashes=HashStringList(),
324 pkgAcqMetaBase *TransactionManager=NULL);
325
326 /** \brief Remove this item from its owner's queue by invoking
327 * pkgAcquire::Remove.
328 */
329 virtual ~Item();
330
331 protected:
332
333 enum RenameOnErrorState {
334 HashSumMismatch,
335 SizeMismatch,
336 InvalidFormat,
337 SignatureError,
338 NotClearsigned,
339 MaximumSizeExceeded
340 };
341
342 /** \brief Rename failed file and set error
343 *
344 * \param state respresenting the error we encountered
345 */
346 bool RenameOnError(RenameOnErrorState const state);
347
348 /** \brief The HashSums of the item is supposed to have than done */
349 HashStringList ExpectedHashes;
350
351 /** \brief The item that is currently being downloaded. */
352 pkgAcquire::ItemDesc Desc;
353 };
354 /*}}}*/
355 /** \brief Information about an index patch (aka diff). */ /*{{{*/
356 struct APT_HIDDEN DiffInfo {
357 /** The filename of the diff. */
358 std::string file;
359
360 /** The hashes of the diff */
361 HashStringList result_hashes;
362
363 /** The hashes of the file after the diff is applied */
364 HashStringList patch_hashes;
365
366 /** The size of the file after the diff is applied */
367 unsigned long long result_size;
368
369 /** The size of the diff itself */
370 unsigned long long patch_size;
371 };
372 /*}}}*/
373 class pkgAcqMetaBase : public pkgAcquire::Item /*{{{*/
374 {
375 void *d;
376
377 protected:
378 std::vector<Item*> Transaction;
379
380 /** \brief A package-system-specific parser for the meta-index file. */
381 indexRecords *MetaIndexParser;
382
383 /** \brief The index files which should be looked up in the meta-index
384 * and then downloaded.
385 */
386 const std::vector<IndexTarget*>* IndexTargets;
387
388 /** \brief If \b true, the index's signature is currently being verified.
389 */
390 bool AuthPass;
391
392 // required to deal gracefully with problems caused by incorrect ims hits
393 bool IMSHit;
394
395 /** \brief Starts downloading the individual index files.
396 *
397 * \param verify If \b true, only indices whose expected hashsum
398 * can be determined from the meta-index will be downloaded, and
399 * the hashsums of indices will be checked (reporting
400 * #StatAuthError if there is a mismatch). If verify is \b false,
401 * no hashsum checking will be performed.
402 */
403 void QueueIndexes(bool verify);
404
405 /** \brief Called when a file is finished being retrieved.
406 *
407 * If the file was not downloaded to DestFile, a copy process is
408 * set up to copy it to DestFile; otherwise, Complete is set to \b
409 * true and the file is moved to its final location.
410 *
411 * \param Message The message block received from the fetch
412 * subprocess.
413 */
414 bool CheckDownloadDone(const std::string &Message,
415 const std::string &RealURI);
416
417 /** \brief Queue the downloaded Signature for verification */
418 void QueueForSignatureVerify(const std::string &MetaIndexFile,
419 const std::string &MetaIndexFileSignature);
420
421 /** \brief get the custom600 header for all pkgAcqMeta */
422 std::string GetCustom600Headers(const std::string &RealURI) const;
423
424 /** \brief Called when authentication succeeded.
425 *
426 * Sanity-checks the authenticated file, queues up the individual
427 * index files for download, and saves the signature in the lists
428 * directory next to the authenticated list file.
429 *
430 * \param Message The message block received from the fetch
431 * subprocess.
432 */
433 bool CheckAuthDone(std::string Message, const std::string &RealURI);
434
435 /** Check if the current item should fail at this point */
436 bool CheckStopAuthentication(const std::string &RealURI,
437 const std::string &Message);
438
439 /** \brief Check that the release file is a release file for the
440 * correct distribution.
441 *
442 * \return \b true if no fatal errors were encountered.
443 */
444 bool VerifyVendor(std::string Message, const std::string &RealURI);
445
446 public:
447 // transaction code
448 void Add(Item *I);
449 void AbortTransaction();
450 bool TransactionHasError() APT_PURE;
451 void CommitTransaction();
452
453 /** \brief Stage (queue) a copy action when the transaction is committed
454 */
455 void TransactionStageCopy(Item *I,
456 const std::string &From,
457 const std::string &To);
458 /** \brief Stage (queue) a removal action when the transaction is committed
459 */
460 void TransactionStageRemoval(Item *I, const std::string &FinalFile);
461
462 pkgAcqMetaBase(pkgAcquire *Owner,
463 const std::vector<IndexTarget*>* IndexTargets,
464 indexRecords* MetaIndexParser,
465 HashStringList const &ExpectedHashes=HashStringList(),
466 pkgAcqMetaBase *TransactionManager=NULL)
467 : Item(Owner, ExpectedHashes, TransactionManager),
468 MetaIndexParser(MetaIndexParser), IndexTargets(IndexTargets),
469 AuthPass(false), IMSHit(false) {};
470 };
471 /*}}}*/
472 /** \brief An acquire item that downloads the detached signature {{{
473 * of a meta-index (Release) file, then queues up the release
474 * file itself.
475 *
476 * \todo Why protected members?
477 *
478 * \sa pkgAcqMetaIndex
479 */
480 class APT_HIDDEN pkgAcqMetaSig : public pkgAcqMetaBase
481 {
482 void *d;
483
484 protected:
485
486 /** \brief The URI of the signature file. Unlike Desc.URI, this is
487 * never modified; it is used to determine the file that is being
488 * downloaded.
489 */
490 std::string RealURI;
491
492 /** \brief The file we need to verify */
493 std::string MetaIndexFile;
494
495 /** \brief The file we use to verify the MetaIndexFile with */
496 std::string MetaIndexFileSignature;
497
498 /** \brief Long URI description used in the acquire system */
499 std::string URIDesc;
500
501 /** \brief Short URI description used in the acquire system */
502 std::string ShortDesc;
503
504 public:
505
506 // Specialized action members
507 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
508 virtual void Done(std::string Message,unsigned long long Size,
509 HashStringList const &Hashes,
510 pkgAcquire::MethodConfig *Cnf);
511 #if APT_PKG_ABI >= 413
512 virtual std::string Custom600Headers() const;
513 #else
514 virtual std::string Custom600Headers();
515 #endif
516 virtual std::string DescURI() {return RealURI; };
517
518 /** \brief Create a new pkgAcqMetaSig. */
519 pkgAcqMetaSig(pkgAcquire *Owner,
520 pkgAcqMetaBase *TransactionManager,
521 std::string URI,std::string URIDesc, std::string ShortDesc,
522 std::string MetaIndexFile,
523 const std::vector<IndexTarget*>* IndexTargets,
524 indexRecords* MetaIndexParser);
525 virtual ~pkgAcqMetaSig();
526 };
527 /*}}}*/
528 /** \brief An item that is responsible for downloading the meta-index {{{
529 * file (i.e., Release) itself and verifying its signature.
530 *
531 * Once the download and verification are complete, the downloads of
532 * the individual index files are queued up using pkgAcqDiffIndex.
533 * If the meta-index file had a valid signature, the expected hashsums
534 * of the index files will be the md5sums listed in the meta-index;
535 * otherwise, the expected hashsums will be "" (causing the
536 * authentication of the index files to be bypassed).
537 */
538 class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
539 {
540 void *d;
541
542 protected:
543 /** \brief The URI that is actually being downloaded; never
544 * modified by pkgAcqMetaIndex.
545 */
546 std::string RealURI;
547
548 std::string URIDesc;
549 std::string ShortDesc;
550
551 /** \brief The URI of the meta-index file for the detached signature */
552 std::string MetaIndexSigURI;
553
554 /** \brief A "URI-style" description of the meta-index file */
555 std::string MetaIndexSigURIDesc;
556
557 /** \brief A brief description of the meta-index file */
558 std::string MetaIndexSigShortDesc;
559
560 /** \brief delayed constructor */
561 void Init(std::string URIDesc, std::string ShortDesc);
562
563 public:
564
565 // Specialized action members
566 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
567 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
568 pkgAcquire::MethodConfig *Cnf);
569 #if APT_PKG_ABI >= 413
570 virtual std::string Custom600Headers() const;
571 #else
572 virtual std::string Custom600Headers();
573 #endif
574 virtual std::string DescURI() {return RealURI; };
575 virtual void Finished();
576
577 /** \brief Create a new pkgAcqMetaIndex. */
578 pkgAcqMetaIndex(pkgAcquire *Owner,
579 pkgAcqMetaBase *TransactionManager,
580 std::string URI,std::string URIDesc, std::string ShortDesc,
581 std::string MetaIndexSigURI, std::string MetaIndexSigURIDesc, std::string MetaIndexSigShortDesc,
582 const std::vector<IndexTarget*>* IndexTargets,
583 indexRecords* MetaIndexParser);
584 };
585 /*}}}*/
586 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
587 class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
588 {
589 void *d;
590
591 /** \brief The URI of the meta-index file for the detached signature */
592 std::string MetaIndexURI;
593
594 /** \brief A "URI-style" description of the meta-index file */
595 std::string MetaIndexURIDesc;
596
597 /** \brief A brief description of the meta-index file */
598 std::string MetaIndexShortDesc;
599
600 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
601 std::string MetaSigURI;
602
603 /** \brief A "URI-style" description of the meta-signature file */
604 std::string MetaSigURIDesc;
605
606 /** \brief A brief description of the meta-signature file */
607 std::string MetaSigShortDesc;
608
609 public:
610 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
611 #if APT_PKG_ABI >= 413
612 virtual std::string Custom600Headers() const;
613 #else
614 virtual std::string Custom600Headers();
615 #endif
616 virtual void Done(std::string Message,unsigned long long Size,
617 HashStringList const &Hashes,
618 pkgAcquire::MethodConfig *Cnf);
619
620 /** \brief Create a new pkgAcqMetaClearSig. */
621 pkgAcqMetaClearSig(pkgAcquire *Owner,
622 std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
623 std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
624 std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
625 const std::vector<IndexTarget*>* IndexTargets,
626 indexRecords* MetaIndexParser);
627 virtual ~pkgAcqMetaClearSig();
628 };
629 /*}}}*/
630 /** \brief Common base class for all classes that deal with fetching {{{
631 indexes
632 */
633 class pkgAcqBaseIndex : public pkgAcquire::Item
634 {
635 void *d;
636
637 protected:
638 /** \brief Pointer to the IndexTarget data
639 */
640 const struct IndexTarget * Target;
641
642 /** \brief Pointer to the indexRecords parser */
643 indexRecords *MetaIndexParser;
644
645 /** \brief The MetaIndex Key */
646 std::string MetaKey;
647
648 /** \brief The URI of the index file to recreate at our end (either
649 * by downloading it or by applying partial patches).
650 */
651 std::string RealURI;
652
653 bool VerifyHashByMetaKey(HashStringList const &Hashes);
654
655 pkgAcqBaseIndex(pkgAcquire *Owner,
656 pkgAcqMetaBase *TransactionManager,
657 struct IndexTarget const * const Target,
658 HashStringList const &ExpectedHashes,
659 indexRecords *MetaIndexParser)
660 : Item(Owner, ExpectedHashes, TransactionManager), Target(Target),
661 MetaIndexParser(MetaIndexParser) {};
662 };
663 /*}}}*/
664 /** \brief An item that is responsible for fetching an index file of {{{
665 * package list diffs and starting the package list's download.
666 *
667 * This item downloads the Index file and parses it, then enqueues
668 * additional downloads of either the individual patches (using
669 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
670 *
671 * \sa pkgAcqIndexDiffs, pkgAcqIndex
672 */
673 class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
674 {
675 void *d;
676
677 protected:
678 /** \brief If \b true, debugging information will be written to std::clog. */
679 bool Debug;
680
681 /** \brief The index file which will be patched to generate the new
682 * file.
683 */
684 std::string CurrentPackagesFile;
685
686 /** \brief A description of the Packages file (stored in
687 * pkgAcquire::ItemDesc::Description).
688 */
689 std::string Description;
690
691 /** \brief If the copy step of the packages file is done
692 */
693 bool PackagesFileReadyInPartial;
694
695 public:
696 // Specialized action members
697 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
698 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
699 pkgAcquire::MethodConfig *Cnf);
700 virtual std::string DescURI() {return RealURI + "Index";};
701 #if APT_PKG_ABI >= 413
702 virtual std::string Custom600Headers() const;
703 #else
704 virtual std::string Custom600Headers();
705 #endif
706
707 /** \brief Parse the Index file for a set of Packages diffs.
708 *
709 * Parses the Index file and creates additional download items as
710 * necessary.
711 *
712 * \param IndexDiffFile The name of the Index file.
713 *
714 * \return \b true if the Index file was successfully parsed, \b
715 * false otherwise.
716 */
717 bool ParseDiffIndex(std::string IndexDiffFile);
718
719
720 /** \brief Create a new pkgAcqDiffIndex.
721 *
722 * \param Owner The Acquire object that owns this item.
723 *
724 * \param URI The URI of the list file to download.
725 *
726 * \param URIDesc A long description of the list file to download.
727 *
728 * \param ShortDesc A short description of the list file to download.
729 *
730 * \param ExpectedHashes The list file's hashsums which are expected.
731 */
732 pkgAcqDiffIndex(pkgAcquire *Owner,
733 pkgAcqMetaBase *TransactionManager,
734 struct IndexTarget const * const Target,
735 HashStringList const &ExpectedHashes,
736 indexRecords *MetaIndexParser);
737 };
738 /*}}}*/
739 /** \brief An item that is responsible for fetching client-merge patches {{{
740 * that need to be applied to a given package index file.
741 *
742 * Instead of downloading and applying each patch one by one like its
743 * sister #pkgAcqIndexDiffs this class will download all patches at once
744 * and call rred with all the patches downloaded once. Rred will then
745 * merge and apply them in one go, which should be a lot faster – but is
746 * incompatible with server-based merges of patches like reprepro can do.
747 *
748 * \sa pkgAcqDiffIndex, pkgAcqIndex
749 */
750 class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
751 {
752 void *d;
753
754 protected:
755
756 /** \brief If \b true, debugging output will be written to
757 * std::clog.
758 */
759 bool Debug;
760
761 /** \brief description of the file being downloaded. */
762 std::string Description;
763
764 /** \brief information about the current patch */
765 struct DiffInfo const patch;
766
767 /** \brief list of all download items for the patches */
768 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
769
770 /** The current status of this patch. */
771 enum DiffState
772 {
773 /** \brief The diff is currently being fetched. */
774 StateFetchDiff,
775
776 /** \brief The diff is currently being applied. */
777 StateApplyDiff,
778
779 /** \brief the work with this diff is done */
780 StateDoneDiff,
781
782 /** \brief something bad happened and fallback was triggered */
783 StateErrorDiff
784 } State;
785
786 public:
787 /** \brief Called when the patch file failed to be downloaded.
788 *
789 * This method will fall back to downloading the whole index file
790 * outright; its arguments are ignored.
791 */
792 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
793 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
794 pkgAcquire::MethodConfig *Cnf);
795 virtual std::string DescURI() {return RealURI + "Index";};
796
797 /** \brief Create an index merge-diff item.
798 *
799 * \param Owner The pkgAcquire object that owns this item.
800 *
801 * \param URI The URI of the package index file being
802 * reconstructed.
803 *
804 * \param URIDesc A long description of this item.
805 *
806 * \param ShortDesc A brief description of this item.
807 *
808 * \param ExpectedHashes The expected md5sum of the completely
809 * reconstructed package index file; the index file will be tested
810 * against this value when it is entirely reconstructed.
811 *
812 * \param patch contains infos about the patch this item is supposed
813 * to download which were read from the index
814 *
815 * \param allPatches contains all related items so that each item can
816 * check if it was the last one to complete the download step
817 */
818 pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
819 pkgAcqMetaBase *TransactionManager,
820 struct IndexTarget const * const Target,
821 HashStringList const &ExpectedHash,
822 indexRecords *MetaIndexParser,
823 DiffInfo const &patch,
824 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
825 };
826 /*}}}*/
827 /** \brief An item that is responsible for fetching server-merge patches {{{
828 * that need to be applied to a given package index file.
829 *
830 * After downloading and applying a single patch, this item will
831 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
832 * patches. If no patch can be found that applies to an intermediate
833 * file or if one of the patches cannot be downloaded, falls back to
834 * downloading the entire package index file using pkgAcqIndex.
835 *
836 * \sa pkgAcqDiffIndex, pkgAcqIndex
837 */
838 class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
839 {
840 void *d;
841
842 private:
843
844 /** \brief Queue up the next diff download.
845 *
846 * Search for the next available diff that applies to the file
847 * that currently exists on disk, and enqueue it by calling
848 * QueueURI().
849 *
850 * \return \b true if an applicable diff was found, \b false
851 * otherwise.
852 */
853 APT_HIDDEN bool QueueNextDiff();
854
855 /** \brief Handle tasks that must be performed after the item
856 * finishes downloading.
857 *
858 * Dequeues the item and checks the resulting file's hashsums
859 * against ExpectedHashes after the last patch was applied.
860 * There is no need to check the md5/sha1 after a "normal"
861 * patch because QueueNextDiff() will check the sha1 later.
862 *
863 * \param allDone If \b true, the file was entirely reconstructed,
864 * and its md5sum is verified.
865 */
866 APT_HIDDEN void Finish(bool allDone=false);
867
868 protected:
869
870 /** \brief If \b true, debugging output will be written to
871 * std::clog.
872 */
873 bool Debug;
874
875 /** A description of the file being downloaded. */
876 std::string Description;
877
878 /** The patches that remain to be downloaded, including the patch
879 * being downloaded right now. This list should be ordered so
880 * that each diff appears before any diff that depends on it.
881 *
882 * \todo These are indexed by sha1sum; why not use some sort of
883 * dictionary instead of relying on ordering and stripping them
884 * off the front?
885 */
886 std::vector<DiffInfo> available_patches;
887
888 /** The current status of this patch. */
889 enum DiffState
890 {
891 /** \brief The diff is in an unknown state. */
892 StateFetchUnkown,
893
894 /** \brief The diff is currently being fetched. */
895 StateFetchDiff,
896
897 /** \brief The diff is currently being uncompressed. */
898 StateUnzipDiff, // FIXME: No longer used
899
900 /** \brief The diff is currently being applied. */
901 StateApplyDiff
902 } State;
903
904 public:
905
906 /** \brief Called when the patch file failed to be downloaded.
907 *
908 * This method will fall back to downloading the whole index file
909 * outright; its arguments are ignored.
910 */
911 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
912
913 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
914 pkgAcquire::MethodConfig *Cnf);
915 virtual std::string DescURI() {return RealURI + "IndexDiffs";};
916
917 /** \brief Create an index diff item.
918 *
919 * After filling in its basic fields, this invokes Finish(true) if
920 * \a diffs is empty, or QueueNextDiff() otherwise.
921 *
922 * \param Owner The pkgAcquire object that owns this item.
923 *
924 * \param URI The URI of the package index file being
925 * reconstructed.
926 *
927 * \param URIDesc A long description of this item.
928 *
929 * \param ShortDesc A brief description of this item.
930 *
931 * \param ExpectedHashes The expected hashsums of the completely
932 * reconstructed package index file; the index file will be tested
933 * against this value when it is entirely reconstructed.
934 *
935 * \param diffs The remaining diffs from the index of diffs. They
936 * should be ordered so that each diff appears before any diff
937 * that depends on it.
938 */
939 pkgAcqIndexDiffs(pkgAcquire *Owner,
940 pkgAcqMetaBase *TransactionManager,
941 struct IndexTarget const * const Target,
942 HashStringList const &ExpectedHash,
943 indexRecords *MetaIndexParser,
944 std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
945 };
946 /*}}}*/
947 /** \brief An acquire item that is responsible for fetching an index {{{
948 * file (e.g., Packages or Sources).
949 *
950 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
951 *
952 * \todo Why does pkgAcqIndex have protected members?
953 */
954 class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
955 {
956 void *d;
957
958 protected:
959
960 /** \brief The stages the method goes through
961 *
962 * The method first downloads the indexfile, then its decompressed (or
963 * copied) and verified
964 */
965 enum AllStages {
966 STAGE_DOWNLOAD,
967 STAGE_DECOMPRESS_AND_VERIFY,
968 };
969 AllStages Stage;
970
971 /** \brief Handle what needs to be done when the download is done */
972 void StageDownloadDone(std::string Message,
973 HashStringList const &Hashes,
974 pkgAcquire::MethodConfig *Cfg);
975
976 /** \brief Handle what needs to be done when the decompression/copy is
977 * done
978 */
979 void StageDecompressDone(std::string Message,
980 HashStringList const &Hashes,
981 pkgAcquire::MethodConfig *Cfg);
982
983 /** \brief If \b set, this partially downloaded file will be
984 * removed when the download completes.
985 */
986 std::string EraseFileName;
987
988 /** \brief The compression-related file extensions that are being
989 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
990 */
991 std::string CompressionExtensions;
992
993 /** \brief The actual compression extension currently used */
994 std::string CurrentCompressionExtension;
995
996 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
997 void InitByHashIfNeeded(const std::string MetaKey);
998
999 /** \brief Auto select the right compression to use */
1000 void AutoSelectCompression();
1001
1002 /** \brief Get the full pathname of the final file for the current URI
1003 */
1004 std::string GetFinalFilename() const;
1005
1006 /** \brief Schedule file for verification after a IMS hit */
1007 void ReverifyAfterIMS();
1008
1009 /** \brief Validate the downloaded index file */
1010 bool ValidateFile(const std::string &FileName);
1011
1012 public:
1013
1014 // Specialized action members
1015 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1016 virtual void Done(std::string Message,unsigned long long Size,
1017 HashStringList const &Hashes,
1018 pkgAcquire::MethodConfig *Cnf);
1019 #if APT_PKG_ABI >= 413
1020 virtual std::string Custom600Headers() const;
1021 #else
1022 virtual std::string Custom600Headers();
1023 #endif
1024 virtual std::string DescURI() {return Desc.URI;};
1025
1026 /** \brief Create a pkgAcqIndex.
1027 *
1028 * \param Owner The pkgAcquire object with which this item is
1029 * associated.
1030 *
1031 * \param URI The URI of the index file that is to be downloaded.
1032 *
1033 * \param URIDesc A "URI-style" description of this index file.
1034 *
1035 * \param ShortDesc A brief description of this index file.
1036 *
1037 * \param ExpectedHashes The expected hashsum of this index file.
1038 *
1039 * \param compressExt The compression-related extension with which
1040 * this index file should be downloaded, or "" to autodetect
1041 * Compression types can be set with config Acquire::CompressionTypes,
1042 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1043 * fallback is ".gz" or none.
1044 */
1045 pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
1046 std::string ShortDesc, HashStringList const &ExpectedHashes);
1047 pkgAcqIndex(pkgAcquire *Owner, pkgAcqMetaBase *TransactionManager,
1048 IndexTarget const * const Target,
1049 HashStringList const &ExpectedHash,
1050 indexRecords *MetaIndexParser);
1051
1052 void Init(std::string const &URI, std::string const &URIDesc,
1053 std::string const &ShortDesc);
1054 };
1055 /*}}}*/
1056 /** \brief Information about an index file. */ /*{{{*/
1057 class APT_HIDDEN IndexTarget
1058 {
1059 void *d;
1060
1061 public:
1062 /** \brief A URI from which the index file can be downloaded. */
1063 std::string URI;
1064
1065 /** \brief A description of the index file. */
1066 std::string Description;
1067
1068 /** \brief A shorter description of the index file. */
1069 std::string ShortDesc;
1070
1071 /** \brief The key by which this index file should be
1072 * looked up within the meta signature file.
1073 */
1074 std::string MetaKey;
1075
1076 virtual bool IsOptional() const {
1077 return false;
1078 }
1079 };
1080 /*}}}*/
1081 /** \brief Information about an optional index file. */ /*{{{*/
1082 class APT_HIDDEN OptionalIndexTarget : public IndexTarget
1083 {
1084 void *d;
1085
1086 virtual bool IsOptional() const {
1087 return true;
1088 }
1089 };
1090 /*}}}*/
1091 /** \brief An item that is responsible for fetching a package file. {{{
1092 *
1093 * If the package file already exists in the cache, nothing will be
1094 * done.
1095 */
1096 class pkgAcqArchive : public pkgAcquire::Item
1097 {
1098 void *d;
1099
1100 protected:
1101 /** \brief The package version being fetched. */
1102 pkgCache::VerIterator Version;
1103
1104 /** \brief The list of sources from which to pick archives to
1105 * download this package from.
1106 */
1107 pkgSourceList *Sources;
1108
1109 /** \brief A package records object, used to look up the file
1110 * corresponding to each version of the package.
1111 */
1112 pkgRecords *Recs;
1113
1114 /** \brief A location in which the actual filename of the package
1115 * should be stored.
1116 */
1117 std::string &StoreFilename;
1118
1119 /** \brief The next file for this version to try to download. */
1120 pkgCache::VerFileIterator Vf;
1121
1122 /** \brief How many (more) times to try to find a new source from
1123 * which to download this package version if it fails.
1124 *
1125 * Set from Acquire::Retries.
1126 */
1127 unsigned int Retries;
1128
1129 /** \brief \b true if this version file is being downloaded from a
1130 * trusted source.
1131 */
1132 bool Trusted;
1133
1134 /** \brief Queue up the next available file for this version. */
1135 bool QueueNext();
1136
1137 public:
1138
1139 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1140 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
1141 pkgAcquire::MethodConfig *Cnf);
1142 virtual std::string DescURI() {return Desc.URI;};
1143 virtual std::string ShortDesc() {return Desc.ShortDesc;};
1144 virtual void Finished();
1145 #if APT_PKG_ABI >= 413
1146 virtual bool IsTrusted() const;
1147 #else
1148 virtual bool IsTrusted();
1149 #endif
1150
1151 /** \brief Create a new pkgAcqArchive.
1152 *
1153 * \param Owner The pkgAcquire object with which this item is
1154 * associated.
1155 *
1156 * \param Sources The sources from which to download version
1157 * files.
1158 *
1159 * \param Recs A package records object, used to look up the file
1160 * corresponding to each version of the package.
1161 *
1162 * \param Version The package version to download.
1163 *
1164 * \param[out] StoreFilename A location in which the actual filename of
1165 * the package should be stored. It will be set to a guessed
1166 * basename in the constructor, and filled in with a fully
1167 * qualified filename once the download finishes.
1168 */
1169 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
1170 pkgRecords *Recs,pkgCache::VerIterator const &Version,
1171 std::string &StoreFilename);
1172 };
1173 /*}}}*/
1174 /** \brief Retrieve an arbitrary file to the current directory. {{{
1175 *
1176 * The file is retrieved even if it is accessed via a URL type that
1177 * normally is a NOP, such as "file". If the download fails, the
1178 * partial file is renamed to get a ".FAILED" extension.
1179 */
1180 class pkgAcqFile : public pkgAcquire::Item
1181 {
1182 void *d;
1183
1184 /** \brief How many times to retry the download, set from
1185 * Acquire::Retries.
1186 */
1187 unsigned int Retries;
1188
1189 /** \brief Should this file be considered a index file */
1190 bool IsIndexFile;
1191
1192 public:
1193
1194 // Specialized action members
1195 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1196 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &CalcHashes,
1197 pkgAcquire::MethodConfig *Cnf);
1198 virtual std::string DescURI() {return Desc.URI;};
1199 #if APT_PKG_ABI >= 413
1200 virtual std::string Custom600Headers() const;
1201 #else
1202 virtual std::string Custom600Headers();
1203 #endif
1204
1205 /** \brief Create a new pkgAcqFile object.
1206 *
1207 * \param Owner The pkgAcquire object with which this object is
1208 * associated.
1209 *
1210 * \param URI The URI to download.
1211 *
1212 * \param Hashes The hashsums of the file to download, if they are known;
1213 * otherwise empty list.
1214 *
1215 * \param Size The size of the file to download, if it is known;
1216 * otherwise 0.
1217 *
1218 * \param Desc A description of the file being downloaded.
1219 *
1220 * \param ShortDesc A brief description of the file being
1221 * downloaded.
1222 *
1223 * \param DestDir The directory the file should be downloaded into.
1224 *
1225 * \param DestFilename The filename+path the file is downloaded to.
1226 *
1227 * \param IsIndexFile The file is considered a IndexFile and cache-control
1228 * headers like "cache-control: max-age=0" are send
1229 *
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.
1234 */
1235
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);
1240 };
1241 /*}}}*/
1242 /** @} */
1243
1244 #endif