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