]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
10d7e6a09d71a69f0e15df357168d5f247f34d48
[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 virtual std::string Custom600Headers() const {return std::string();};
258
259 /** \brief A "descriptive" URI-like string.
260 *
261 * \return a URI that should be used to describe what is being fetched.
262 */
263 virtual std::string DescURI() = 0;
264 /** \brief Short item description.
265 *
266 * \return a brief description of the object being fetched.
267 */
268 virtual std::string ShortDesc() {return DescURI();}
269
270 /** \brief Invoked by the worker when the download is completely done. */
271 virtual void Finished() {};
272
273 /** \brief HashSums
274 *
275 * \return the HashSums of this object, if applicable; otherwise, an
276 * empty list.
277 */
278 HashStringList HashSums() const {return ExpectedHashes;};
279 std::string HashSum() const {HashStringList const hashes = HashSums(); HashString const * const hs = hashes.find(NULL); return hs != NULL ? hs->toStr() : ""; };
280
281 /** \return the acquire process with which this item is associated. */
282 pkgAcquire *GetOwner() const {return Owner;};
283
284 /** \return \b true if this object is being fetched from a trusted source. */
285 virtual bool IsTrusted() const {return false;};
286
287 /** \brief Report mirror problem
288 *
289 * This allows reporting mirror failures back to a centralized
290 * server. The apt-report-mirror-failure script is called for this
291 *
292 * \param FailCode A short failure string that is send
293 */
294 void ReportMirrorFailure(std::string FailCode);
295
296 /** \brief Set the name of the current active subprocess
297 *
298 * See also #ActiveSubprocess
299 */
300 void SetActiveSubprocess(const std::string &subprocess);
301
302 /** \brief Initialize an item.
303 *
304 * Adds the item to the list of items known to the acquire
305 * process, but does not place it into any fetch queues (you must
306 * manually invoke QueueURI() to do so).
307 *
308 * \param Owner The new owner of this item.
309 * \param ExpectedHashes of the file represented by this item
310 */
311 Item(pkgAcquire *Owner,
312 HashStringList const &ExpectedHashes=HashStringList(),
313 pkgAcqMetaBase *TransactionManager=NULL);
314
315 /** \brief Remove this item from its owner's queue by invoking
316 * pkgAcquire::Remove.
317 */
318 virtual ~Item();
319
320 protected:
321
322 enum RenameOnErrorState {
323 HashSumMismatch,
324 SizeMismatch,
325 InvalidFormat,
326 SignatureError,
327 NotClearsigned,
328 MaximumSizeExceeded
329 };
330
331 /** \brief Rename failed file and set error
332 *
333 * \param state respresenting the error we encountered
334 */
335 bool RenameOnError(RenameOnErrorState const state);
336
337 /** \brief The HashSums of the item is supposed to have than done */
338 HashStringList ExpectedHashes;
339
340 /** \brief The item that is currently being downloaded. */
341 pkgAcquire::ItemDesc Desc;
342 };
343 /*}}}*/
344 /** \brief Information about an index patch (aka diff). */ /*{{{*/
345 struct DiffInfo {
346 /** The filename of the diff. */
347 std::string file;
348
349 /** The hashes of the diff */
350 HashStringList result_hashes;
351
352 /** The hashes of the file after the diff is applied */
353 HashStringList patch_hashes;
354
355 /** The size of the file after the diff is applied */
356 unsigned long long result_size;
357
358 /** The size of the diff itself */
359 unsigned long long patch_size;
360 };
361 /*}}}*/
362 /*}}}*/
363
364 class pkgAcqMetaBase : public pkgAcquire::Item
365 {
366 void *d;
367
368 protected:
369 std::vector<Item*> Transaction;
370
371 /** \brief A package-system-specific parser for the meta-index file. */
372 indexRecords *MetaIndexParser;
373
374 /** \brief The index files which should be looked up in the meta-index
375 * and then downloaded.
376 */
377 const std::vector<IndexTarget*>* IndexTargets;
378
379 /** \brief If \b true, the index's signature is currently being verified.
380 */
381 bool AuthPass;
382
383 // required to deal gracefully with problems caused by incorrect ims hits
384 bool IMSHit;
385
386 /** \brief Starts downloading the individual index files.
387 *
388 * \param verify If \b true, only indices whose expected hashsum
389 * can be determined from the meta-index will be downloaded, and
390 * the hashsums of indices will be checked (reporting
391 * #StatAuthError if there is a mismatch). If verify is \b false,
392 * no hashsum checking will be performed.
393 */
394 void QueueIndexes(bool verify);
395
396 /** \brief Called when a file is finished being retrieved.
397 *
398 * If the file was not downloaded to DestFile, a copy process is
399 * set up to copy it to DestFile; otherwise, Complete is set to \b
400 * true and the file is moved to its final location.
401 *
402 * \param Message The message block received from the fetch
403 * subprocess.
404 */
405 bool CheckDownloadDone(const std::string &Message,
406 const std::string &RealURI);
407
408 /** \brief Queue the downloaded Signature for verification */
409 void QueueForSignatureVerify(const std::string &MetaIndexFile,
410 const std::string &MetaIndexFileSignature);
411
412 /** \brief get the custom600 header for all pkgAcqMeta */
413 std::string GetCustom600Headers(const std::string &RealURI) const;
414
415 /** \brief Called when authentication succeeded.
416 *
417 * Sanity-checks the authenticated file, queues up the individual
418 * index files for download, and saves the signature in the lists
419 * directory next to the authenticated list file.
420 *
421 * \param Message The message block received from the fetch
422 * subprocess.
423 */
424 bool CheckAuthDone(std::string Message, const std::string &RealURI);
425
426 /** Check if the current item should fail at this point */
427 bool CheckStopAuthentication(const std::string &RealURI,
428 const std::string &Message);
429
430 /** \brief Check that the release file is a release file for the
431 * correct distribution.
432 *
433 * \return \b true if no fatal errors were encountered.
434 */
435 bool VerifyVendor(std::string Message, const std::string &RealURI);
436
437 public:
438 // transaction code
439 void Add(Item *I);
440 void AbortTransaction();
441 bool TransactionHasError() APT_PURE;
442 void CommitTransaction();
443
444 /** \brief Stage (queue) a copy action when the transaction is commited
445 */
446 void TransactionStageCopy(Item *I,
447 const std::string &From,
448 const std::string &To);
449 /** \brief Stage (queue) a removal action when the transaction is commited
450 */
451 void TransactionStageRemoval(Item *I, const std::string &FinalFile);
452
453 pkgAcqMetaBase(pkgAcquire *Owner,
454 const std::vector<IndexTarget*>* IndexTargets,
455 indexRecords* MetaIndexParser,
456 HashStringList const &ExpectedHashes=HashStringList(),
457 pkgAcqMetaBase *TransactionManager=NULL)
458 : Item(Owner, ExpectedHashes, TransactionManager),
459 MetaIndexParser(MetaIndexParser), IndexTargets(IndexTargets),
460 AuthPass(false), IMSHit(false) {};
461 };
462
463 /** \brief An acquire item that downloads the detached signature {{{
464 * of a meta-index (Release) file, then queues up the release
465 * file itself.
466 *
467 * \todo Why protected members?
468 *
469 * \sa pkgAcqMetaIndex
470 */
471 class pkgAcqMetaSig : public pkgAcqMetaBase
472 {
473 void *d;
474
475 protected:
476
477 /** \brief The URI of the signature file. Unlike Desc.URI, this is
478 * never modified; it is used to determine the file that is being
479 * downloaded.
480 */
481 std::string RealURI;
482
483 /** \brief The file we need to verify */
484 std::string MetaIndexFile;
485
486 /** \brief The file we use to verify the MetaIndexFile with */
487 std::string MetaIndexFileSignature;
488
489 /** \brief Long URI description used in the acquire system */
490 std::string URIDesc;
491
492 /** \brief Short URI description used in the acquire system */
493 std::string ShortDesc;
494
495 public:
496
497 // Specialized action members
498 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
499 virtual void Done(std::string Message,unsigned long long Size,
500 HashStringList const &Hashes,
501 pkgAcquire::MethodConfig *Cnf);
502 virtual std::string Custom600Headers() const;
503 virtual std::string DescURI() {return RealURI; };
504
505 /** \brief Create a new pkgAcqMetaSig. */
506 pkgAcqMetaSig(pkgAcquire *Owner,
507 pkgAcqMetaBase *TransactionManager,
508 std::string URI,std::string URIDesc, std::string ShortDesc,
509 std::string MetaIndexFile,
510 const std::vector<IndexTarget*>* IndexTargets,
511 indexRecords* MetaIndexParser);
512 virtual ~pkgAcqMetaSig();
513 };
514 /*}}}*/
515
516 /** \brief An item that is responsible for downloading the meta-index {{{
517 * file (i.e., Release) itself and verifying its signature.
518 *
519 * Once the download and verification are complete, the downloads of
520 * the individual index files are queued up using pkgAcqDiffIndex.
521 * If the meta-index file had a valid signature, the expected hashsums
522 * of the index files will be the md5sums listed in the meta-index;
523 * otherwise, the expected hashsums will be "" (causing the
524 * authentication of the index files to be bypassed).
525 */
526 class pkgAcqMetaIndex : public pkgAcqMetaBase
527 {
528 void *d;
529
530 protected:
531 /** \brief The URI that is actually being downloaded; never
532 * modified by pkgAcqMetaIndex.
533 */
534 std::string RealURI;
535
536 std::string URIDesc;
537 std::string ShortDesc;
538
539 /** \brief The URI of the meta-index file for the detached signature */
540 std::string MetaIndexSigURI;
541
542 /** \brief A "URI-style" description of the meta-index file */
543 std::string MetaIndexSigURIDesc;
544
545 /** \brief A brief description of the meta-index file */
546 std::string MetaIndexSigShortDesc;
547
548 /** \brief delayed constructor */
549 void Init(std::string URIDesc, std::string ShortDesc);
550
551 public:
552
553 // Specialized action members
554 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
555 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
556 pkgAcquire::MethodConfig *Cnf);
557 virtual std::string Custom600Headers() const;
558 virtual std::string DescURI() {return RealURI; };
559 virtual void Finished();
560
561 /** \brief Create a new pkgAcqMetaIndex. */
562 pkgAcqMetaIndex(pkgAcquire *Owner,
563 pkgAcqMetaBase *TransactionManager,
564 std::string URI,std::string URIDesc, std::string ShortDesc,
565 std::string MetaIndexSigURI, std::string MetaIndexSigURIDesc, std::string MetaIndexSigShortDesc,
566 const std::vector<IndexTarget*>* IndexTargets,
567 indexRecords* MetaIndexParser);
568 };
569 /*}}}*/
570 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
571 class pkgAcqMetaClearSig : public pkgAcqMetaIndex
572 {
573 void *d;
574
575 /** \brief The URI of the meta-index file for the detached signature */
576 std::string MetaIndexURI;
577
578 /** \brief A "URI-style" description of the meta-index file */
579 std::string MetaIndexURIDesc;
580
581 /** \brief A brief description of the meta-index file */
582 std::string MetaIndexShortDesc;
583
584 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
585 std::string MetaSigURI;
586
587 /** \brief A "URI-style" description of the meta-signature file */
588 std::string MetaSigURIDesc;
589
590 /** \brief A brief description of the meta-signature file */
591 std::string MetaSigShortDesc;
592
593 public:
594 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
595 virtual std::string Custom600Headers() const;
596 virtual void Done(std::string Message,unsigned long long Size,
597 HashStringList const &Hashes,
598 pkgAcquire::MethodConfig *Cnf);
599
600 /** \brief Create a new pkgAcqMetaClearSig. */
601 pkgAcqMetaClearSig(pkgAcquire *Owner,
602 std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
603 std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
604 std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
605 const std::vector<IndexTarget*>* IndexTargets,
606 indexRecords* MetaIndexParser);
607 virtual ~pkgAcqMetaClearSig();
608 };
609 /*}}}*/
610
611
612 /** \brief Common base class for all classes that deal with fetching {{{
613 indexes
614 */
615 class pkgAcqBaseIndex : public pkgAcquire::Item
616 {
617 void *d;
618
619 protected:
620 /** \brief Pointer to the IndexTarget data
621 */
622 const struct IndexTarget * Target;
623
624 /** \brief Pointer to the indexRecords parser */
625 indexRecords *MetaIndexParser;
626
627 /** \brief The MetaIndex Key */
628 std::string MetaKey;
629
630 /** \brief The URI of the index file to recreate at our end (either
631 * by downloading it or by applying partial patches).
632 */
633 std::string RealURI;
634
635 bool VerifyHashByMetaKey(HashStringList const &Hashes);
636
637 pkgAcqBaseIndex(pkgAcquire *Owner,
638 pkgAcqMetaBase *TransactionManager,
639 struct IndexTarget const * const Target,
640 HashStringList const &ExpectedHashes,
641 indexRecords *MetaIndexParser)
642 : Item(Owner, ExpectedHashes, TransactionManager), Target(Target),
643 MetaIndexParser(MetaIndexParser) {};
644 };
645 /*}}}*/
646 /** \brief An item that is responsible for fetching an index file of {{{
647 * package list diffs and starting the package list's download.
648 *
649 * This item downloads the Index file and parses it, then enqueues
650 * additional downloads of either the individual patches (using
651 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
652 *
653 * \sa pkgAcqIndexDiffs, pkgAcqIndex
654 */
655 class pkgAcqDiffIndex : public pkgAcqBaseIndex
656 {
657 void *d;
658
659 protected:
660 /** \brief If \b true, debugging information will be written to std::clog. */
661 bool Debug;
662
663 /** \brief The index file which will be patched to generate the new
664 * file.
665 */
666 std::string CurrentPackagesFile;
667
668 /** \brief A description of the Packages file (stored in
669 * pkgAcquire::ItemDesc::Description).
670 */
671 std::string Description;
672
673 /** \brief If the copy step of the packages file is done
674 */
675 bool PackagesFileReadyInPartial;
676
677 public:
678 // Specialized action members
679 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
680 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
681 pkgAcquire::MethodConfig *Cnf);
682 virtual std::string DescURI() {return RealURI + "Index";};
683 virtual std::string Custom600Headers() const;
684
685 /** \brief Parse the Index file for a set of Packages diffs.
686 *
687 * Parses the Index file and creates additional download items as
688 * necessary.
689 *
690 * \param IndexDiffFile The name of the Index file.
691 *
692 * \return \b true if the Index file was successfully parsed, \b
693 * false otherwise.
694 */
695 bool ParseDiffIndex(std::string IndexDiffFile);
696
697
698 /** \brief Create a new pkgAcqDiffIndex.
699 *
700 * \param Owner The Acquire object that owns this item.
701 *
702 * \param URI The URI of the list file to download.
703 *
704 * \param URIDesc A long description of the list file to download.
705 *
706 * \param ShortDesc A short description of the list file to download.
707 *
708 * \param ExpectedHashes The list file's hashsums which are expected.
709 */
710 pkgAcqDiffIndex(pkgAcquire *Owner,
711 pkgAcqMetaBase *TransactionManager,
712 struct IndexTarget const * const Target,
713 HashStringList const &ExpectedHashes,
714 indexRecords *MetaIndexParser);
715 };
716 /*}}}*/
717 /** \brief An item that is responsible for fetching client-merge patches {{{
718 * that need to be applied to a given package index file.
719 *
720 * Instead of downloading and applying each patch one by one like its
721 * sister #pkgAcqIndexDiffs this class will download all patches at once
722 * and call rred with all the patches downloaded once. Rred will then
723 * merge and apply them in one go, which should be a lot faster – but is
724 * incompatible with server-based merges of patches like reprepro can do.
725 *
726 * \sa pkgAcqDiffIndex, pkgAcqIndex
727 */
728 class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
729 {
730 void *d;
731
732 protected:
733
734 /** \brief If \b true, debugging output will be written to
735 * std::clog.
736 */
737 bool Debug;
738
739 /** \brief description of the file being downloaded. */
740 std::string Description;
741
742 /** \brief information about the current patch */
743 struct DiffInfo const patch;
744
745 /** \brief list of all download items for the patches */
746 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
747
748 /** The current status of this patch. */
749 enum DiffState
750 {
751 /** \brief The diff is currently being fetched. */
752 StateFetchDiff,
753
754 /** \brief The diff is currently being applied. */
755 StateApplyDiff,
756
757 /** \brief the work with this diff is done */
758 StateDoneDiff,
759
760 /** \brief something bad happened and fallback was triggered */
761 StateErrorDiff
762 } State;
763
764 public:
765 /** \brief Called when the patch file failed to be downloaded.
766 *
767 * This method will fall back to downloading the whole index file
768 * outright; its arguments are ignored.
769 */
770 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
771 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
772 pkgAcquire::MethodConfig *Cnf);
773 virtual std::string DescURI() {return RealURI + "Index";};
774
775 /** \brief Create an index merge-diff item.
776 *
777 * \param Owner The pkgAcquire object that owns this item.
778 *
779 * \param URI The URI of the package index file being
780 * reconstructed.
781 *
782 * \param URIDesc A long description of this item.
783 *
784 * \param ShortDesc A brief description of this item.
785 *
786 * \param ExpectedHashes The expected md5sum of the completely
787 * reconstructed package index file; the index file will be tested
788 * against this value when it is entirely reconstructed.
789 *
790 * \param patch contains infos about the patch this item is supposed
791 * to download which were read from the index
792 *
793 * \param allPatches contains all related items so that each item can
794 * check if it was the last one to complete the download step
795 */
796 pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
797 pkgAcqMetaBase *TransactionManager,
798 struct IndexTarget const * const Target,
799 HashStringList const &ExpectedHash,
800 indexRecords *MetaIndexParser,
801 DiffInfo const &patch,
802 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
803 };
804 /*}}}*/
805 /** \brief An item that is responsible for fetching server-merge patches {{{
806 * that need to be applied to a given package index file.
807 *
808 * After downloading and applying a single patch, this item will
809 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
810 * patches. If no patch can be found that applies to an intermediate
811 * file or if one of the patches cannot be downloaded, falls back to
812 * downloading the entire package index file using pkgAcqIndex.
813 *
814 * \sa pkgAcqDiffIndex, pkgAcqIndex
815 */
816 class pkgAcqIndexDiffs : public pkgAcqBaseIndex
817 {
818 void *d;
819
820 private:
821
822 /** \brief Queue up the next diff download.
823 *
824 * Search for the next available diff that applies to the file
825 * that currently exists on disk, and enqueue it by calling
826 * QueueURI().
827 *
828 * \return \b true if an applicable diff was found, \b false
829 * otherwise.
830 */
831 APT_HIDDEN bool QueueNextDiff();
832
833 /** \brief Handle tasks that must be performed after the item
834 * finishes downloading.
835 *
836 * Dequeues the item and checks the resulting file's hashsums
837 * against ExpectedHashes after the last patch was applied.
838 * There is no need to check the md5/sha1 after a "normal"
839 * patch because QueueNextDiff() will check the sha1 later.
840 *
841 * \param allDone If \b true, the file was entirely reconstructed,
842 * and its md5sum is verified.
843 */
844 APT_HIDDEN void Finish(bool allDone=false);
845
846 protected:
847
848 /** \brief If \b true, debugging output will be written to
849 * std::clog.
850 */
851 bool Debug;
852
853 /** A description of the file being downloaded. */
854 std::string Description;
855
856 /** The patches that remain to be downloaded, including the patch
857 * being downloaded right now. This list should be ordered so
858 * that each diff appears before any diff that depends on it.
859 *
860 * \todo These are indexed by sha1sum; why not use some sort of
861 * dictionary instead of relying on ordering and stripping them
862 * off the front?
863 */
864 std::vector<DiffInfo> available_patches;
865
866 /** The current status of this patch. */
867 enum DiffState
868 {
869 /** \brief The diff is in an unknown state. */
870 StateFetchUnkown,
871
872 /** \brief The diff is currently being fetched. */
873 StateFetchDiff,
874
875 /** \brief The diff is currently being uncompressed. */
876 StateUnzipDiff, // FIXME: No longer used
877
878 /** \brief The diff is currently being applied. */
879 StateApplyDiff
880 } State;
881
882 public:
883
884 /** \brief Called when the patch file failed to be downloaded.
885 *
886 * This method will fall back to downloading the whole index file
887 * outright; its arguments are ignored.
888 */
889 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
890
891 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
892 pkgAcquire::MethodConfig *Cnf);
893 virtual std::string DescURI() {return RealURI + "IndexDiffs";};
894
895 /** \brief Create an index diff item.
896 *
897 * After filling in its basic fields, this invokes Finish(true) if
898 * \a diffs is empty, or QueueNextDiff() otherwise.
899 *
900 * \param Owner The pkgAcquire object that owns this item.
901 *
902 * \param URI The URI of the package index file being
903 * reconstructed.
904 *
905 * \param URIDesc A long description of this item.
906 *
907 * \param ShortDesc A brief description of this item.
908 *
909 * \param ExpectedHashes The expected hashsums of the completely
910 * reconstructed package index file; the index file will be tested
911 * against this value when it is entirely reconstructed.
912 *
913 * \param diffs The remaining diffs from the index of diffs. They
914 * should be ordered so that each diff appears before any diff
915 * that depends on it.
916 */
917 pkgAcqIndexDiffs(pkgAcquire *Owner,
918 pkgAcqMetaBase *TransactionManager,
919 struct IndexTarget const * const Target,
920 HashStringList const &ExpectedHash,
921 indexRecords *MetaIndexParser,
922 std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
923 };
924 /*}}}*/
925 /** \brief An acquire item that is responsible for fetching an index {{{
926 * file (e.g., Packages or Sources).
927 *
928 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
929 *
930 * \todo Why does pkgAcqIndex have protected members?
931 */
932 class pkgAcqIndex : public pkgAcqBaseIndex
933 {
934 void *d;
935
936 protected:
937
938 /** \brief The stages the method goes through
939 *
940 * The method first downloads the indexfile, then its decompressed (or
941 * copied) and verified
942 */
943 enum AllStages {
944 STAGE_DOWNLOAD,
945 STAGE_DECOMPRESS_AND_VERIFY,
946 };
947 AllStages Stage;
948
949 /** \brief Handle what needs to be done when the download is done */
950 void StageDownloadDone(std::string Message,
951 HashStringList const &Hashes,
952 pkgAcquire::MethodConfig *Cfg);
953
954 /** \brief Handle what needs to be done when the decompression/copy is
955 * done
956 */
957 void StageDecompressDone(std::string Message,
958 HashStringList const &Hashes,
959 pkgAcquire::MethodConfig *Cfg);
960
961 /** \brief If \b set, this partially downloaded file will be
962 * removed when the download completes.
963 */
964 std::string EraseFileName;
965
966 /** \brief The compression-related file extensions that are being
967 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
968 */
969 std::string CompressionExtensions;
970
971 /** \brief The actual compression extension currently used */
972 std::string CurrentCompressionExtension;
973
974 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
975 void InitByHashIfNeeded(const std::string MetaKey);
976
977 /** \brief Auto select the right compression to use */
978 void AutoSelectCompression();
979
980 /** \brief Get the full pathname of the final file for the current URI
981 */
982 std::string GetFinalFilename() const;
983
984 /** \brief Schedule file for verification after a IMS hit */
985 void ReverifyAfterIMS();
986
987 /** \brief Validate the downloaded index file */
988 bool ValidateFile(const std::string &FileName);
989
990 public:
991
992 // Specialized action members
993 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
994 virtual void Done(std::string Message,unsigned long long Size,
995 HashStringList const &Hashes,
996 pkgAcquire::MethodConfig *Cnf);
997 virtual std::string Custom600Headers() const;
998 virtual std::string DescURI() {return Desc.URI;};
999
1000 /** \brief Create a pkgAcqIndex.
1001 *
1002 * \param Owner The pkgAcquire object with which this item is
1003 * associated.
1004 *
1005 * \param URI The URI of the index file that is to be downloaded.
1006 *
1007 * \param URIDesc A "URI-style" description of this index file.
1008 *
1009 * \param ShortDesc A brief description of this index file.
1010 *
1011 * \param ExpectedHashes The expected hashsum of this index file.
1012 *
1013 * \param compressExt The compression-related extension with which
1014 * this index file should be downloaded, or "" to autodetect
1015 * Compression types can be set with config Acquire::CompressionTypes,
1016 * default is ".lzma" or ".bz2" (if the needed binaries are present)
1017 * fallback is ".gz" or none.
1018 */
1019 pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
1020 std::string ShortDesc, HashStringList const &ExpectedHashes);
1021 pkgAcqIndex(pkgAcquire *Owner, pkgAcqMetaBase *TransactionManager,
1022 IndexTarget const * const Target,
1023 HashStringList const &ExpectedHash,
1024 indexRecords *MetaIndexParser);
1025
1026 void Init(std::string const &URI, std::string const &URIDesc,
1027 std::string const &ShortDesc);
1028 };
1029 /*}}}*/
1030 /** \brief Information about an index file. */ /*{{{*/
1031 class IndexTarget
1032 {
1033 void *d;
1034
1035 public:
1036 /** \brief A URI from which the index file can be downloaded. */
1037 std::string URI;
1038
1039 /** \brief A description of the index file. */
1040 std::string Description;
1041
1042 /** \brief A shorter description of the index file. */
1043 std::string ShortDesc;
1044
1045 /** \brief The key by which this index file should be
1046 * looked up within the meta signature file.
1047 */
1048 std::string MetaKey;
1049
1050 virtual bool IsOptional() const {
1051 return false;
1052 }
1053 };
1054 /*}}}*/
1055 /** \brief Information about an optional index file. */ /*{{{*/
1056 class OptionalIndexTarget : public IndexTarget
1057 {
1058 void *d;
1059
1060 virtual bool IsOptional() const {
1061 return true;
1062 }
1063 };
1064 /*}}}*/
1065 /** \brief An item that is responsible for fetching a package file. {{{
1066 *
1067 * If the package file already exists in the cache, nothing will be
1068 * done.
1069 */
1070 class pkgAcqArchive : public pkgAcquire::Item
1071 {
1072 void *d;
1073
1074 protected:
1075 /** \brief The package version being fetched. */
1076 pkgCache::VerIterator Version;
1077
1078 /** \brief The list of sources from which to pick archives to
1079 * download this package from.
1080 */
1081 pkgSourceList *Sources;
1082
1083 /** \brief A package records object, used to look up the file
1084 * corresponding to each version of the package.
1085 */
1086 pkgRecords *Recs;
1087
1088 /** \brief A location in which the actual filename of the package
1089 * should be stored.
1090 */
1091 std::string &StoreFilename;
1092
1093 /** \brief The next file for this version to try to download. */
1094 pkgCache::VerFileIterator Vf;
1095
1096 /** \brief How many (more) times to try to find a new source from
1097 * which to download this package version if it fails.
1098 *
1099 * Set from Acquire::Retries.
1100 */
1101 unsigned int Retries;
1102
1103 /** \brief \b true if this version file is being downloaded from a
1104 * trusted source.
1105 */
1106 bool Trusted;
1107
1108 /** \brief Queue up the next available file for this version. */
1109 bool QueueNext();
1110
1111 public:
1112
1113 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1114 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
1115 pkgAcquire::MethodConfig *Cnf);
1116 virtual std::string DescURI() {return Desc.URI;};
1117 virtual std::string ShortDesc() {return Desc.ShortDesc;};
1118 virtual void Finished();
1119 virtual bool IsTrusted() const;
1120
1121 /** \brief Create a new pkgAcqArchive.
1122 *
1123 * \param Owner The pkgAcquire object with which this item is
1124 * associated.
1125 *
1126 * \param Sources The sources from which to download version
1127 * files.
1128 *
1129 * \param Recs A package records object, used to look up the file
1130 * corresponding to each version of the package.
1131 *
1132 * \param Version The package version to download.
1133 *
1134 * \param[out] StoreFilename A location in which the actual filename of
1135 * the package should be stored. It will be set to a guessed
1136 * basename in the constructor, and filled in with a fully
1137 * qualified filename once the download finishes.
1138 */
1139 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
1140 pkgRecords *Recs,pkgCache::VerIterator const &Version,
1141 std::string &StoreFilename);
1142 };
1143 /*}}}*/
1144 /** \brief Retrieve an arbitrary file to the current directory. {{{
1145 *
1146 * The file is retrieved even if it is accessed via a URL type that
1147 * normally is a NOP, such as "file". If the download fails, the
1148 * partial file is renamed to get a ".FAILED" extension.
1149 */
1150 class pkgAcqFile : public pkgAcquire::Item
1151 {
1152 void *d;
1153
1154 /** \brief How many times to retry the download, set from
1155 * Acquire::Retries.
1156 */
1157 unsigned int Retries;
1158
1159 /** \brief Should this file be considered a index file */
1160 bool IsIndexFile;
1161
1162 public:
1163
1164 // Specialized action members
1165 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1166 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &CalcHashes,
1167 pkgAcquire::MethodConfig *Cnf);
1168 virtual std::string DescURI() {return Desc.URI;};
1169 virtual std::string Custom600Headers() const;
1170
1171 /** \brief Create a new pkgAcqFile object.
1172 *
1173 * \param Owner The pkgAcquire object with which this object is
1174 * associated.
1175 *
1176 * \param URI The URI to download.
1177 *
1178 * \param Hashes The hashsums of the file to download, if they are known;
1179 * otherwise empty list.
1180 *
1181 * \param Size The size of the file to download, if it is known;
1182 * otherwise 0.
1183 *
1184 * \param Desc A description of the file being downloaded.
1185 *
1186 * \param ShortDesc A brief description of the file being
1187 * downloaded.
1188 *
1189 * \param DestDir The directory the file should be downloaded into.
1190 *
1191 * \param DestFilename The filename+path the file is downloaded to.
1192 *
1193 * \param IsIndexFile The file is considered a IndexFile and cache-control
1194 * headers like "cache-control: max-age=0" are send
1195 *
1196 * If DestFilename is empty, download to DestDir/\<basename\> if
1197 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1198 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1199 * is the absolute name to which the file should be downloaded.
1200 */
1201
1202 pkgAcqFile(pkgAcquire *Owner, std::string URI, HashStringList const &Hashes, unsigned long long Size,
1203 std::string Desc, std::string ShortDesc,
1204 const std::string &DestDir="", const std::string &DestFilename="",
1205 bool IsIndexFile=false);
1206 };
1207 /*}}}*/
1208 /** @} */
1209
1210 #endif