]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
* merged the no-pragma branch
[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 Md5
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/vendor.h>
26 #include <apt-pkg/sourcelist.h>
27 #include <apt-pkg/pkgrecords.h>
28 #include <apt-pkg/indexrecords.h>
29
30
31 /** \addtogroup acquire
32 * @{
33 *
34 * \file acquire-item.h
35 */
36
37 /** \brief Represents the process by which a pkgAcquire object should
38 * retrieve a file or a collection of files.
39 *
40 * By convention, Item subclasses should insert themselves into the
41 * acquire queue when they are created by calling QueueURI(), and
42 * remove themselves by calling Dequeue() when either Done() or
43 * Failed() is invoked. Item objects are also responsible for
44 * notifying the download progress indicator (accessible via
45 * #Owner->Log) of their status.
46 *
47 * \see pkgAcquire
48 */
49 class pkgAcquire::Item
50 {
51 protected:
52
53 /** \brief The acquire object with which this item is associated. */
54 pkgAcquire *Owner;
55
56 /** \brief Insert this item into its owner's queue.
57 *
58 * \param ItemDesc Metadata about this item (its URI and
59 * description).
60 */
61 inline void QueueURI(ItemDesc &Item)
62 {Owner->Enqueue(Item);};
63
64 /** \brief Remove this item from its owner's queue. */
65 inline void Dequeue() {Owner->Dequeue(this);};
66
67 /** \brief Rename a file without modifying its timestamp.
68 *
69 * Many item methods call this as their final action.
70 *
71 * \param From The file to be renamed.
72 *
73 * \param To The new name of #From. If #To exists it will be
74 * overwritten.
75 */
76 void Rename(string From,string To);
77
78 public:
79
80 /** \brief The current status of this item. */
81 enum ItemState
82 {
83 /** \brief The item is waiting to be downloaded. */
84 StatIdle,
85
86 /** \brief The item is currently being downloaded. */
87 StatFetching,
88
89 /** \brief The item has been successfully downloaded. */
90 StatDone,
91
92 /** \brief An error was encountered while downloading this
93 * item.
94 */
95 StatError,
96
97 /** \brief The item was downloaded but its authenticity could
98 * not be verified.
99 */
100 StatAuthError
101 } Status;
102
103 /** \brief Contains a textual description of the error encountered
104 * if #Status is #StatError or #StatAuthError.
105 */
106 string ErrorText;
107
108 /** \brief The size of the object to fetch. */
109 unsigned long FileSize;
110
111 /** \brief How much of the object was already fetched. */
112 unsigned long PartialSize;
113
114 /** \brief If not \b NULL, contains the name of a subprocess that
115 * is operating on this object (for instance, "gzip" or "gpgv").
116 */
117 const char *Mode;
118
119 /** \brief A client-supplied unique identifier.
120 *
121 * This field is initalized to 0; it is meant to be filled in by
122 * clients that wish to use it to uniquely identify items.
123 *
124 * \todo it's unused in apt itself
125 */
126 unsigned long ID;
127
128 /** \brief If \b true, the entire object has been successfully fetched.
129 *
130 * Subclasses should set this to \b true when appropriate.
131 */
132 bool Complete;
133
134 /** \brief If \b true, the URI of this object is "local".
135 *
136 * The only effect of this field is to exclude the object from the
137 * download progress indicator's overall statistics.
138 */
139 bool Local;
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 name of the file into which the retrieved object
152 * will be written.
153 */
154 string DestFile;
155
156 /** \brief Invoked by the acquire worker when the object couldn't
157 * be fetched.
158 *
159 * This is a branch of the continuation of the fetch process.
160 *
161 * \param Message An RFC822-formatted message from the acquire
162 * method describing what went wrong. Use LookupTag() to parse
163 * it.
164 *
165 * \param Cnf The method via which the worker tried to fetch this object.
166 *
167 * \sa pkgAcqMethod
168 */
169 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
170
171 /** \brief Invoked by the acquire worker when the object was
172 * fetched successfully.
173 *
174 * Note that the object might \e not have been written to
175 * DestFile; check for the presence of an Alt-Filename entry in
176 * Message to find the file to which it was really written.
177 *
178 * Done is often used to switch from one stage of the processing
179 * to the next (e.g. fetching, unpacking, copying). It is one
180 * branch of the continuation of the fetch process.
181 *
182 * \param Message Data from the acquire method. Use LookupTag()
183 * to parse it.
184 * \param Size The size of the object that was fetched.
185 * \param Md5Hash The MD5Sum of the object that was fetched.
186 * \param Cnf The method via which the object was fetched.
187 *
188 * \sa pkgAcqMethod
189 */
190 virtual void Done(string Message,unsigned long Size,string Md5Hash,
191 pkgAcquire::MethodConfig *Cnf);
192
193 /** \brief Invoked when the worker starts to fetch this object.
194 *
195 * \param Message RFC822-formatted data from the worker process.
196 * Use LookupTag() to parse it.
197 *
198 * \param Size The size of the object being fetched.
199 *
200 * \sa pkgAcqMethod
201 */
202 virtual void Start(string Message,unsigned long Size);
203
204 /** \brief Custom headers to be sent to the fetch process.
205 *
206 * \return a string containing RFC822-style headers that are to be
207 * inserted into the 600 URI Acquire message sent to the fetch
208 * subprocess. The headers are inserted after a newline-less
209 * line, so they should (if nonempty) have a leading newline and
210 * no trailing newline.
211 */
212 virtual string Custom600Headers() {return string();};
213
214 /** \brief A "descriptive" URI-like string.
215 *
216 * \return a URI that should be used to describe what is being fetched.
217 */
218 virtual string DescURI() = 0;
219 /** \brief Short item description.
220 *
221 * \return a brief description of the object being fetched.
222 */
223 virtual string ShortDesc() {return DescURI();}
224
225 /** \brief Invoked by the worker when the download is completely done. */
226 virtual void Finished() {};
227
228 /** \brief MD5Sum.
229 *
230 * \return the MD5Sum of this object, if applicable; otherwise, an
231 * empty string.
232 */
233 virtual string MD5Sum() {return string();};
234
235 /** \return the acquire process with which this item is associated. */
236 pkgAcquire *GetOwner() {return Owner;};
237
238 /** \return \b true if this object is being fetched from a trusted source. */
239 virtual bool IsTrusted() {return false;};
240
241 /** \brief Initialize an item.
242 *
243 * Adds the item to the list of items known to the acquire
244 * process, but does not place it into any fetch queues (you must
245 * manually invoke QueueURI() to do so).
246 *
247 * Initializes all fields of the item other than Owner to 0,
248 * false, or the empty string.
249 *
250 * \param Owner The new owner of this item.
251 */
252 Item(pkgAcquire *Owner);
253
254 /** \brief Remove this item from its owner's queue by invoking
255 * pkgAcquire::Remove.
256 */
257 virtual ~Item();
258 };
259
260 /** \brief Information about an index patch (aka diff). */
261 struct DiffInfo {
262 /** The filename of the diff. */
263 string file;
264
265 /** The sha1 hash of the diff. */
266 string sha1;
267
268 /** The size of the diff. */
269 unsigned long size;
270 };
271
272 /** \brief An item that is responsible for fetching an index file of
273 * package list diffs and starting the package list's download.
274 *
275 * This item downloads the Index file and parses it, then enqueues
276 * additional downloads of either the individual patches (using
277 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
278 *
279 * \sa pkgAcqIndexDiffs, pkgAcqIndex
280 */
281 class pkgAcqDiffIndex : public pkgAcquire::Item
282 {
283 protected:
284 /** \brief If \b true, debugging information will be written to std::clog. */
285 bool Debug;
286
287 /** \brief The item that is currently being downloaded. */
288 pkgAcquire::ItemDesc Desc;
289
290 /** \brief The URI of the index file to recreate at our end (either
291 * by downloading it or by applying partial patches).
292 */
293 string RealURI;
294
295 /** \brief The MD5Sum that the real index file should have after
296 * all patches have been applied.
297 */
298 string ExpectedMD5;
299
300 /** \brief The index file which will be patched to generate the new
301 * file.
302 */
303 string CurrentPackagesFile;
304
305 /** \brief A description of the Packages file (stored in
306 * pkgAcquire::ItemDesc::Description).
307 */
308 string Description;
309
310 public:
311 // Specialized action members
312 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
313 virtual void Done(string Message,unsigned long Size,string Md5Hash,
314 pkgAcquire::MethodConfig *Cnf);
315 virtual string DescURI() {return RealURI + "Index";};
316 virtual string Custom600Headers();
317
318 /** \brief Parse the Index file for a set of Packages diffs.
319 *
320 * Parses the Index file and creates additional download items as
321 * necessary.
322 *
323 * \param IndexDiffFile The name of the Index file.
324 *
325 * \return \b true if the Index file was successfully parsed, \b
326 * false otherwise.
327 */
328 bool ParseDiffIndex(string IndexDiffFile);
329
330
331 /** \brief Create a new pkgAcqDiffIndex.
332 *
333 * \param Owner The Acquire object that owns this item.
334 *
335 * \param URI The URI of the list file to download.
336 *
337 * \param URIDesc A long description of the list file to download.
338 *
339 * \param ShortDesc A short description of the list file to download.
340 *
341 * \param ExpectedMD5 The list file's MD5 signature.
342 */
343 pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc,
344 string ShortDesc, string ExpectedMD5);
345 };
346
347 /** \brief An item that is responsible for fetching all the patches
348 * that need to be applied to a given package index file.
349 *
350 * After downloading and applying a single patch, this item will
351 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
352 * patches. If no patch can be found that applies to an intermediate
353 * file or if one of the patches cannot be downloaded, falls back to
354 * downloading the entire package index file using pkgAcqIndex.
355 *
356 * \sa pkgAcqDiffIndex, pkgAcqIndex
357 */
358 class pkgAcqIndexDiffs : public pkgAcquire::Item
359 {
360 private:
361
362 /** \brief Queue up the next diff download.
363 *
364 * Search for the next available diff that applies to the file
365 * that currently exists on disk, and enqueue it by calling
366 * QueueURI().
367 *
368 * \return \b true if an applicable diff was found, \b false
369 * otherwise.
370 */
371 bool QueueNextDiff();
372
373 /** \brief Handle tasks that must be performed after the item
374 * finishes downloading.
375 *
376 * Dequeues the item and checks the resulting file's md5sum
377 * against ExpectedMD5 after the last patch was applied.
378 * There is no need to check the md5/sha1 after a "normal"
379 * patch because QueueNextDiff() will check the sha1 later.
380 *
381 * \param allDone If \b true, the file was entirely reconstructed,
382 * and its md5sum is verified.
383 */
384 void Finish(bool allDone=false);
385
386 protected:
387
388 /** \brief If \b true, debugging output will be written to
389 * std::clog.
390 */
391 bool Debug;
392
393 /** \brief A description of the item that is currently being
394 * downloaded.
395 */
396 pkgAcquire::ItemDesc Desc;
397
398 /** \brief The URI of the package index file that is being
399 * reconstructed.
400 */
401 string RealURI;
402
403 /** \brief The MD5Sum of the package index file that is being
404 * reconstructed.
405 */
406 string ExpectedMD5;
407
408 /** A description of the file being downloaded. */
409 string Description;
410
411 /** The patches that remain to be downloaded, including the patch
412 * being downloaded right now. This list should be ordered so
413 * that each diff appears before any diff that depends on it.
414 *
415 * \todo These are indexed by sha1sum; why not use some sort of
416 * dictionary instead of relying on ordering and stripping them
417 * off the front?
418 */
419 vector<DiffInfo> available_patches;
420 /** The current status of this patch. */
421 enum DiffState
422 {
423 /** \brief The diff is in an unknown state. */
424 StateFetchUnkown,
425
426 /** \brief The diff is currently being fetched. */
427 StateFetchDiff,
428
429 /** \brief The diff is currently being uncompressed. */
430 StateUnzipDiff,
431
432 /** \brief The diff is currently being applied. */
433 StateApplyDiff
434 } State;
435
436 public:
437
438 /** \brief Called when the patch file failed to be downloaded.
439 *
440 * This method will fall back to downloading the whole index file
441 * outright; its arguments are ignored.
442 */
443 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
444
445 virtual void Done(string Message,unsigned long Size,string Md5Hash,
446 pkgAcquire::MethodConfig *Cnf);
447 virtual string DescURI() {return RealURI + "Index";};
448
449 /** \brief Create an index diff item.
450 *
451 * After filling in its basic fields, this invokes Finish(true) if
452 * #diffs is empty, or QueueNextDiff() otherwise.
453 *
454 * \param Owner The pkgAcquire object that owns this item.
455 *
456 * \param URI The URI of the package index file being
457 * reconstructed.
458 *
459 * \param URIDesc A long description of this item.
460 *
461 * \param ShortDesc A brief description of this item.
462 *
463 * \param ExpectedMD5 The expected md5sum of the completely
464 * reconstructed package index file; the index file will be tested
465 * against this value when it is entirely reconstructed.
466 *
467 * \param diffs The remaining diffs from the index of diffs. They
468 * should be ordered so that each diff appears before any diff
469 * that depends on it.
470 */
471 pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc,
472 string ShortDesc, string ExpectedMD5,
473 vector<DiffInfo> diffs=vector<DiffInfo>());
474 };
475
476 /** \brief An acquire item that is responsible for fetching an index
477 * file (e.g., Packages or Sources).
478 *
479 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
480 *
481 * \todo Why does pkgAcqIndex have protected members?
482 */
483 class pkgAcqIndex : public pkgAcquire::Item
484 {
485 protected:
486
487 /** \brief If \b true, the index file has been decompressed. */
488 bool Decompression;
489
490 /** \brief If \b true, the partially downloaded file will be
491 * removed when the download completes.
492 */
493 bool Erase;
494
495 /** \brief The download request that is currently being
496 * processed.
497 */
498 pkgAcquire::ItemDesc Desc;
499
500 /** \brief The object that is actually being fetched (minus any
501 * compression-related extensions).
502 */
503 string RealURI;
504
505 /** \brief The expected md5sum of the decompressed index file. */
506 string ExpectedMD5;
507
508 /** \brief The compression-related file extension that is being
509 * added to the downloaded file (e.g., ".gz" or ".bz2").
510 */
511 string CompressionExtension;
512
513 public:
514
515 // Specialized action members
516 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
517 virtual void Done(string Message,unsigned long Size,string Md5Hash,
518 pkgAcquire::MethodConfig *Cnf);
519 virtual string Custom600Headers();
520 virtual string DescURI() {return RealURI + CompressionExtension;};
521
522 /** \brief Create a pkgAcqIndex.
523 *
524 * \param Owner The pkgAcquire object with which this item is
525 * associated.
526 *
527 * \param URI The URI of the index file that is to be downloaded.
528 *
529 * \param URIDesc A "URI-style" description of this index file.
530 *
531 * \param ShortDesc A brief description of this index file.
532 *
533 * \param ExpectedMD5 The expected md5sum of this index file.
534 *
535 * \param compressExt The compression-related extension with which
536 * this index file should be downloaded, or "" to autodetect
537 * (".bz2" is used if bzip2 is installed, ".gz" otherwise).
538 */
539 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
540 string ShortDesc, string ExpectedMD5, string compressExt="");
541 };
542
543 /** \brief An acquire item that is responsible for fetching a
544 * translated index file.
545 *
546 * The only difference from pkgAcqIndex is that transient failures
547 * are suppressed: no error occurs if the translated index file is
548 * missing.
549 */
550 class pkgAcqIndexTrans : public pkgAcqIndex
551 {
552 public:
553
554 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
555
556 /** \brief Create a pkgAcqIndexTrans.
557 *
558 * \param Owner The pkgAcquire object with which this item is
559 * associated.
560 *
561 * \param URI The URI of the index file that is to be downloaded.
562 *
563 * \param URIDesc A "URI-style" description of this index file.
564 *
565 * \param ShortDesc A brief description of this index file.
566 *
567 * \param ExpectedMD5 The expected md5sum of this index file.
568 *
569 * \param compressExt The compression-related extension with which
570 * this index file should be downloaded, or "" to autodetect
571 * (".bz2" is used if bzip2 is installed, ".gz" otherwise).
572 */
573 pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
574 string ShortDesc);
575 };
576
577 /** \brief Information about an index file. */
578 struct IndexTarget
579 {
580 /** \brief A URI from which the index file can be downloaded. */
581 string URI;
582
583 /** \brief A description of the index file. */
584 string Description;
585
586 /** \brief A shorter description of the index file. */
587 string ShortDesc;
588
589 /** \brief The key by which this index file should be
590 * looked up within the meta signature file.
591 */
592 string MetaKey;
593 };
594
595 /** \brief An acquire item that downloads the detached signature
596 * of a meta-index (Release) file, then queues up the release
597 * file itself.
598 *
599 * \todo Why protected members?
600 *
601 * \sa pkgAcqMetaIndex
602 */
603 class pkgAcqMetaSig : public pkgAcquire::Item
604 {
605 protected:
606 /** \brief The fetch request that is currently being processed. */
607 pkgAcquire::ItemDesc Desc;
608
609 /** \brief The URI of the signature file. Unlike Desc.URI, this is
610 * never modified; it is used to determine the file that is being
611 * downloaded.
612 */
613 string RealURI;
614
615 /** \brief The URI of the meta-index file to be fetched after the signature. */
616 string MetaIndexURI;
617
618 /** \brief A "URI-style" description of the meta-index file to be
619 * fetched after the signature.
620 */
621 string MetaIndexURIDesc;
622
623 /** \brief A brief description of the meta-index file to be fetched
624 * after the signature.
625 */
626 string MetaIndexShortDesc;
627
628 /** \brief A package-system-specific parser for the meta-index file. */
629 indexRecords* MetaIndexParser;
630
631 /** \brief The index files which should be looked up in the meta-index
632 * and then downloaded.
633 *
634 * \todo Why a list of pointers instead of a list of structs?
635 */
636 const vector<struct IndexTarget*>* IndexTargets;
637
638 public:
639
640 // Specialized action members
641 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
642 virtual void Done(string Message,unsigned long Size,string Md5Hash,
643 pkgAcquire::MethodConfig *Cnf);
644 virtual string Custom600Headers();
645 virtual string DescURI() {return RealURI; };
646
647 /** \brief Create a new pkgAcqMetaSig. */
648 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
649 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
650 const vector<struct IndexTarget*>* IndexTargets,
651 indexRecords* MetaIndexParser);
652 };
653
654 /** \brief An item that is responsible for downloading the meta-index
655 * file (i.e., Release) itself and verifying its signature.
656 *
657 * Once the download and verification are complete, the downloads of
658 * the individual index files are queued up using pkgAcqDiffIndex.
659 * If the meta-index file had a valid signature, the expected md5sums
660 * of the index files will be the md5sums listed in the meta-index;
661 * otherwise, the expected md5sums will be "" (causing the
662 * authentication of the index files to be bypassed).
663 */
664 class pkgAcqMetaIndex : public pkgAcquire::Item
665 {
666 protected:
667 /** \brief The fetch command that is currently being processed. */
668 pkgAcquire::ItemDesc Desc;
669
670 /** \brief The URI that is actually being downloaded; never
671 * modified by pkgAcqMetaIndex.
672 */
673 string RealURI;
674
675 /** \brief The file in which the signature for this index was stored.
676 *
677 * If empty, the signature and the md5sums of the individual
678 * indices will not be checked.
679 */
680 string SigFile;
681
682 /** \brief The index files to download. */
683 const vector<struct IndexTarget*>* IndexTargets;
684
685 /** \brief The parser for the meta-index file. */
686 indexRecords* MetaIndexParser;
687
688 /** \brief If \b true, the index's signature is currently being verified.
689 */
690 bool AuthPass;
691 // required to deal gracefully with problems caused by incorrect ims hits
692 bool IMSHit;
693
694 /** \brief Check that the release file is a release file for the
695 * correct distribution.
696 *
697 * \return \b true if no fatal errors were encountered.
698 */
699 bool VerifyVendor(string Message);
700
701 /** \brief Called when a file is finished being retrieved.
702 *
703 * If the file was not downloaded to DestFile, a copy process is
704 * set up to copy it to DestFile; otherwise, Complete is set to \b
705 * true and the file is moved to its final location.
706 *
707 * \param Message The message block received from the fetch
708 * subprocess.
709 */
710 void RetrievalDone(string Message);
711
712 /** \brief Called when authentication succeeded.
713 *
714 * Sanity-checks the authenticated file, queues up the individual
715 * index files for download, and saves the signature in the lists
716 * directory next to the authenticated list file.
717 *
718 * \param Message The message block received from the fetch
719 * subprocess.
720 */
721 void AuthDone(string Message);
722
723 /** \brief Starts downloading the individual index files.
724 *
725 * \param verify If \b true, only indices whose expected md5sum
726 * can be determined from the meta-index will be downloaded, and
727 * the md5sums of indices will be checked (reporting
728 * #StatAuthError if there is a mismatch). If verify is \b false,
729 * no md5sum checking will be performed.
730 */
731 void QueueIndexes(bool verify);
732
733 public:
734
735 // Specialized action members
736 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
737 virtual void Done(string Message,unsigned long Size,string Md5Hash,
738 pkgAcquire::MethodConfig *Cnf);
739 virtual string Custom600Headers();
740 virtual string DescURI() {return RealURI; };
741
742 /** \brief Create a new pkgAcqMetaIndex. */
743 pkgAcqMetaIndex(pkgAcquire *Owner,
744 string URI,string URIDesc, string ShortDesc,
745 string SigFile,
746 const vector<struct IndexTarget*>* IndexTargets,
747 indexRecords* MetaIndexParser);
748 };
749
750 /** \brief An item that is responsible for fetching a package file.
751 *
752 * If the package file already exists in the cache, nothing will be
753 * done.
754 */
755 class pkgAcqArchive : public pkgAcquire::Item
756 {
757 protected:
758 /** \brief The package version being fetched. */
759 pkgCache::VerIterator Version;
760
761 /** \brief The fetch command that is currently being processed. */
762 pkgAcquire::ItemDesc Desc;
763
764 /** \brief The list of sources from which to pick archives to
765 * download this package from.
766 */
767 pkgSourceList *Sources;
768
769 /** \brief A package records object, used to look up the file
770 * corresponding to each version of the package.
771 */
772 pkgRecords *Recs;
773
774 /** \brief The md5sum of this package. */
775 string MD5;
776
777 /** \brief A location in which the actual filename of the package
778 * should be stored.
779 */
780 string &StoreFilename;
781
782 /** \brief The next file for this version to try to download. */
783 pkgCache::VerFileIterator Vf;
784
785 /** \brief How many (more) times to try to find a new source from
786 * which to download this package version if it fails.
787 *
788 * Set from Acquire::Retries.
789 */
790 unsigned int Retries;
791
792 /** \brief \b true if this version file is being downloaded from a
793 * trusted source.
794 */
795 bool Trusted;
796
797 /** \brief Queue up the next available file for this version. */
798 bool QueueNext();
799
800 public:
801
802 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
803 virtual void Done(string Message,unsigned long Size,string Md5Hash,
804 pkgAcquire::MethodConfig *Cnf);
805 virtual string MD5Sum() {return MD5;};
806 virtual string DescURI() {return Desc.URI;};
807 virtual string ShortDesc() {return Desc.ShortDesc;};
808 virtual void Finished();
809
810 virtual bool IsTrusted();
811
812 /** \brief Create a new pkgAcqArchive.
813 *
814 * \param Owner The pkgAcquire object with which this item is
815 * associated.
816 *
817 * \param Sources The sources from which to download version
818 * files.
819 *
820 * \param Recs A package records object, used to look up the file
821 * corresponding to each version of the package.
822 *
823 * \param Version The package version to download.
824 *
825 * \param StoreFilename A location in which the actual filename of
826 * the package should be stored. It will be set to a guessed
827 * basename in the constructor, and filled in with a fully
828 * qualified filename once the download finishes.
829 */
830 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
831 pkgRecords *Recs,pkgCache::VerIterator const &Version,
832 string &StoreFilename);
833 };
834
835 /** \brief Retrieve an arbitrary file to the current directory.
836 *
837 * The file is retrieved even if it is accessed via a URL type that
838 * normally is a NOP, such as "file". If the download fails, the
839 * partial file is renamed to get a ".FAILED" extension.
840 */
841 class pkgAcqFile : public pkgAcquire::Item
842 {
843 /** \brief The currently active download process. */
844 pkgAcquire::ItemDesc Desc;
845
846 /** \brief The md5sum of the file to download, if it is known. */
847 string Md5Hash;
848
849 /** \brief How many times to retry the download, set from
850 * Acquire::Retries.
851 */
852 unsigned int Retries;
853
854 public:
855
856 // Specialized action members
857 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
858 virtual void Done(string Message,unsigned long Size,string Md5Hash,
859 pkgAcquire::MethodConfig *Cnf);
860 virtual string MD5Sum() {return Md5Hash;};
861 virtual string DescURI() {return Desc.URI;};
862
863 /** \brief Create a new pkgAcqFile object.
864 *
865 * \param Owner The pkgAcquire object with which this object is
866 * associated.
867 *
868 * \param URI The URI to download.
869 *
870 * \param MD5 The md5sum of the file to download, if it is known;
871 * otherwise "".
872 *
873 * \param Size The size of the file to download, if it is known;
874 * otherwise 0.
875 *
876 * \param Desc A description of the file being downloaded.
877 *
878 * \param ShortDesc A brief description of the file being
879 * downloaded.
880 *
881 * \param DestDir The directory the file should be downloaded into.
882 *
883 * \param DestFilename The filename+path the file is downloaded to.
884 *
885 *
886 * If DestFilename is empty, download to DestDir/<basename> if
887 * DestDir is non-empty, $CWD/<basename> otherwise. If
888 * DestFilename is NOT empty, DestDir is ignored and DestFilename
889 * is the absolute name to which the file should be downloaded.
890 */
891
892 pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size,
893 string Desc, string ShortDesc,
894 const string &DestDir="", const string &DestFilename="");
895 };
896
897 /** @} */
898
899 #endif