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