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