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