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