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