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