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