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