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