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