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