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