]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/acquire-item.h
give a descriptive error for pipe tries with 'false'
[apt.git] / apt-pkg / acquire-item.h
... / ...
CommitLineData
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
44class pkgRecords;
45class pkgSourceList;
46class pkgAcqMetaClearSig;
47class pkgAcqIndexMergeDiffs;
48class metaIndex;
49
50class 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 protected:
308 /** \brief The acquire object with which this item is associated. */
309 pkgAcquire * const Owner;
310
311 /** \brief The item that is currently being downloaded. */
312 pkgAcquire::ItemDesc Desc;
313
314 enum RenameOnErrorState {
315 HashSumMismatch,
316 SizeMismatch,
317 InvalidFormat,
318 SignatureError,
319 NotClearsigned,
320 MaximumSizeExceeded,
321 PDiffError,
322 };
323
324 /** \brief Rename failed file and set error
325 *
326 * \param state respresenting the error we encountered
327 */
328 bool RenameOnError(RenameOnErrorState const state);
329
330 /** \brief Insert this item into its owner's queue.
331 *
332 * The method is designed to check if the request would end
333 * in an IMSHit and if it determines that it would, it isn't
334 * queueing the Item and instead sets it to completion instantly.
335 *
336 * \param Item Metadata about this item (its URI and
337 * description).
338 * \return true if the item was inserted, false if IMSHit was detected
339 */
340 virtual bool QueueURI(ItemDesc &Item);
341
342 /** \brief Remove this item from its owner's queue. */
343 void Dequeue();
344
345 /** \brief Rename a file without modifying its timestamp.
346 *
347 * Many item methods call this as their final action.
348 *
349 * \param From The file to be renamed.
350 *
351 * \param To The new name of \a From. If \a To exists it will be
352 * overwritten. If \a From and \a To are equal nothing happens.
353 */
354 bool Rename(std::string const &From, std::string const &To);
355
356 /** \brief Get the full pathname of the final file for the current URI */
357 virtual std::string GetFinalFilename() const;
358
359 private:
360 void * const d;
361
362 friend class pkgAcqMetaBase;
363 friend class pkgAcqMetaClearSig;
364};
365 /*}}}*/
366class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item /*{{{*/
367/** \brief baseclass for the indexes files to manage them all together */
368{
369 void * const d;
370 protected:
371 HashStringList GetExpectedHashesFor(std::string const &MetaKey) const;
372
373 bool QueueURI(pkgAcquire::ItemDesc &Item) APT_OVERRIDE;
374
375 public:
376 IndexTarget const Target;
377
378 /** \brief storge name until a transaction is finished */
379 std::string PartialFile;
380
381 /** \brief TransactionManager */
382 pkgAcqMetaClearSig * const TransactionManager;
383
384 enum TransactionStates {
385 TransactionStarted,
386 TransactionCommit,
387 TransactionAbort,
388 };
389 virtual bool TransactionState(TransactionStates const state);
390
391 virtual std::string DescURI() const APT_OVERRIDE { return Target.URI; }
392 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
393 virtual std::string GetMetaKey() const;
394 virtual bool HashesRequired() const APT_OVERRIDE;
395
396
397 pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager, IndexTarget const &Target) APT_NONNULL(2, 3);
398 virtual ~pkgAcqTransactionItem();
399
400 friend class pkgAcqMetaBase;
401 friend class pkgAcqMetaClearSig;
402};
403 /*}}}*/
404class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
405/** \brief the manager of a transaction */
406{
407 void * const d;
408 protected:
409 std::vector<pkgAcqTransactionItem*> Transaction;
410
411 /** \brief If \b true, the index's signature is currently being verified.
412 */
413 bool AuthPass;
414
415 /** \brief Called when a file is finished being retrieved.
416 *
417 * If the file was not downloaded to DestFile, a copy process is
418 * set up to copy it to DestFile; otherwise, Complete is set to \b
419 * true and the file is moved to its final location.
420 *
421 * \param Message The message block received from the fetch
422 * subprocess.
423 */
424 bool CheckDownloadDone(pkgAcqTransactionItem * const I, const std::string &Message, HashStringList const &Hashes) const;
425
426 /** \brief Queue the downloaded Signature for verification */
427 void QueueForSignatureVerify(pkgAcqTransactionItem * const I, std::string const &File, std::string const &Signature);
428
429 virtual std::string Custom600Headers() const APT_OVERRIDE;
430
431 /** \brief Called when authentication succeeded.
432 *
433 * Sanity-checks the authenticated file, queues up the individual
434 * index files for download, and saves the signature in the lists
435 * directory next to the authenticated list file.
436 *
437 * \param Message The message block received from the fetch
438 * subprocess.
439 */
440 bool CheckAuthDone(std::string const &Message);
441
442 /** Check if the current item should fail at this point */
443 bool CheckStopAuthentication(pkgAcquire::Item * const I, const std::string &Message);
444
445 /** \brief Check that the release file is a release file for the
446 * correct distribution.
447 *
448 * \return \b true if no fatal errors were encountered.
449 */
450 bool VerifyVendor(std::string const &Message);
451
452 virtual bool TransactionState(TransactionStates const state) APT_OVERRIDE;
453
454 public:
455 // This refers more to the Transaction-Manager than the actual file
456 bool IMSHit;
457 TransactionStates State;
458 std::string BaseURI;
459
460 virtual bool QueueURI(pkgAcquire::ItemDesc &Item) APT_OVERRIDE;
461 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
462 virtual bool HashesRequired() const APT_OVERRIDE;
463
464 // transaction code
465 void Add(pkgAcqTransactionItem * const I);
466 void AbortTransaction();
467 bool TransactionHasError() const;
468 void CommitTransaction();
469
470 /** \brief Stage (queue) a copy action when the transaction is committed
471 */
472 void TransactionStageCopy(pkgAcqTransactionItem * const I,
473 const std::string &From,
474 const std::string &To);
475 /** \brief Stage (queue) a removal action when the transaction is committed
476 */
477 void TransactionStageRemoval(pkgAcqTransactionItem * const I, const std::string &FinalFile);
478
479 /** \brief Get the full pathname of the final file for the current URI */
480 virtual std::string GetFinalFilename() const APT_OVERRIDE;
481
482 pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
483 IndexTarget const &DataTarget) APT_NONNULL(2, 3);
484 virtual ~pkgAcqMetaBase();
485};
486 /*}}}*/
487/** \brief An item that is responsible for downloading the meta-index {{{
488 * file (i.e., Release) itself and verifying its signature.
489 *
490 * Once the download and verification are complete, the downloads of
491 * the individual index files are queued up using pkgAcqDiffIndex.
492 * If the meta-index file had a valid signature, the expected hashsums
493 * of the index files will be the md5sums listed in the meta-index;
494 * otherwise, the expected hashsums will be "" (causing the
495 * authentication of the index files to be bypassed).
496 */
497class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
498{
499 void * const d;
500 protected:
501 IndexTarget const DetachedSigTarget;
502
503 /** \brief delayed constructor */
504 void Init(std::string const &URIDesc, std::string const &ShortDesc);
505
506 public:
507 virtual std::string DescURI() const APT_OVERRIDE;
508
509 // Specialized action members
510 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
511 virtual void Done(std::string const &Message, HashStringList const &Hashes,
512 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
513
514 /** \brief Create a new pkgAcqMetaIndex. */
515 pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
516 IndexTarget const &DataTarget, IndexTarget const &DetachedSigTarget) APT_NONNULL(2, 3);
517 virtual ~pkgAcqMetaIndex();
518
519 friend class pkgAcqMetaSig;
520};
521 /*}}}*/
522/** \brief An acquire item that downloads the detached signature {{{
523 * of a meta-index (Release) file, then queues up the release
524 * file itself.
525 *
526 * \todo Why protected members?
527 *
528 * \sa pkgAcqMetaIndex
529 */
530class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem
531{
532 void * const d;
533
534 pkgAcqMetaIndex * const MetaIndex;
535
536 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
537 std::string MetaIndexFileSignature;
538
539 protected:
540
541 /** \brief Get the full pathname of the final file for the current URI */
542 virtual std::string GetFinalFilename() const APT_OVERRIDE;
543
544 public:
545 virtual bool HashesRequired() const APT_OVERRIDE { return false; }
546
547 // Specialized action members
548 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
549 virtual void Done(std::string const &Message, HashStringList const &Hashes,
550 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
551 virtual std::string Custom600Headers() const APT_OVERRIDE;
552
553 /** \brief Create a new pkgAcqMetaSig. */
554 pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
555 IndexTarget const &Target, pkgAcqMetaIndex * const MetaIndex) APT_NONNULL(2, 3, 5);
556 virtual ~pkgAcqMetaSig();
557};
558 /*}}}*/
559/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
560class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
561{
562 void * const d;
563 IndexTarget const DetachedDataTarget;
564
565 public:
566 /** \brief A package-system-specific parser for the meta-index file. */
567 metaIndex *MetaIndexParser;
568 metaIndex *LastMetaIndexParser;
569
570 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
571 virtual std::string Custom600Headers() const APT_OVERRIDE;
572 virtual bool VerifyDone(std::string const &Message, pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
573 virtual void Done(std::string const &Message, HashStringList const &Hashes,
574 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
575 virtual void Finished() APT_OVERRIDE;
576
577 /** \brief Starts downloading the individual index files.
578 *
579 * \param verify If \b true, only indices whose expected hashsum
580 * can be determined from the meta-index will be downloaded, and
581 * the hashsums of indices will be checked (reporting
582 * #StatAuthError if there is a mismatch). If verify is \b false,
583 * no hashsum checking will be performed.
584 */
585 void QueueIndexes(bool const verify);
586
587 /** \brief Create a new pkgAcqMetaClearSig. */
588 pkgAcqMetaClearSig(pkgAcquire * const Owner,
589 IndexTarget const &ClearsignedTarget,
590 IndexTarget const &DetachedDataTarget,
591 IndexTarget const &DetachedSigTarget,
592 metaIndex * const MetaIndexParser);
593 virtual ~pkgAcqMetaClearSig();
594};
595 /*}}}*/
596/** \brief Common base class for all classes that deal with fetching indexes {{{*/
597class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
598{
599 void * const d;
600
601 public:
602 /** \brief Get the full pathname of the final file for the current URI */
603 virtual std::string GetFinalFilename() const APT_OVERRIDE;
604 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
605
606 pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
607 IndexTarget const &Target) APT_NONNULL(2, 3);
608 virtual ~pkgAcqBaseIndex();
609};
610 /*}}}*/
611/** \brief An item that is responsible for fetching an index file of {{{
612 * package list diffs and starting the package list's download.
613 *
614 * This item downloads the Index file and parses it, then enqueues
615 * additional downloads of either the individual patches (using
616 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
617 *
618 * \sa pkgAcqIndexDiffs, pkgAcqIndex
619 */
620class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
621{
622 void * const d;
623 std::vector<pkgAcqIndexMergeDiffs*> * diffs;
624
625 protected:
626 /** \brief If \b true, debugging information will be written to std::clog. */
627 bool Debug;
628
629 /** \brief A description of the Packages file (stored in
630 * pkgAcquire::ItemDesc::Description).
631 */
632 std::string Description;
633
634 /** \brief Get the full pathname of the final file for the current URI */
635 virtual std::string GetFinalFilename() const APT_OVERRIDE;
636
637 virtual bool QueueURI(pkgAcquire::ItemDesc &Item) APT_OVERRIDE;
638
639 virtual bool TransactionState(TransactionStates const state) APT_OVERRIDE;
640 public:
641 // Specialized action members
642 virtual void Failed(std::string const &Message, pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
643 virtual void Done(std::string const &Message, HashStringList const &Hashes,
644 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
645 virtual std::string DescURI() const APT_OVERRIDE {return Target.URI + "Index";};
646 virtual std::string Custom600Headers() const APT_OVERRIDE;
647 virtual std::string GetMetaKey() const APT_OVERRIDE;
648
649 /** \brief Parse the Index file for a set of Packages diffs.
650 *
651 * Parses the Index file and creates additional download items as
652 * necessary.
653 *
654 * \param IndexDiffFile The name of the Index file.
655 *
656 * \return \b true if the Index file was successfully parsed, \b
657 * false otherwise.
658 */
659 bool ParseDiffIndex(std::string const &IndexDiffFile);
660
661 /** \brief Create a new pkgAcqDiffIndex.
662 *
663 * \param Owner The Acquire object that owns this item.
664 *
665 * \param URI The URI of the list file to download.
666 *
667 * \param URIDesc A long description of the list file to download.
668 *
669 * \param ShortDesc A short description of the list file to download.
670 */
671 pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
672 IndexTarget const &Target) APT_NONNULL(2, 3);
673 virtual ~pkgAcqDiffIndex();
674 private:
675 APT_HIDDEN void QueueOnIMSHit() const;
676};
677 /*}}}*/
678struct APT_HIDDEN DiffInfo { /*{{{*/
679 /** The filename of the diff. */
680 std::string file;
681
682 /** The hashes of the file after the diff is applied */
683 HashStringList result_hashes;
684
685 /** The hashes of the diff */
686 HashStringList patch_hashes;
687
688 /** The hashes of the compressed diff */
689 HashStringList download_hashes;
690};
691 /*}}}*/
692/** \brief An item that is responsible for fetching client-merge patches {{{
693 * that need to be applied to a given package index file.
694 *
695 * Instead of downloading and applying each patch one by one like its
696 * sister #pkgAcqIndexDiffs this class will download all patches at once
697 * and call rred with all the patches downloaded once. Rred will then
698 * merge and apply them in one go, which should be a lot faster – but is
699 * incompatible with server-based merges of patches like reprepro can do.
700 *
701 * \sa pkgAcqDiffIndex, pkgAcqIndex
702 */
703class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
704{
705 void * const d;
706
707 protected:
708
709 /** \brief If \b true, debugging output will be written to
710 * std::clog.
711 */
712 bool Debug;
713
714 /** \brief description of the file being downloaded. */
715 std::string Description;
716
717 /** \brief information about the current patch */
718 struct DiffInfo const patch;
719
720 /** \brief list of all download items for the patches */
721 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
722
723 /** The current status of this patch. */
724 enum DiffState
725 {
726 /** \brief The diff is currently being fetched. */
727 StateFetchDiff,
728
729 /** \brief The diff is currently being applied. */
730 StateApplyDiff,
731
732 /** \brief the work with this diff is done */
733 StateDoneDiff,
734
735 /** \brief something bad happened and fallback was triggered */
736 StateErrorDiff
737 } State;
738
739 public:
740 /** \brief Called when the patch file failed to be downloaded.
741 *
742 * This method will fall back to downloading the whole index file
743 * outright; its arguments are ignored.
744 */
745 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
746 virtual void Done(std::string const &Message, HashStringList const &Hashes,
747 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
748 virtual std::string Custom600Headers() const APT_OVERRIDE;
749 virtual std::string DescURI() const APT_OVERRIDE {return Target.URI + "Index";};
750 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
751 virtual bool HashesRequired() const APT_OVERRIDE;
752
753 /** \brief Create an index merge-diff item.
754 *
755 * \param Owner The pkgAcquire object that owns this item.
756 *
757 * \param URI The URI of the package index file being
758 * reconstructed.
759 *
760 * \param URIDesc A long description of this item.
761 *
762 * \param ShortDesc A brief description of this item.
763 *
764 * \param patch contains infos about the patch this item is supposed
765 * to download which were read from the index
766 *
767 * \param allPatches contains all related items so that each item can
768 * check if it was the last one to complete the download step
769 */
770 pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
771 IndexTarget const &Target, DiffInfo const &patch,
772 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches) APT_NONNULL(2, 3, 6);
773 virtual ~pkgAcqIndexMergeDiffs();
774};
775 /*}}}*/
776/** \brief An item that is responsible for fetching server-merge patches {{{
777 * that need to be applied to a given package index file.
778 *
779 * After downloading and applying a single patch, this item will
780 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
781 * patches. If no patch can be found that applies to an intermediate
782 * file or if one of the patches cannot be downloaded, falls back to
783 * downloading the entire package index file using pkgAcqIndex.
784 *
785 * \sa pkgAcqDiffIndex, pkgAcqIndex
786 */
787class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
788{
789 void * const d;
790
791 private:
792
793 /** \brief Queue up the next diff download.
794 *
795 * Search for the next available diff that applies to the file
796 * that currently exists on disk, and enqueue it by calling
797 * QueueURI().
798 *
799 * \return \b true if an applicable diff was found, \b false
800 * otherwise.
801 */
802 APT_HIDDEN bool QueueNextDiff();
803
804 /** \brief Handle tasks that must be performed after the item
805 * finishes downloading.
806 *
807 * Dequeues the item and checks the resulting file's hashsums
808 * against ExpectedHashes after the last patch was applied.
809 * There is no need to check the md5/sha1 after a "normal"
810 * patch because QueueNextDiff() will check the sha1 later.
811 *
812 * \param allDone If \b true, the file was entirely reconstructed,
813 * and its md5sum is verified.
814 */
815 APT_HIDDEN void Finish(bool const allDone=false);
816
817 protected:
818
819 /** \brief If \b true, debugging output will be written to
820 * std::clog.
821 */
822 bool Debug;
823
824 /** A description of the file being downloaded. */
825 std::string Description;
826
827 /** The patches that remain to be downloaded, including the patch
828 * being downloaded right now. This list should be ordered so
829 * that each diff appears before any diff that depends on it.
830 *
831 * \todo These are indexed by sha1sum; why not use some sort of
832 * dictionary instead of relying on ordering and stripping them
833 * off the front?
834 */
835 std::vector<DiffInfo> available_patches;
836
837 /** The current status of this patch. */
838 enum DiffState
839 {
840 /** \brief The diff is currently being fetched. */
841 StateFetchDiff,
842
843 /** \brief The diff is currently being applied. */
844 StateApplyDiff
845 } State;
846
847 public:
848
849 /** \brief Called when the patch file failed to be downloaded.
850 *
851 * This method will fall back to downloading the whole index file
852 * outright; its arguments are ignored.
853 */
854 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
855
856 virtual void Done(std::string const &Message, HashStringList const &Hashes,
857 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
858 virtual std::string Custom600Headers() const APT_OVERRIDE;
859 virtual std::string DescURI() const APT_OVERRIDE {return Target.URI + "IndexDiffs";};
860 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
861 virtual bool HashesRequired() const APT_OVERRIDE;
862
863 /** \brief Create an index diff item.
864 *
865 * After filling in its basic fields, this invokes Finish(true) if
866 * \a diffs is empty, or QueueNextDiff() otherwise.
867 *
868 * \param Owner The pkgAcquire object that owns this item.
869 *
870 * \param URI The URI of the package index file being
871 * reconstructed.
872 *
873 * \param URIDesc A long description of this item.
874 *
875 * \param ShortDesc A brief description of this item.
876 *
877 * \param diffs The remaining diffs from the index of diffs. They
878 * should be ordered so that each diff appears before any diff
879 * that depends on it.
880 */
881 pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
882 IndexTarget const &Target,
883 std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>()) APT_NONNULL(2, 3);
884 virtual ~pkgAcqIndexDiffs();
885};
886 /*}}}*/
887/** \brief An acquire item that is responsible for fetching an index {{{
888 * file (e.g., Packages or Sources).
889 *
890 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
891 *
892 * \todo Why does pkgAcqIndex have protected members?
893 */
894class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
895{
896 void * const d;
897
898 protected:
899
900 /** \brief The stages the method goes through
901 *
902 * The method first downloads the indexfile, then its decompressed (or
903 * copied) and verified
904 */
905 enum AllStages {
906 STAGE_DOWNLOAD,
907 STAGE_DECOMPRESS_AND_VERIFY,
908 };
909 AllStages Stage;
910
911 /** \brief Handle what needs to be done when the download is done */
912 void StageDownloadDone(std::string const &Message);
913
914 /** \brief Handle what needs to be done when the decompression/copy is
915 * done
916 */
917 void StageDecompressDone();
918
919 /** \brief If \b set, this partially downloaded file will be
920 * removed when the download completes.
921 */
922 std::string EraseFileName;
923
924 /** \brief The compression-related file extensions that are being
925 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
926 */
927 std::string CompressionExtensions;
928
929 /** \brief The actual compression extension currently used */
930 std::string CurrentCompressionExtension;
931
932 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
933 void InitByHashIfNeeded();
934
935 /** \brief Get the full pathname of the final file for the current URI */
936 virtual std::string GetFinalFilename() const APT_OVERRIDE;
937
938 virtual bool TransactionState(TransactionStates const state) APT_OVERRIDE;
939
940 public:
941 // Specialized action members
942 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
943 virtual void Done(std::string const &Message, HashStringList const &Hashes,
944 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
945 virtual std::string Custom600Headers() const APT_OVERRIDE;
946 virtual std::string DescURI() const APT_OVERRIDE {return Desc.URI;};
947 virtual std::string GetMetaKey() const APT_OVERRIDE;
948
949 pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
950 IndexTarget const &Target) APT_NONNULL(2, 3);
951 virtual ~pkgAcqIndex();
952
953 private:
954 APT_HIDDEN void Init(std::string const &URI, std::string const &URIDesc,
955 std::string const &ShortDesc);
956};
957 /*}}}*/
958/** \brief An item that is responsible for fetching a package file. {{{
959 *
960 * If the package file already exists in the cache, nothing will be
961 * done.
962 */
963class pkgAcqArchive : public pkgAcquire::Item
964{
965 void * const d;
966
967 bool LocalSource;
968 HashStringList ExpectedHashes;
969
970 protected:
971 /** \brief The package version being fetched. */
972 pkgCache::VerIterator Version;
973
974 /** \brief The list of sources from which to pick archives to
975 * download this package from.
976 */
977 pkgSourceList *Sources;
978
979 /** \brief A package records object, used to look up the file
980 * corresponding to each version of the package.
981 */
982 pkgRecords *Recs;
983
984 /** \brief A location in which the actual filename of the package
985 * should be stored.
986 */
987 std::string &StoreFilename;
988
989 /** \brief The next file for this version to try to download. */
990 pkgCache::VerFileIterator Vf;
991
992 /** \brief How many (more) times to try to find a new source from
993 * which to download this package version if it fails.
994 *
995 * Set from Acquire::Retries.
996 */
997 unsigned int Retries;
998
999 /** \brief \b true if this version file is being downloaded from a
1000 * trusted source.
1001 */
1002 bool Trusted;
1003
1004 /** \brief Queue up the next available file for this version. */
1005 bool QueueNext();
1006
1007 /** \brief Get the full pathname of the final file for the current URI */
1008 virtual std::string GetFinalFilename() const APT_OVERRIDE;
1009
1010 public:
1011
1012 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1013 virtual void Done(std::string const &Message, HashStringList const &Hashes,
1014 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1015 virtual std::string DescURI() const APT_OVERRIDE;
1016 virtual std::string ShortDesc() const APT_OVERRIDE;
1017 virtual void Finished() APT_OVERRIDE;
1018 virtual bool IsTrusted() const APT_OVERRIDE;
1019 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
1020 virtual bool HashesRequired() const APT_OVERRIDE;
1021
1022 /** \brief Create a new pkgAcqArchive.
1023 *
1024 * \param Owner The pkgAcquire object with which this item is
1025 * associated.
1026 *
1027 * \param Sources The sources from which to download version
1028 * files.
1029 *
1030 * \param Recs A package records object, used to look up the file
1031 * corresponding to each version of the package.
1032 *
1033 * \param Version The package version to download.
1034 *
1035 * \param[out] StoreFilename A location in which the actual filename of
1036 * the package should be stored. It will be set to a guessed
1037 * basename in the constructor, and filled in with a fully
1038 * qualified filename once the download finishes.
1039 */
1040 pkgAcqArchive(pkgAcquire * const Owner,pkgSourceList * const Sources,
1041 pkgRecords * const Recs,pkgCache::VerIterator const &Version,
1042 std::string &StoreFilename);
1043 virtual ~pkgAcqArchive();
1044};
1045 /*}}}*/
1046/** \brief Retrieve the changelog for the given version {{{
1047 *
1048 * Downloads the changelog to a temporary file it will also remove again
1049 * while it is deconstructed or downloads it to a named location.
1050 */
1051class pkgAcqChangelog : public pkgAcquire::Item
1052{
1053 class Private;
1054 Private * const d;
1055 std::string TemporaryDirectory;
1056 std::string const SrcName;
1057 std::string const SrcVersion;
1058
1059 public:
1060 // we will never have hashes for changelogs.
1061 // If you need verified ones, download the deb and extract the changelog.
1062 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE { return HashStringList(); }
1063 virtual bool HashesRequired() const APT_OVERRIDE { return false; }
1064
1065 // Specialized action members
1066 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1067 virtual void Done(std::string const &Message, HashStringList const &CalcHashes,
1068 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1069 virtual std::string DescURI() const APT_OVERRIDE {return Desc.URI;};
1070
1071 /** returns the URI to the changelog of this version
1072 *
1073 * @param Ver is the version to get the changelog for
1074 * @return the URI which will be used to acquire the changelog
1075 */
1076 static std::string URI(pkgCache::VerIterator const &Ver);
1077
1078 /** returns the URI to the changelog of this version
1079 *
1080 * \param Rls is the Release file the package comes from
1081 * \param Component in which the package resides, can be empty
1082 * \param SrcName is the source package name
1083 * \param SrcVersion is the source package version
1084 * @return the URI which will be used to acquire the changelog
1085 */
1086 static std::string URI(pkgCache::RlsFileIterator const &Rls,
1087 char const * const Component, char const * const SrcName,
1088 char const * const SrcVersion);
1089
1090 /** returns the URI to the changelog of this version
1091 *
1092 * \param Template URI where @CHANGEPATH@ has to be filled in
1093 * \param Component in which the package resides, can be empty
1094 * \param SrcName is the source package name
1095 * \param SrcVersion is the source package version
1096 * @return the URI which will be used to acquire the changelog
1097 */
1098 static std::string URI(std::string const &Template,
1099 char const * const Component, char const * const SrcName,
1100 char const * const SrcVersion);
1101
1102 /** returns the URI template for this release file
1103 *
1104 * \param Rls is a Release file
1105 * @return the URI template to use for this release file
1106 */
1107 static std::string URITemplate(pkgCache::RlsFileIterator const &Rls);
1108
1109 /** \brief Create a new pkgAcqChangelog object.
1110 *
1111 * \param Owner The pkgAcquire object with which this object is
1112 * associated.
1113 * \param Ver is the version to get the changelog for
1114 * \param DestDir The directory the file should be downloaded into.
1115 * Will be an autocreated (and cleaned up) temporary directory if not set.
1116 * \param DestFilename The filename the file should have in #DestDir
1117 * Defaults to sourcepackagename.changelog if not set.
1118 */
1119 pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::VerIterator const &Ver,
1120 std::string const &DestDir="", std::string const &DestFilename="");
1121
1122 /** \brief Create a new pkgAcqChangelog object.
1123 *
1124 * \param Owner The pkgAcquire object with which this object is
1125 * associated.
1126 * \param Rls is the Release file the package comes from
1127 * \param Component in which the package resides, can be empty
1128 * \param SrcName is the source package name
1129 * \param SrcVersion is the source package version
1130 * \param DestDir The directory the file should be downloaded into.
1131 * Will be an autocreated (and cleaned up) temporary directory if not set.
1132 * \param DestFilename The filename the file should have in #DestDir
1133 * Defaults to sourcepackagename.changelog if not set.
1134 */
1135 pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::RlsFileIterator const &Rls,
1136 char const * const Component, char const * const SrcName, char const * const SrcVersion,
1137 std::string const &DestDir="", std::string const &DestFilename="");
1138
1139 /** \brief Create a new pkgAcqChangelog object.
1140 *
1141 * \param Owner The pkgAcquire object with which this object is
1142 * associated.
1143 * \param URI is to be used to get the changelog
1144 * \param SrcName is the source package name
1145 * \param SrcVersion is the source package version
1146 * \param DestDir The directory the file should be downloaded into.
1147 * Will be an autocreated (and cleaned up) temporary directory if not set.
1148 * \param DestFilename The filename the file should have in #DestDir
1149 * Defaults to sourcepackagename.changelog if not set.
1150 */
1151 pkgAcqChangelog(pkgAcquire * const Owner, std::string const &URI,
1152 char const * const SrcName, char const * const SrcVersion,
1153 std::string const &DestDir="", std::string const &DestFilename="");
1154
1155 virtual ~pkgAcqChangelog();
1156
1157private:
1158 APT_HIDDEN void Init(std::string const &DestDir, std::string const &DestFilename);
1159};
1160 /*}}}*/
1161/** \brief Retrieve an arbitrary file to the current directory. {{{
1162 *
1163 * The file is retrieved even if it is accessed via a URL type that
1164 * normally is a NOP, such as "file". If the download fails, the
1165 * partial file is renamed to get a ".FAILED" extension.
1166 */
1167class pkgAcqFile : public pkgAcquire::Item
1168{
1169 void * const d;
1170
1171 /** \brief How many times to retry the download, set from
1172 * Acquire::Retries.
1173 */
1174 unsigned int Retries;
1175
1176 /** \brief Should this file be considered a index file */
1177 bool IsIndexFile;
1178
1179 HashStringList const ExpectedHashes;
1180 public:
1181 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
1182 virtual bool HashesRequired() const APT_OVERRIDE;
1183
1184 // Specialized action members
1185 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1186 virtual void Done(std::string const &Message, HashStringList const &CalcHashes,
1187 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1188 virtual std::string DescURI() const APT_OVERRIDE {return Desc.URI;};
1189 virtual std::string Custom600Headers() const APT_OVERRIDE;
1190
1191 /** \brief Create a new pkgAcqFile object.
1192 *
1193 * \param Owner The pkgAcquire object with which this object is
1194 * associated.
1195 *
1196 * \param URI The URI to download.
1197 *
1198 * \param Hashes The hashsums of the file to download, if they are known;
1199 * otherwise empty list.
1200 *
1201 * \param Size The size of the file to download, if it is known;
1202 * otherwise 0.
1203 *
1204 * \param Desc A description of the file being downloaded.
1205 *
1206 * \param ShortDesc A brief description of the file being
1207 * downloaded.
1208 *
1209 * \param DestDir The directory the file should be downloaded into.
1210 *
1211 * \param DestFilename The filename+path the file is downloaded to.
1212 *
1213 * \param IsIndexFile The file is considered a IndexFile and cache-control
1214 * headers like "cache-control: max-age=0" are send
1215 *
1216 * If DestFilename is empty, download to DestDir/\<basename\> if
1217 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1218 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1219 * is the absolute name to which the file should be downloaded.
1220 */
1221
1222 pkgAcqFile(pkgAcquire * const Owner, std::string const &URI, HashStringList const &Hashes, unsigned long long const Size,
1223 std::string const &Desc, std::string const &ShortDesc,
1224 std::string const &DestDir="", std::string const &DestFilename="",
1225 bool const IsIndexFile=false);
1226 virtual ~pkgAcqFile();
1227};
1228 /*}}}*/
1229/** @} */
1230
1231#endif