]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
b6d569737d96532e872836fe6aedf5423f372cbd
[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/indexfile.h>
25 #include <apt-pkg/hashes.h>
26 #include <apt-pkg/weakptr.h>
27 #include <apt-pkg/pkgcache.h>
28 #include <apt-pkg/cacheiterators.h>
29
30 #include <string>
31 #include <vector>
32 #include <map>
33
34 #ifndef APT_8_CLEANER_HEADERS
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 pkgAcqMetaBase;
51
52 class pkgAcquire::Item : public WeakPointable /*{{{*/
53 /** \brief Represents the process by which a pkgAcquire object should
54 * retrieve a file or a collection of files.
55 *
56 * By convention, Item subclasses should insert themselves into the
57 * acquire queue when they are created by calling QueueURI(), and
58 * remove themselves by calling Dequeue() when either Done() or
59 * Failed() is invoked. Item objects are also responsible for
60 * notifying the download progress indicator (accessible via
61 * #Owner->Log) of their status.
62 *
63 * \see pkgAcquire
64 */
65 {
66 public:
67
68 /** \brief The current status of this item. */
69 enum ItemState
70 {
71 /** \brief The item is waiting to be downloaded. */
72 StatIdle,
73
74 /** \brief The item is currently being downloaded. */
75 StatFetching,
76
77 /** \brief The item has been successfully downloaded. */
78 StatDone,
79
80 /** \brief An error was encountered while downloading this
81 * item.
82 */
83 StatError,
84
85 /** \brief The item was downloaded but its authenticity could
86 * not be verified.
87 */
88 StatAuthError,
89
90 /** \brief The item was could not be downloaded because of
91 * a transient network error (e.g. network down)
92 */
93 StatTransientNetworkError,
94 } Status;
95
96 /** \brief Contains a textual description of the error encountered
97 * if #ItemState is #StatError or #StatAuthError.
98 */
99 std::string ErrorText;
100
101 /** \brief The size of the object to fetch. */
102 unsigned long long FileSize;
103
104 /** \brief How much of the object was already fetched. */
105 unsigned long long PartialSize;
106
107 /** \brief If not \b NULL, contains the name of a subprocess that
108 * is operating on this object (for instance, "gzip" or "gpgv").
109 */
110 APT_DEPRECATED const char *Mode;
111
112 /** \brief contains the name of the subprocess that is operating on this object
113 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
114 * as it can manage the lifetime of included string properly. */
115 std::string ActiveSubprocess;
116
117 /** \brief A client-supplied unique identifier.
118 *
119 * This field is initalized to 0; it is meant to be filled in by
120 * clients that wish to use it to uniquely identify items.
121 *
122 * APT progress reporting will store an ID there as shown in "Get:42 …"
123 */
124 unsigned long ID;
125
126 /** \brief If \b true, the entire object has been successfully fetched.
127 *
128 * Subclasses should set this to \b true when appropriate.
129 */
130 bool Complete;
131
132 /** \brief If \b true, the URI of this object is "local".
133 *
134 * The only effect of this field is to exclude the object from the
135 * download progress indicator's overall statistics.
136 */
137 bool Local;
138
139 std::string UsedMirror;
140
141 /** \brief The number of fetch queues into which this item has been
142 * inserted.
143 *
144 * There is one queue for each source from which an item could be
145 * downloaded.
146 *
147 * \sa pkgAcquire
148 */
149 unsigned int QueueCounter;
150
151 /** \brief The number of additional fetch items that are expected
152 * once this item is done.
153 *
154 * Some items like pkgAcqMeta{Index,Sig} will queue additional
155 * items. This variable can be set by the methods if it knows
156 * in advance how many items to expect to get a more accurate
157 * progress.
158 */
159 unsigned int ExpectedAdditionalItems;
160
161 /** \brief The name of the file into which the retrieved object
162 * will be written.
163 */
164 std::string DestFile;
165
166 /** \brief Invoked by the acquire worker when the object couldn't
167 * be fetched.
168 *
169 * This is a branch of the continuation of the fetch process.
170 *
171 * \param Message An RFC822-formatted message from the acquire
172 * method describing what went wrong. Use LookupTag() to parse
173 * it.
174 *
175 * \param Cnf The method via which the worker tried to fetch this object.
176 *
177 * \sa pkgAcqMethod
178 */
179 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
180
181 /** \brief Invoked by the acquire worker when the object was
182 * fetched successfully.
183 *
184 * Note that the object might \e not have been written to
185 * DestFile; check for the presence of an Alt-Filename entry in
186 * Message to find the file to which it was really written.
187 *
188 * Done is often used to switch from one stage of the processing
189 * to the next (e.g. fetching, unpacking, copying). It is one
190 * branch of the continuation of the fetch process.
191 *
192 * \param Message Data from the acquire method. Use LookupTag()
193 * to parse it.
194 * \param Hashes The HashSums of the object that was fetched.
195 * \param Cnf The method via which the object was fetched.
196 *
197 * \sa pkgAcqMethod
198 */
199 virtual void Done(std::string const &Message, HashStringList const &Hashes,
200 pkgAcquire::MethodConfig const * const Cnf);
201
202 /** \brief Invoked when the worker starts to fetch this object.
203 *
204 * \param Message RFC822-formatted data from the worker process.
205 * Use LookupTag() to parse it.
206 *
207 * \param Hashes The expected hashes of the object being fetched.
208 *
209 * \sa pkgAcqMethod
210 */
211 virtual void Start(std::string const &Message, unsigned long long const Size);
212
213 /** \brief Custom headers to be sent to the fetch process.
214 *
215 * \return a string containing RFC822-style headers that are to be
216 * inserted into the 600 URI Acquire message sent to the fetch
217 * subprocess. The headers are inserted after a newline-less
218 * line, so they should (if nonempty) have a leading newline and
219 * no trailing newline.
220 */
221 virtual std::string Custom600Headers() const;
222
223 /** \brief A "descriptive" URI-like string.
224 *
225 * \return a URI that should be used to describe what is being fetched.
226 */
227 virtual std::string DescURI() const = 0;
228 /** \brief Short item description.
229 *
230 * \return a brief description of the object being fetched.
231 */
232 virtual std::string ShortDesc() const;
233
234 /** \brief Invoked by the worker when the download is completely done. */
235 virtual void Finished();
236
237 /** \return HashSums the DestFile is supposed to have in this stage */
238 virtual HashStringList GetExpectedHashes() const = 0;
239 /** \return the 'best' hash for display proposes like --print-uris */
240 std::string HashSum() const;
241
242 /** \return if having no hashes is a hard failure or not
243 *
244 * Idealy this is always \b true for every subclass, but thanks to
245 * historical grow we don't have hashes for all files in all cases
246 * in all steps, so it is slightly more complicated than it should be.
247 */
248 virtual bool HashesRequired() const { return true; }
249
250 /** \return the acquire process with which this item is associated. */
251 pkgAcquire *GetOwner() const;
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 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 *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 protected:
348 IndexTarget const Target;
349 HashStringList GetExpectedHashesFor(std::string const MetaKey) const;
350
351 bool QueueURI(pkgAcquire::ItemDesc &Item);
352
353 public:
354 /** \brief storge name until a transaction is finished */
355 std::string PartialFile;
356
357 /** \brief TransactionManager */
358 pkgAcqMetaBase * const TransactionManager;
359
360 enum TransactionStates {
361 TransactionCommit,
362 TransactionAbort,
363 };
364 virtual bool TransactionState(TransactionStates const state);
365
366 virtual std::string DescURI() const { return Target.URI; }
367 virtual HashStringList GetExpectedHashes() const;
368 virtual std::string GetMetaKey() const;
369 virtual bool HashesRequired() const;
370
371
372 pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const Target);
373 virtual ~pkgAcqTransactionItem();
374
375 friend class pkgAcqMetaBase;
376 };
377 /*}}}*/
378 class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
379 /** \brief the manager of a transaction */
380 {
381 void *d;
382
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 };
481 /*}}}*/
482 /** \brief An item that is responsible for downloading the meta-index {{{
483 * file (i.e., Release) itself and verifying its signature.
484 *
485 * Once the download and verification are complete, the downloads of
486 * the individual index files are queued up using pkgAcqDiffIndex.
487 * If the meta-index file had a valid signature, the expected hashsums
488 * of the index files will be the md5sums listed in the meta-index;
489 * otherwise, the expected hashsums will be "" (causing the
490 * authentication of the index files to be bypassed).
491 */
492 class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
493 {
494 void *d;
495
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
516 friend class pkgAcqMetaSig;
517 };
518 /*}}}*/
519 /** \brief An acquire item that downloads the detached signature {{{
520 * of a meta-index (Release) file, then queues up the release
521 * file itself.
522 *
523 * \todo Why protected members?
524 *
525 * \sa pkgAcqMetaIndex
526 */
527 class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem
528 {
529 void *d;
530
531 pkgAcqMetaIndex * const MetaIndex;
532
533 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
534 std::string MetaIndexFileSignature;
535
536 protected:
537
538 /** \brief Get the full pathname of the final file for the current URI */
539 virtual std::string GetFinalFilename() const;
540
541 public:
542 virtual bool HashesRequired() const { return false; }
543
544 // Specialized action members
545 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
546 virtual void Done(std::string const &Message, HashStringList const &Hashes,
547 pkgAcquire::MethodConfig const * const Cnf);
548
549 /** \brief Create a new pkgAcqMetaSig. */
550 pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager, IndexTarget const Target,
551 pkgAcqMetaIndex * const MetaIndex);
552 virtual ~pkgAcqMetaSig();
553 };
554 /*}}}*/
555 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
556 class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
557 {
558 void *d;
559
560 IndexTarget const ClearsignedTarget;
561 IndexTarget const DetachedDataTarget;
562 IndexTarget const DetachedSigTarget;
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 *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 };
592 /*}}}*/
593 /** \brief An item that is responsible for fetching an index file of {{{
594 * package list diffs and starting the package list's download.
595 *
596 * This item downloads the Index file and parses it, then enqueues
597 * additional downloads of either the individual patches (using
598 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
599 *
600 * \sa pkgAcqIndexDiffs, pkgAcqIndex
601 */
602 class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
603 {
604 void *d;
605
606 protected:
607 /** \brief If \b true, debugging information will be written to std::clog. */
608 bool Debug;
609
610 /** \brief A description of the Packages file (stored in
611 * pkgAcquire::ItemDesc::Description).
612 */
613 std::string Description;
614
615 /** \brief Get the full pathname of the final file for the current URI */
616 virtual std::string GetFinalFilename() const;
617
618 virtual bool QueueURI(pkgAcquire::ItemDesc &Item);
619
620 virtual bool TransactionState(TransactionStates const state);
621 public:
622 // Specialized action members
623 virtual void Failed(std::string const &Message, pkgAcquire::MethodConfig const * const Cnf);
624 virtual void Done(std::string const &Message, HashStringList const &Hashes,
625 pkgAcquire::MethodConfig const * const Cnf);
626 virtual std::string DescURI() const {return Target.URI + "Index";};
627 virtual std::string Custom600Headers() const;
628 virtual std::string GetMetaKey() const;
629
630 /** \brief Parse the Index file for a set of Packages diffs.
631 *
632 * Parses the Index file and creates additional download items as
633 * necessary.
634 *
635 * \param IndexDiffFile The name of the Index file.
636 *
637 * \return \b true if the Index file was successfully parsed, \b
638 * false otherwise.
639 */
640 bool ParseDiffIndex(std::string const &IndexDiffFile);
641
642 /** \brief Create a new pkgAcqDiffIndex.
643 *
644 * \param Owner The Acquire object that owns this item.
645 *
646 * \param URI The URI of the list file to download.
647 *
648 * \param URIDesc A long description of the list file to download.
649 *
650 * \param ShortDesc A short description of the list file to download.
651 */
652 pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
653 IndexTarget const Target);
654 private:
655 APT_HIDDEN void QueueOnIMSHit() const;
656 };
657 /*}}}*/
658 struct APT_HIDDEN DiffInfo { /*{{{*/
659 /** The filename of the diff. */
660 std::string file;
661
662 /** The hashes of the file after the diff is applied */
663 HashStringList result_hashes;
664
665 /** The hashes of the diff */
666 HashStringList patch_hashes;
667
668 /** The hashes of the compressed diff */
669 HashStringList download_hashes;
670 };
671 /*}}}*/
672 /** \brief An item that is responsible for fetching client-merge patches {{{
673 * that need to be applied to a given package index file.
674 *
675 * Instead of downloading and applying each patch one by one like its
676 * sister #pkgAcqIndexDiffs this class will download all patches at once
677 * and call rred with all the patches downloaded once. Rred will then
678 * merge and apply them in one go, which should be a lot faster – but is
679 * incompatible with server-based merges of patches like reprepro can do.
680 *
681 * \sa pkgAcqDiffIndex, pkgAcqIndex
682 */
683 class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
684 {
685 void *d;
686
687 protected:
688
689 /** \brief If \b true, debugging output will be written to
690 * std::clog.
691 */
692 bool Debug;
693
694 /** \brief description of the file being downloaded. */
695 std::string Description;
696
697 /** \brief information about the current patch */
698 struct DiffInfo const patch;
699
700 /** \brief list of all download items for the patches */
701 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
702
703 /** The current status of this patch. */
704 enum DiffState
705 {
706 /** \brief The diff is currently being fetched. */
707 StateFetchDiff,
708
709 /** \brief The diff is currently being applied. */
710 StateApplyDiff,
711
712 /** \brief the work with this diff is done */
713 StateDoneDiff,
714
715 /** \brief something bad happened and fallback was triggered */
716 StateErrorDiff
717 } State;
718
719 public:
720 /** \brief Called when the patch file failed to be downloaded.
721 *
722 * This method will fall back to downloading the whole index file
723 * outright; its arguments are ignored.
724 */
725 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
726 virtual void Done(std::string const &Message, HashStringList const &Hashes,
727 pkgAcquire::MethodConfig const * const Cnf);
728 virtual std::string Custom600Headers() const;
729 virtual std::string DescURI() const {return Target.URI + "Index";};
730 virtual HashStringList GetExpectedHashes() const;
731 virtual bool HashesRequired() const;
732
733 /** \brief Create an index merge-diff item.
734 *
735 * \param Owner The pkgAcquire object that owns this item.
736 *
737 * \param URI The URI of the package index file being
738 * reconstructed.
739 *
740 * \param URIDesc A long description of this item.
741 *
742 * \param ShortDesc A brief description of this item.
743 *
744 * \param patch contains infos about the patch this item is supposed
745 * to download which were read from the index
746 *
747 * \param allPatches contains all related items so that each item can
748 * check if it was the last one to complete the download step
749 */
750 pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
751 IndexTarget const Target, DiffInfo const &patch,
752 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
753 };
754 /*}}}*/
755 /** \brief An item that is responsible for fetching server-merge patches {{{
756 * that need to be applied to a given package index file.
757 *
758 * After downloading and applying a single patch, this item will
759 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
760 * patches. If no patch can be found that applies to an intermediate
761 * file or if one of the patches cannot be downloaded, falls back to
762 * downloading the entire package index file using pkgAcqIndex.
763 *
764 * \sa pkgAcqDiffIndex, pkgAcqIndex
765 */
766 class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
767 {
768 void *d;
769
770 private:
771
772 /** \brief Queue up the next diff download.
773 *
774 * Search for the next available diff that applies to the file
775 * that currently exists on disk, and enqueue it by calling
776 * QueueURI().
777 *
778 * \return \b true if an applicable diff was found, \b false
779 * otherwise.
780 */
781 APT_HIDDEN bool QueueNextDiff();
782
783 /** \brief Handle tasks that must be performed after the item
784 * finishes downloading.
785 *
786 * Dequeues the item and checks the resulting file's hashsums
787 * against ExpectedHashes after the last patch was applied.
788 * There is no need to check the md5/sha1 after a "normal"
789 * patch because QueueNextDiff() will check the sha1 later.
790 *
791 * \param allDone If \b true, the file was entirely reconstructed,
792 * and its md5sum is verified.
793 */
794 APT_HIDDEN void Finish(bool const allDone=false);
795
796 protected:
797
798 /** \brief If \b true, debugging output will be written to
799 * std::clog.
800 */
801 bool Debug;
802
803 /** A description of the file being downloaded. */
804 std::string Description;
805
806 /** The patches that remain to be downloaded, including the patch
807 * being downloaded right now. This list should be ordered so
808 * that each diff appears before any diff that depends on it.
809 *
810 * \todo These are indexed by sha1sum; why not use some sort of
811 * dictionary instead of relying on ordering and stripping them
812 * off the front?
813 */
814 std::vector<DiffInfo> available_patches;
815
816 /** The current status of this patch. */
817 enum DiffState
818 {
819 /** \brief The diff is in an unknown state. */
820 StateFetchUnkown,
821
822 /** \brief The diff is currently being fetched. */
823 StateFetchDiff,
824
825 /** \brief The diff is currently being applied. */
826 StateApplyDiff
827 } State;
828
829 public:
830
831 /** \brief Called when the patch file failed to be downloaded.
832 *
833 * This method will fall back to downloading the whole index file
834 * outright; its arguments are ignored.
835 */
836 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
837
838 virtual void Done(std::string const &Message, HashStringList const &Hashes,
839 pkgAcquire::MethodConfig const * const Cnf);
840 virtual std::string Custom600Headers() const;
841 virtual std::string DescURI() const {return Target.URI + "IndexDiffs";};
842 virtual HashStringList GetExpectedHashes() const;
843 virtual bool HashesRequired() const;
844
845 /** \brief Create an index diff item.
846 *
847 * After filling in its basic fields, this invokes Finish(true) if
848 * \a diffs is empty, or QueueNextDiff() otherwise.
849 *
850 * \param Owner The pkgAcquire object that owns this item.
851 *
852 * \param URI The URI of the package index file being
853 * reconstructed.
854 *
855 * \param URIDesc A long description of this item.
856 *
857 * \param ShortDesc A brief description of this item.
858 *
859 * \param diffs The remaining diffs from the index of diffs. They
860 * should be ordered so that each diff appears before any diff
861 * that depends on it.
862 */
863 pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
864 IndexTarget const Target,
865 std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>());
866 };
867 /*}}}*/
868 /** \brief An acquire item that is responsible for fetching an index {{{
869 * file (e.g., Packages or Sources).
870 *
871 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
872 *
873 * \todo Why does pkgAcqIndex have protected members?
874 */
875 class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
876 {
877 void *d;
878
879 protected:
880
881 /** \brief The stages the method goes through
882 *
883 * The method first downloads the indexfile, then its decompressed (or
884 * copied) and verified
885 */
886 enum AllStages {
887 STAGE_DOWNLOAD,
888 STAGE_DECOMPRESS_AND_VERIFY,
889 };
890 AllStages Stage;
891
892 /** \brief Handle what needs to be done when the download is done */
893 void StageDownloadDone(std::string const &Message,
894 HashStringList const &Hashes,
895 pkgAcquire::MethodConfig const * const Cfg);
896
897 /** \brief Handle what needs to be done when the decompression/copy is
898 * done
899 */
900 void StageDecompressDone(std::string const &Message,
901 HashStringList const &Hashes,
902 pkgAcquire::MethodConfig const * const Cfg);
903
904 /** \brief If \b set, this partially downloaded file will be
905 * removed when the download completes.
906 */
907 std::string EraseFileName;
908
909 /** \brief The compression-related file extensions that are being
910 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
911 */
912 std::string CompressionExtensions;
913
914 /** \brief The actual compression extension currently used */
915 std::string CurrentCompressionExtension;
916
917 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
918 void InitByHashIfNeeded();
919
920 /** \brief Auto select the right compression to use */
921 void AutoSelectCompression();
922
923 /** \brief Schedule file for verification after a IMS hit */
924 void ReverifyAfterIMS();
925
926 /** \brief Get the full pathname of the final file for the current URI */
927 virtual std::string GetFinalFilename() const;
928
929 virtual bool TransactionState(TransactionStates const state);
930
931 public:
932 // Specialized action members
933 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
934 virtual void Done(std::string const &Message, HashStringList const &Hashes,
935 pkgAcquire::MethodConfig const * const Cnf);
936 virtual std::string Custom600Headers() const;
937 virtual std::string DescURI() const {return Desc.URI;};
938 virtual std::string GetMetaKey() const;
939
940 pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaBase * const TransactionManager,
941 IndexTarget const Target);
942
943 void Init(std::string const &URI, std::string const &URIDesc,
944 std::string const &ShortDesc);
945 };
946 /*}}}*/
947 /** \brief An item that is responsible for fetching a package file. {{{
948 *
949 * If the package file already exists in the cache, nothing will be
950 * done.
951 */
952 class pkgAcqArchive : public pkgAcquire::Item
953 {
954 void *d;
955
956 bool LocalSource;
957 HashStringList ExpectedHashes;
958
959 protected:
960 /** \brief The package version being fetched. */
961 pkgCache::VerIterator Version;
962
963 /** \brief The list of sources from which to pick archives to
964 * download this package from.
965 */
966 pkgSourceList *Sources;
967
968 /** \brief A package records object, used to look up the file
969 * corresponding to each version of the package.
970 */
971 pkgRecords *Recs;
972
973 /** \brief A location in which the actual filename of the package
974 * should be stored.
975 */
976 std::string &StoreFilename;
977
978 /** \brief The next file for this version to try to download. */
979 pkgCache::VerFileIterator Vf;
980
981 /** \brief How many (more) times to try to find a new source from
982 * which to download this package version if it fails.
983 *
984 * Set from Acquire::Retries.
985 */
986 unsigned int Retries;
987
988 /** \brief \b true if this version file is being downloaded from a
989 * trusted source.
990 */
991 bool Trusted;
992
993 /** \brief Queue up the next available file for this version. */
994 bool QueueNext();
995
996 /** \brief Get the full pathname of the final file for the current URI */
997 virtual std::string GetFinalFilename() const;
998
999 public:
1000
1001 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
1002 virtual void Done(std::string const &Message, HashStringList const &Hashes,
1003 pkgAcquire::MethodConfig const * const Cnf);
1004 virtual std::string DescURI() const;
1005 virtual std::string ShortDesc() const;
1006 virtual void Finished();
1007 virtual bool IsTrusted() const;
1008 virtual HashStringList GetExpectedHashes() const;
1009 virtual bool HashesRequired() const;
1010
1011 /** \brief Create a new pkgAcqArchive.
1012 *
1013 * \param Owner The pkgAcquire object with which this item is
1014 * associated.
1015 *
1016 * \param Sources The sources from which to download version
1017 * files.
1018 *
1019 * \param Recs A package records object, used to look up the file
1020 * corresponding to each version of the package.
1021 *
1022 * \param Version The package version to download.
1023 *
1024 * \param[out] StoreFilename A location in which the actual filename of
1025 * the package should be stored. It will be set to a guessed
1026 * basename in the constructor, and filled in with a fully
1027 * qualified filename once the download finishes.
1028 */
1029 pkgAcqArchive(pkgAcquire * const Owner,pkgSourceList * const Sources,
1030 pkgRecords * const Recs,pkgCache::VerIterator const &Version,
1031 std::string &StoreFilename);
1032 };
1033 /*}}}*/
1034 /** \brief Retrieve an arbitrary file to the current directory. {{{
1035 *
1036 * The file is retrieved even if it is accessed via a URL type that
1037 * normally is a NOP, such as "file". If the download fails, the
1038 * partial file is renamed to get a ".FAILED" extension.
1039 */
1040 class pkgAcqFile : public pkgAcquire::Item
1041 {
1042 void *d;
1043
1044 /** \brief How many times to retry the download, set from
1045 * Acquire::Retries.
1046 */
1047 unsigned int Retries;
1048
1049 /** \brief Should this file be considered a index file */
1050 bool IsIndexFile;
1051
1052 HashStringList const ExpectedHashes;
1053 public:
1054 virtual HashStringList GetExpectedHashes() const;
1055 virtual bool HashesRequired() const;
1056
1057 // Specialized action members
1058 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
1059 virtual void Done(std::string const &Message, HashStringList const &CalcHashes,
1060 pkgAcquire::MethodConfig const * const Cnf);
1061 virtual std::string DescURI() const {return Desc.URI;};
1062 virtual std::string Custom600Headers() const;
1063
1064 /** \brief Create a new pkgAcqFile object.
1065 *
1066 * \param Owner The pkgAcquire object with which this object is
1067 * associated.
1068 *
1069 * \param URI The URI to download.
1070 *
1071 * \param Hashes The hashsums of the file to download, if they are known;
1072 * otherwise empty list.
1073 *
1074 * \param Size The size of the file to download, if it is known;
1075 * otherwise 0.
1076 *
1077 * \param Desc A description of the file being downloaded.
1078 *
1079 * \param ShortDesc A brief description of the file being
1080 * downloaded.
1081 *
1082 * \param DestDir The directory the file should be downloaded into.
1083 *
1084 * \param DestFilename The filename+path the file is downloaded to.
1085 *
1086 * \param IsIndexFile The file is considered a IndexFile and cache-control
1087 * headers like "cache-control: max-age=0" are send
1088 *
1089 * If DestFilename is empty, download to DestDir/\<basename\> if
1090 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1091 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1092 * is the absolute name to which the file should be downloaded.
1093 */
1094
1095 pkgAcqFile(pkgAcquire * const Owner, std::string const &URI, HashStringList const &Hashes, unsigned long long const Size,
1096 std::string const &Desc, std::string const &ShortDesc,
1097 std::string const &DestDir="", std::string const &DestFilename="",
1098 bool const IsIndexFile=false);
1099 };
1100 /*}}}*/
1101 /** @} */
1102
1103 #endif