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