]> git.saurik.com Git - apt.git/blame - apt-pkg/acquire-item.h
fix same-mirror redirection for Release{,.gpg} pair
[apt.git] / apt-pkg / acquire-item.h
CommitLineData
0118833a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
0118833a
AL
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
448c38bd
DK
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
770c32ec 11 Three item classes are provided to provide functionality for
a52f938b 12 downloading of Index, Translation and Packages files.
448c38bd 13
495e5cb2 14 A Archive class is provided for downloading .deb files. It does Hash
17caf1b1 15 checking and source location as well as a retry algorithm.
448c38bd 16
0118833a
AL
17 ##################################################################### */
18 /*}}}*/
19#ifndef PKGLIB_ACQUIRE_ITEM_H
20#define PKGLIB_ACQUIRE_ITEM_H
21
22#include <apt-pkg/acquire.h>
e3c1cfc7 23#include <apt-pkg/indexfile.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 33#ifndef APT_8_CLEANER_HEADERS
b9dadc24
DK
34#include <apt-pkg/sourcelist.h>
35#include <apt-pkg/pkgrecords.h>
b9dadc24
DK
36#endif
37
3174e150
MV
38/** \addtogroup acquire
39 * @{
40 *
41 * \file acquire-item.h
42 */
43
472ff00e
DK
44class pkgRecords;
45class pkgSourceList;
3d8232bf
DK
46class pkgAcqMetaClearSig;
47class pkgAcqIndexMergeDiffs;
5ad0096a 48class metaIndex;
472ff00e 49
448c38bd
DK
50class pkgAcquire::Item : public WeakPointable /*{{{*/
51/** \brief Represents the process by which a pkgAcquire object should
3174e150
MV
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 */
448c38bd 63{
0118833a
AL
64 public:
65
3174e150
MV
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 */
6ca714d5
MV
86 StatAuthError,
87
448c38bd 88 /** \brief The item was could not be downloaded because of
6ca714d5
MV
89 * a transient network error (e.g. network down)
90 */
56472095 91 StatTransientNetworkError,
3174e150
MV
92 } Status;
93
94 /** \brief Contains a textual description of the error encountered
255c9e4b 95 * if #ItemState is #StatError or #StatAuthError.
3174e150 96 */
472ff00e 97 std::string ErrorText;
3174e150
MV
98
99 /** \brief The size of the object to fetch. */
e2c66de5 100 unsigned long long FileSize;
3174e150
MV
101
102 /** \brief How much of the object was already fetched. */
e2c66de5 103 unsigned long long PartialSize;
3174e150
MV
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 */
5dd00edb 108 APT_DEPRECATED_MSG("Use the std::string member ActiveSubprocess instead") const char *Mode;
ffbe056d
DK
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;
3174e150
MV
114
115 /** \brief A client-supplied unique identifier.
448c38bd 116 *
3174e150
MV
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 *
448c38bd 120 * APT progress reporting will store an ID there as shown in "Get:42 …"
3174e150 121 */
b98f2859 122 unsigned long ID;
3174e150
MV
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 */
8267fe24 128 bool Complete;
3174e150
MV
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 */
a6568219 135 bool Local;
448c38bd 136
472ff00e 137 std::string UsedMirror;
30e1eab5 138
3174e150
MV
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 */
0118833a 147 unsigned int QueueCounter;
d0cfa8ad
MV
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;
448c38bd 158
3174e150
MV
159 /** \brief The name of the file into which the retrieved object
160 * will be written.
161 */
472ff00e 162 std::string DestFile;
7d8afa39 163
3174e150
MV
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 */
448c38bd 177 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf);
3174e150 178
dd676dc7
DK
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
3174e150
MV
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.
b3501edb 214 * \param Hashes The HashSums of the object that was fetched.
3174e150
MV
215 * \param Cnf The method via which the object was fetched.
216 *
217 * \sa pkgAcqMethod
218 */
448c38bd
DK
219 virtual void Done(std::string const &Message, HashStringList const &Hashes,
220 pkgAcquire::MethodConfig const * const Cnf);
3174e150
MV
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 *
448c38bd 227 * \param Hashes The expected hashes of the object being fetched.
3174e150
MV
228 *
229 * \sa pkgAcqMethod
230 */
448c38bd 231 virtual void Start(std::string const &Message, unsigned long long const Size);
3174e150
MV
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 */
448c38bd 241 virtual std::string Custom600Headers() const;
3174e150
MV
242
243 /** \brief A "descriptive" URI-like string.
244 *
245 * \return a URI that should be used to describe what is being fetched.
246 */
448c38bd 247 virtual std::string DescURI() const = 0;
3174e150
MV
248 /** \brief Short item description.
249 *
250 * \return a brief description of the object being fetched.
251 */
448c38bd 252 virtual std::string ShortDesc() const;
3174e150
MV
253
254 /** \brief Invoked by the worker when the download is completely done. */
448c38bd
DK
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
3174e150 263 *
448c38bd
DK
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.
3174e150 267 */
448c38bd 268 virtual bool HashesRequired() const { return true; }
3174e150
MV
269
270 /** \return the acquire process with which this item is associated. */
448c38bd 271 pkgAcquire *GetOwner() const;
08ea7806 272 pkgAcquire::ItemDesc &GetItemDesc();
3174e150
MV
273
274 /** \return \b true if this object is being fetched from a trusted source. */
448c38bd
DK
275 virtual bool IsTrusted() const;
276
702c84fb 277 /** \brief Report mirror problem
448c38bd 278 *
702c84fb
MV
279 * This allows reporting mirror failures back to a centralized
280 * server. The apt-report-mirror-failure script is called for this
448c38bd 281 *
702c84fb
MV
282 * \param FailCode A short failure string that is send
283 */
3383ef4d 284 APT_DEPRECATED_MSG("Item::Failed does this for you") void ReportMirrorFailure(std::string const &FailCode);
36280399 285
eeac6897
MV
286 /** \brief Set the name of the current active subprocess
287 *
288 * See also #ActiveSubprocess
289 */
448c38bd 290 void SetActiveSubprocess(std::string const &subprocess);
eeac6897 291
3174e150
MV
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 *
3174e150
MV
298 * \param Owner The new owner of this item.
299 */
e8afd168 300 explicit Item(pkgAcquire * const Owner);
3174e150
MV
301
302 /** \brief Remove this item from its owner's queue by invoking
303 * pkgAcquire::Remove.
304 */
0118833a 305 virtual ~Item();
3c8030a4
DK
306
307 protected:
448c38bd
DK
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;
3c8030a4
DK
313
314 enum RenameOnErrorState {
315 HashSumMismatch,
316 SizeMismatch,
631a7dc7
MV
317 InvalidFormat,
318 SignatureError,
319 NotClearsigned,
146f7715
DK
320 MaximumSizeExceeded,
321 PDiffError,
3c8030a4
DK
322 };
323
324 /** \brief Rename failed file and set error
325 *
326 * \param state respresenting the error we encountered
3c8030a4
DK
327 */
328 bool RenameOnError(RenameOnErrorState const state);
fa3b260f 329
448c38bd
DK
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:
6c55f07a 360 void * const d;
448c38bd
DK
361
362 friend class pkgAcqMetaBase;
3d8232bf 363 friend class pkgAcqMetaClearSig;
448c38bd
DK
364};
365 /*}}}*/
366class APT_HIDDEN pkgAcqTransactionItem: public pkgAcquire::Item /*{{{*/
367/** \brief baseclass for the indexes files to manage them all together */
368{
6c55f07a 369 void * const d;
448c38bd 370 protected:
dcbbb14d 371 IndexTarget const Target;
e8afd168 372 HashStringList GetExpectedHashesFor(std::string const &MetaKey) const;
448c38bd 373
3b302846 374 bool QueueURI(pkgAcquire::ItemDesc &Item) APT_OVERRIDE;
448c38bd
DK
375
376 public:
377 /** \brief storge name until a transaction is finished */
378 std::string PartialFile;
379
380 /** \brief TransactionManager */
3d8232bf 381 pkgAcqMetaClearSig * const TransactionManager;
448c38bd 382
146f7715 383 enum TransactionStates {
57f16d51 384 TransactionStarted,
146f7715
DK
385 TransactionCommit,
386 TransactionAbort,
387 };
388 virtual bool TransactionState(TransactionStates const state);
389
3b302846
DK
390 virtual std::string DescURI() const APT_OVERRIDE { return Target.URI; }
391 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
448c38bd 392 virtual std::string GetMetaKey() const;
3b302846 393 virtual bool HashesRequired() const APT_OVERRIDE;
fa3b260f 394
3174e150 395
3d8232bf 396 pkgAcqTransactionItem(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager, IndexTarget const &Target);
448c38bd 397 virtual ~pkgAcqTransactionItem();
f6d4ab9a 398
448c38bd 399 friend class pkgAcqMetaBase;
3d8232bf 400 friend class pkgAcqMetaClearSig;
002d9943 401};
92fcbfc1 402 /*}}}*/
448c38bd
DK
403class APT_HIDDEN pkgAcqMetaBase : public pkgAcqTransactionItem /*{{{*/
404/** \brief the manager of a transaction */
e6e89390 405{
6c55f07a 406 void * const d;
e6e89390 407 protected:
448c38bd 408 std::vector<pkgAcqTransactionItem*> Transaction;
715c65de 409
c045cc02
MV
410 /** \brief The index files which should be looked up in the meta-index
411 * and then downloaded.
412 */
d7a51997 413 std::vector<IndexTarget> IndexTargets;
c045cc02 414
fa3a96a1
MV
415 /** \brief If \b true, the index's signature is currently being verified.
416 */
417 bool AuthPass;
418
c045cc02
MV
419 /** \brief Starts downloading the individual index files.
420 *
421 * \param verify If \b true, only indices whose expected hashsum
422 * can be determined from the meta-index will be downloaded, and
423 * the hashsums of indices will be checked (reporting
424 * #StatAuthError if there is a mismatch). If verify is \b false,
425 * no hashsum checking will be performed.
426 */
448c38bd 427 void QueueIndexes(bool const verify);
c045cc02 428
f3097647
MV
429 /** \brief Called when a file is finished being retrieved.
430 *
431 * If the file was not downloaded to DestFile, a copy process is
432 * set up to copy it to DestFile; otherwise, Complete is set to \b
433 * true and the file is moved to its final location.
434 *
435 * \param Message The message block received from the fetch
436 * subprocess.
437 */
448c38bd 438 bool CheckDownloadDone(pkgAcqTransactionItem * const I, const std::string &Message, HashStringList const &Hashes) const;
f3097647
MV
439
440 /** \brief Queue the downloaded Signature for verification */
448c38bd 441 void QueueForSignatureVerify(pkgAcqTransactionItem * const I, std::string const &File, std::string const &Signature);
f3097647 442
3b302846 443 virtual std::string Custom600Headers() const APT_OVERRIDE;
27e6c17a 444
f3097647
MV
445 /** \brief Called when authentication succeeded.
446 *
447 * Sanity-checks the authenticated file, queues up the individual
448 * index files for download, and saves the signature in the lists
449 * directory next to the authenticated list file.
450 *
451 * \param Message The message block received from the fetch
452 * subprocess.
453 */
448c38bd 454 bool CheckAuthDone(std::string const &Message);
f3097647 455
2d0a7bb4 456 /** Check if the current item should fail at this point */
6bf93605 457 bool CheckStopAuthentication(pkgAcquire::Item * const I, const std::string &Message);
2d0a7bb4 458
f3097647
MV
459 /** \brief Check that the release file is a release file for the
460 * correct distribution.
461 *
462 * \return \b true if no fatal errors were encountered.
463 */
448c38bd 464 bool VerifyVendor(std::string const &Message);
295d848b 465
3b302846 466 virtual bool TransactionState(TransactionStates const state) APT_OVERRIDE;
295d848b 467
715c65de 468 public:
ba6b79bd
DK
469 // This refers more to the Transaction-Manager than the actual file
470 bool IMSHit;
57f16d51 471 TransactionStates State;
9b8034a9 472 std::string BaseURI;
ba6b79bd 473
3b302846
DK
474 virtual bool QueueURI(pkgAcquire::ItemDesc &Item) APT_OVERRIDE;
475 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
476 virtual bool HashesRequired() const APT_OVERRIDE;
295d848b 477
715c65de 478 // transaction code
448c38bd 479 void Add(pkgAcqTransactionItem * const I);
715c65de 480 void AbortTransaction();
448c38bd 481 bool TransactionHasError() const;
715c65de
MV
482 void CommitTransaction();
483
dce45dbe 484 /** \brief Stage (queue) a copy action when the transaction is committed
fa3a96a1 485 */
448c38bd
DK
486 void TransactionStageCopy(pkgAcqTransactionItem * const I,
487 const std::string &From,
fa3a96a1 488 const std::string &To);
dce45dbe 489 /** \brief Stage (queue) a removal action when the transaction is committed
fa3a96a1 490 */
448c38bd 491 void TransactionStageRemoval(pkgAcqTransactionItem * const I, const std::string &FinalFile);
fa3a96a1 492
6bf93605 493 /** \brief Get the full pathname of the final file for the current URI */
3b302846 494 virtual std::string GetFinalFilename() const APT_OVERRIDE;
6bf93605 495
3d8232bf 496 pkgAcqMetaBase(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
e8afd168 497 std::vector<IndexTarget> const &IndexTargets,
3d8232bf 498 IndexTarget const &DataTarget);
c8a4ce6c 499 virtual ~pkgAcqMetaBase();
e6e89390 500};
dce45dbe 501 /*}}}*/
56472095
MV
502/** \brief An item that is responsible for downloading the meta-index {{{
503 * file (i.e., Release) itself and verifying its signature.
504 *
505 * Once the download and verification are complete, the downloads of
506 * the individual index files are queued up using pkgAcqDiffIndex.
507 * If the meta-index file had a valid signature, the expected hashsums
508 * of the index files will be the md5sums listed in the meta-index;
509 * otherwise, the expected hashsums will be "" (causing the
510 * authentication of the index files to be bypassed).
511 */
dce45dbe 512class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase
56472095 513{
6c55f07a 514 void * const d;
56472095 515 protected:
448c38bd 516 IndexTarget const DetachedSigTarget;
e05672e8
MV
517
518 /** \brief delayed constructor */
448c38bd
DK
519 void Init(std::string const &URIDesc, std::string const &ShortDesc);
520
56472095 521 public:
3b302846 522 virtual std::string DescURI() const APT_OVERRIDE;
631a7dc7 523
56472095 524 // Specialized action members
3b302846 525 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 526 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846 527 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
56472095
MV
528
529 /** \brief Create a new pkgAcqMetaIndex. */
3d8232bf 530 pkgAcqMetaIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
448c38bd 531 IndexTarget const &DataTarget, IndexTarget const &DetachedSigTarget,
3d8232bf 532 std::vector<IndexTarget> const &IndexTargets);
c8a4ce6c 533 virtual ~pkgAcqMetaIndex();
6bf93605
DK
534
535 friend class pkgAcqMetaSig;
536};
537 /*}}}*/
538/** \brief An acquire item that downloads the detached signature {{{
539 * of a meta-index (Release) file, then queues up the release
540 * file itself.
541 *
542 * \todo Why protected members?
543 *
544 * \sa pkgAcqMetaIndex
545 */
448c38bd 546class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem
6bf93605 547{
6c55f07a 548 void * const d;
6bf93605
DK
549
550 pkgAcqMetaIndex * const MetaIndex;
551
552 /** \brief The file we use to verify the MetaIndexFile with (not always set!) */
553 std::string MetaIndexFileSignature;
554
555 protected:
556
6bf93605 557 /** \brief Get the full pathname of the final file for the current URI */
3b302846 558 virtual std::string GetFinalFilename() const APT_OVERRIDE;
6bf93605
DK
559
560 public:
3b302846 561 virtual bool HashesRequired() const APT_OVERRIDE { return false; }
6bf93605
DK
562
563 // Specialized action members
3b302846 564 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 565 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846
DK
566 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
567 virtual std::string Custom600Headers() const APT_OVERRIDE;
6bf93605
DK
568
569 /** \brief Create a new pkgAcqMetaSig. */
3d8232bf
DK
570 pkgAcqMetaSig(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
571 IndexTarget const &Target, pkgAcqMetaIndex * const MetaIndex);
6bf93605 572 virtual ~pkgAcqMetaSig();
56472095
MV
573};
574 /*}}}*/
575/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
dce45dbe 576class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex
56472095 577{
6c55f07a 578 void * const d;
60323ed7 579
448c38bd
DK
580 IndexTarget const ClearsignedTarget;
581 IndexTarget const DetachedDataTarget;
56472095 582
3d8232bf
DK
583 public:
584 /** \brief A package-system-specific parser for the meta-index file. */
5ad0096a
DK
585 metaIndex *MetaIndexParser;
586 metaIndex *LastMetaIndexParser;
3d8232bf 587
3b302846
DK
588 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
589 virtual std::string Custom600Headers() const APT_OVERRIDE;
dd676dc7 590 virtual bool VerifyDone(std::string const &Message, pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 591 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846 592 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
57f16d51 593 virtual void Finished() APT_OVERRIDE;
56472095
MV
594
595 /** \brief Create a new pkgAcqMetaClearSig. */
448c38bd
DK
596 pkgAcqMetaClearSig(pkgAcquire * const Owner,
597 IndexTarget const &ClearsignedTarget,
598 IndexTarget const &DetachedDataTarget,
599 IndexTarget const &DetachedSigTarget,
e8afd168 600 std::vector<IndexTarget> const &IndexTargets,
5ad0096a 601 metaIndex * const MetaIndexParser);
56472095
MV
602 virtual ~pkgAcqMetaClearSig();
603};
604 /*}}}*/
448c38bd
DK
605/** \brief Common base class for all classes that deal with fetching indexes {{{*/
606class APT_HIDDEN pkgAcqBaseIndex : public pkgAcqTransactionItem
c2184314 607{
6c55f07a 608 void * const d;
60323ed7 609
448c38bd 610 public:
295d848b 611 /** \brief Get the full pathname of the final file for the current URI */
3b302846 612 virtual std::string GetFinalFilename() const APT_OVERRIDE;
0340069c 613 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
295d848b 614
3d8232bf 615 pkgAcqBaseIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
e8afd168 616 IndexTarget const &Target);
c8a4ce6c 617 virtual ~pkgAcqBaseIndex();
c2184314 618};
0b58b3f8 619 /*}}}*/
92fcbfc1 620/** \brief An item that is responsible for fetching an index file of {{{
3174e150
MV
621 * package list diffs and starting the package list's download.
622 *
623 * This item downloads the Index file and parses it, then enqueues
624 * additional downloads of either the individual patches (using
625 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
626 *
627 * \sa pkgAcqIndexDiffs, pkgAcqIndex
628 */
dce45dbe 629class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqBaseIndex
2237bd01 630{
6c55f07a 631 void * const d;
3d8232bf 632 std::vector<pkgAcqIndexMergeDiffs*> * diffs;
60323ed7 633
2237bd01 634 protected:
3174e150 635 /** \brief If \b true, debugging information will be written to std::clog. */
2237bd01 636 bool Debug;
3174e150 637
3174e150
MV
638 /** \brief A description of the Packages file (stored in
639 * pkgAcquire::ItemDesc::Description).
640 */
472ff00e 641 std::string Description;
2237bd01 642
295d848b 643 /** \brief Get the full pathname of the final file for the current URI */
3b302846 644 virtual std::string GetFinalFilename() const APT_OVERRIDE;
295d848b 645
3b302846 646 virtual bool QueueURI(pkgAcquire::ItemDesc &Item) APT_OVERRIDE;
146f7715 647
3b302846 648 virtual bool TransactionState(TransactionStates const state) APT_OVERRIDE;
2237bd01
MV
649 public:
650 // Specialized action members
3b302846 651 virtual void Failed(std::string const &Message, pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 652 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846
DK
653 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
654 virtual std::string DescURI() const APT_OVERRIDE {return Target.URI + "Index";};
655 virtual std::string Custom600Headers() const APT_OVERRIDE;
656 virtual std::string GetMetaKey() const APT_OVERRIDE;
2237bd01 657
3174e150
MV
658 /** \brief Parse the Index file for a set of Packages diffs.
659 *
660 * Parses the Index file and creates additional download items as
661 * necessary.
662 *
663 * \param IndexDiffFile The name of the Index file.
664 *
665 * \return \b true if the Index file was successfully parsed, \b
666 * false otherwise.
667 */
448c38bd 668 bool ParseDiffIndex(std::string const &IndexDiffFile);
3174e150
MV
669
670 /** \brief Create a new pkgAcqDiffIndex.
671 *
672 * \param Owner The Acquire object that owns this item.
673 *
674 * \param URI The URI of the list file to download.
675 *
676 * \param URIDesc A long description of the list file to download.
677 *
678 * \param ShortDesc A short description of the list file to download.
3174e150 679 */
3d8232bf 680 pkgAcqDiffIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
e8afd168 681 IndexTarget const &Target);
c8a4ce6c 682 virtual ~pkgAcqDiffIndex();
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{
6c55f07a 714 void * const d;
60323ed7 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 */
3b302846 754 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 755 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846
DK
756 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
757 virtual std::string Custom600Headers() const APT_OVERRIDE;
758 virtual std::string DescURI() const APT_OVERRIDE {return Target.URI + "Index";};
759 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
760 virtual bool HashesRequired() const APT_OVERRIDE;
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 */
3d8232bf 779 pkgAcqIndexMergeDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
e8afd168 780 IndexTarget const &Target, DiffInfo const &patch,
c2184314 781 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
c8a4ce6c 782 virtual ~pkgAcqIndexMergeDiffs();
47d2bc78
DK
783};
784 /*}}}*/
785/** \brief An item that is responsible for fetching server-merge patches {{{
3174e150
MV
786 * that need to be applied to a given package index file.
787 *
788 * After downloading and applying a single patch, this item will
789 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
790 * patches. If no patch can be found that applies to an intermediate
791 * file or if one of the patches cannot be downloaded, falls back to
792 * downloading the entire package index file using pkgAcqIndex.
793 *
794 * \sa pkgAcqDiffIndex, pkgAcqIndex
795 */
dce45dbe 796class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex
ac5b205a 797{
6c55f07a 798 void * const d;
60323ed7 799
3174e150
MV
800 private:
801
802 /** \brief Queue up the next diff download.
803 *
804 * Search for the next available diff that applies to the file
805 * that currently exists on disk, and enqueue it by calling
806 * QueueURI().
807 *
808 * \return \b true if an applicable diff was found, \b false
809 * otherwise.
810 */
3809194b 811 APT_HIDDEN bool QueueNextDiff();
3174e150
MV
812
813 /** \brief Handle tasks that must be performed after the item
814 * finishes downloading.
815 *
b3501edb
DK
816 * Dequeues the item and checks the resulting file's hashsums
817 * against ExpectedHashes after the last patch was applied.
3174e150
MV
818 * There is no need to check the md5/sha1 after a "normal"
819 * patch because QueueNextDiff() will check the sha1 later.
820 *
821 * \param allDone If \b true, the file was entirely reconstructed,
822 * and its md5sum is verified.
823 */
448c38bd 824 APT_HIDDEN void Finish(bool const allDone=false);
3174e150 825
ac5b205a 826 protected:
3174e150
MV
827
828 /** \brief If \b true, debugging output will be written to
829 * std::clog.
830 */
ac5b205a 831 bool Debug;
3174e150 832
3174e150 833 /** A description of the file being downloaded. */
472ff00e 834 std::string Description;
3174e150
MV
835
836 /** The patches that remain to be downloaded, including the patch
837 * being downloaded right now. This list should be ordered so
838 * that each diff appears before any diff that depends on it.
839 *
840 * \todo These are indexed by sha1sum; why not use some sort of
841 * dictionary instead of relying on ordering and stripping them
842 * off the front?
843 */
472ff00e 844 std::vector<DiffInfo> available_patches;
8a3207f4 845
3174e150
MV
846 /** The current status of this patch. */
847 enum DiffState
4e3c5633 848 {
3174e150
MV
849 /** \brief The diff is currently being fetched. */
850 StateFetchDiff,
3174e150
MV
851
852 /** \brief The diff is currently being applied. */
853 StateApplyDiff
854 } State;
6cb30d01 855
ac5b205a 856 public:
448c38bd 857
3174e150
MV
858 /** \brief Called when the patch file failed to be downloaded.
859 *
860 * This method will fall back to downloading the whole index file
861 * outright; its arguments are ignored.
862 */
3b302846 863 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
3174e150 864
448c38bd 865 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846
DK
866 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
867 virtual std::string Custom600Headers() const APT_OVERRIDE;
868 virtual std::string DescURI() const APT_OVERRIDE {return Target.URI + "IndexDiffs";};
869 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
870 virtual bool HashesRequired() const APT_OVERRIDE;
ac5b205a 871
3174e150
MV
872 /** \brief Create an index diff item.
873 *
874 * After filling in its basic fields, this invokes Finish(true) if
255c9e4b 875 * \a diffs is empty, or QueueNextDiff() otherwise.
3174e150
MV
876 *
877 * \param Owner The pkgAcquire object that owns this item.
878 *
879 * \param URI The URI of the package index file being
880 * reconstructed.
881 *
882 * \param URIDesc A long description of this item.
883 *
884 * \param ShortDesc A brief description of this item.
885 *
3174e150
MV
886 * \param diffs The remaining diffs from the index of diffs. They
887 * should be ordered so that each diff appears before any diff
888 * that depends on it.
889 */
3d8232bf 890 pkgAcqIndexDiffs(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
e8afd168 891 IndexTarget const &Target,
448c38bd 892 std::vector<DiffInfo> const &diffs=std::vector<DiffInfo>());
c8a4ce6c 893 virtual ~pkgAcqIndexDiffs();
ac5b205a 894};
92fcbfc1
DK
895 /*}}}*/
896/** \brief An acquire item that is responsible for fetching an index {{{
3174e150
MV
897 * file (e.g., Packages or Sources).
898 *
899 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
900 *
901 * \todo Why does pkgAcqIndex have protected members?
902 */
dce45dbe 903class APT_HIDDEN pkgAcqIndex : public pkgAcqBaseIndex
0118833a 904{
6c55f07a 905 void * const d;
60323ed7 906
0118833a 907 protected:
3174e150 908
651bddad
MV
909 /** \brief The stages the method goes through
910 *
911 * The method first downloads the indexfile, then its decompressed (or
912 * copied) and verified
3174e150 913 */
651bddad
MV
914 enum AllStages {
915 STAGE_DOWNLOAD,
916 STAGE_DECOMPRESS_AND_VERIFY,
917 };
918 AllStages Stage;
3174e150 919
651bddad 920 /** \brief Handle what needs to be done when the download is done */
0179cfa8 921 void StageDownloadDone(std::string const &Message);
651bddad
MV
922
923 /** \brief Handle what needs to be done when the decompression/copy is
924 * done
3174e150 925 */
0179cfa8 926 void StageDecompressDone();
3174e150 927
1e8ba0d4
MV
928 /** \brief If \b set, this partially downloaded file will be
929 * removed when the download completes.
930 */
931 std::string EraseFileName;
932
5d885723
DK
933 /** \brief The compression-related file extensions that are being
934 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
3174e150 935 */
651bddad
MV
936 std::string CompressionExtensions;
937
938 /** \brief The actual compression extension currently used */
1e8ba0d4 939 std::string CurrentCompressionExtension;
13e8426f 940
59194959 941 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
448c38bd 942 void InitByHashIfNeeded();
59194959 943
295d848b 944 /** \brief Get the full pathname of the final file for the current URI */
3b302846 945 virtual std::string GetFinalFilename() const APT_OVERRIDE;
295d848b 946
3b302846 947 virtual bool TransactionState(TransactionStates const state) APT_OVERRIDE;
146f7715 948
0118833a 949 public:
17caf1b1 950 // Specialized action members
3b302846 951 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 952 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846
DK
953 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
954 virtual std::string Custom600Headers() const APT_OVERRIDE;
955 virtual std::string DescURI() const APT_OVERRIDE {return Desc.URI;};
956 virtual std::string GetMetaKey() const APT_OVERRIDE;
448c38bd 957
3d8232bf 958 pkgAcqIndex(pkgAcquire * const Owner, pkgAcqMetaClearSig * const TransactionManager,
e8afd168 959 IndexTarget const &Target);
c8a4ce6c 960 virtual ~pkgAcqIndex();
0118833a 961
c8a4ce6c
DK
962 private:
963 APT_HIDDEN void Init(std::string const &URI, std::string const &URIDesc,
0b58b3f8 964 std::string const &ShortDesc);
0118833a 965};
92fcbfc1 966 /*}}}*/
92fcbfc1 967/** \brief An item that is responsible for fetching a package file. {{{
3174e150
MV
968 *
969 * If the package file already exists in the cache, nothing will be
970 * done.
971 */
03e39e59
AL
972class pkgAcqArchive : public pkgAcquire::Item
973{
6c55f07a 974 void * const d;
60323ed7 975
448c38bd
DK
976 bool LocalSource;
977 HashStringList ExpectedHashes;
978
03e39e59 979 protected:
3174e150 980 /** \brief The package version being fetched. */
03e39e59 981 pkgCache::VerIterator Version;
3174e150 982
3174e150
MV
983 /** \brief The list of sources from which to pick archives to
984 * download this package from.
985 */
03e39e59 986 pkgSourceList *Sources;
3174e150
MV
987
988 /** \brief A package records object, used to look up the file
989 * corresponding to each version of the package.
990 */
03e39e59 991 pkgRecords *Recs;
3174e150 992
3174e150
MV
993 /** \brief A location in which the actual filename of the package
994 * should be stored.
995 */
472ff00e 996 std::string &StoreFilename;
3174e150
MV
997
998 /** \brief The next file for this version to try to download. */
b185acc2 999 pkgCache::VerFileIterator Vf;
3174e150
MV
1000
1001 /** \brief How many (more) times to try to find a new source from
1002 * which to download this package version if it fails.
1003 *
1004 * Set from Acquire::Retries.
1005 */
7d8afa39 1006 unsigned int Retries;
3174e150
MV
1007
1008 /** \brief \b true if this version file is being downloaded from a
1009 * trusted source.
1010 */
448c38bd 1011 bool Trusted;
17caf1b1 1012
3174e150 1013 /** \brief Queue up the next available file for this version. */
b185acc2 1014 bool QueueNext();
295d848b
DK
1015
1016 /** \brief Get the full pathname of the final file for the current URI */
3b302846 1017 virtual std::string GetFinalFilename() const APT_OVERRIDE;
295d848b 1018
03e39e59 1019 public:
295d848b 1020
3b302846 1021 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 1022 virtual void Done(std::string const &Message, HashStringList const &Hashes,
3b302846
DK
1023 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1024 virtual std::string DescURI() const APT_OVERRIDE;
1025 virtual std::string ShortDesc() const APT_OVERRIDE;
1026 virtual void Finished() APT_OVERRIDE;
1027 virtual bool IsTrusted() const APT_OVERRIDE;
1028 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
1029 virtual bool HashesRequired() const APT_OVERRIDE;
02e20767 1030
3174e150
MV
1031 /** \brief Create a new pkgAcqArchive.
1032 *
1033 * \param Owner The pkgAcquire object with which this item is
1034 * associated.
1035 *
1036 * \param Sources The sources from which to download version
1037 * files.
1038 *
1039 * \param Recs A package records object, used to look up the file
1040 * corresponding to each version of the package.
1041 *
1042 * \param Version The package version to download.
1043 *
3c8030a4 1044 * \param[out] StoreFilename A location in which the actual filename of
3174e150
MV
1045 * the package should be stored. It will be set to a guessed
1046 * basename in the constructor, and filled in with a fully
1047 * qualified filename once the download finishes.
1048 */
448c38bd
DK
1049 pkgAcqArchive(pkgAcquire * const Owner,pkgSourceList * const Sources,
1050 pkgRecords * const Recs,pkgCache::VerIterator const &Version,
472ff00e 1051 std::string &StoreFilename);
c8a4ce6c 1052 virtual ~pkgAcqArchive();
03e39e59 1053};
92fcbfc1 1054 /*}}}*/
d56e2917
DK
1055/** \brief Retrieve the changelog for the given version {{{
1056 *
1057 * Downloads the changelog to a temporary file it will also remove again
1058 * while it is deconstructed or downloads it to a named location.
1059 */
1060class pkgAcqChangelog : public pkgAcquire::Item
1061{
6fd4b4c0
DK
1062 class Private;
1063 Private * const d;
d56e2917
DK
1064 std::string TemporaryDirectory;
1065 std::string const SrcName;
1066 std::string const SrcVersion;
1067
1068 public:
1069 // we will never have hashes for changelogs.
1070 // If you need verified ones, download the deb and extract the changelog.
3b302846
DK
1071 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE { return HashStringList(); }
1072 virtual bool HashesRequired() const APT_OVERRIDE { return false; }
d56e2917
DK
1073
1074 // Specialized action members
3b302846 1075 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
d56e2917 1076 virtual void Done(std::string const &Message, HashStringList const &CalcHashes,
3b302846
DK
1077 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1078 virtual std::string DescURI() const APT_OVERRIDE {return Desc.URI;};
d56e2917
DK
1079
1080 /** returns the URI to the changelog of this version
1081 *
1082 * @param Ver is the version to get the changelog for
1083 * @return the URI which will be used to acquire the changelog
1084 */
1085 static std::string URI(pkgCache::VerIterator const &Ver);
1086
1087 /** returns the URI to the changelog of this version
1088 *
1089 * \param Rls is the Release file the package comes from
1090 * \param Component in which the package resides, can be empty
1091 * \param SrcName is the source package name
1092 * \param SrcVersion is the source package version
1093 * @return the URI which will be used to acquire the changelog
1094 */
1095 static std::string URI(pkgCache::RlsFileIterator const &Rls,
1096 char const * const Component, char const * const SrcName,
1097 char const * const SrcVersion);
1098
1099 /** returns the URI to the changelog of this version
1100 *
430481e7 1101 * \param Template URI where @CHANGEPATH@ has to be filled in
d56e2917
DK
1102 * \param Component in which the package resides, can be empty
1103 * \param SrcName is the source package name
1104 * \param SrcVersion is the source package version
1105 * @return the URI which will be used to acquire the changelog
1106 */
1107 static std::string URI(std::string const &Template,
1108 char const * const Component, char const * const SrcName,
1109 char const * const SrcVersion);
1110
1111 /** returns the URI template for this release file
1112 *
1113 * \param Rls is a Release file
1114 * @return the URI template to use for this release file
1115 */
1116 static std::string URITemplate(pkgCache::RlsFileIterator const &Rls);
1117
1118 /** \brief Create a new pkgAcqChangelog object.
1119 *
1120 * \param Owner The pkgAcquire object with which this object is
1121 * associated.
1122 * \param Ver is the version to get the changelog for
1123 * \param DestDir The directory the file should be downloaded into.
1124 * Will be an autocreated (and cleaned up) temporary directory if not set.
1125 * \param DestFilename The filename the file should have in #DestDir
1126 * Defaults to sourcepackagename.changelog if not set.
1127 */
1128 pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::VerIterator const &Ver,
1129 std::string const &DestDir="", std::string const &DestFilename="");
1130
1131 /** \brief Create a new pkgAcqChangelog object.
1132 *
1133 * \param Owner The pkgAcquire object with which this object is
1134 * associated.
1135 * \param Rls is the Release file the package comes from
1136 * \param Component in which the package resides, can be empty
1137 * \param SrcName is the source package name
1138 * \param SrcVersion is the source package version
1139 * \param DestDir The directory the file should be downloaded into.
1140 * Will be an autocreated (and cleaned up) temporary directory if not set.
1141 * \param DestFilename The filename the file should have in #DestDir
1142 * Defaults to sourcepackagename.changelog if not set.
1143 */
1144 pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::RlsFileIterator const &Rls,
1145 char const * const Component, char const * const SrcName, char const * const SrcVersion,
1146 std::string const &DestDir="", std::string const &DestFilename="");
1147
1148 /** \brief Create a new pkgAcqChangelog object.
1149 *
1150 * \param Owner The pkgAcquire object with which this object is
1151 * associated.
1152 * \param URI is to be used to get the changelog
1153 * \param SrcName is the source package name
1154 * \param SrcVersion is the source package version
1155 * \param DestDir The directory the file should be downloaded into.
1156 * Will be an autocreated (and cleaned up) temporary directory if not set.
1157 * \param DestFilename The filename the file should have in #DestDir
1158 * Defaults to sourcepackagename.changelog if not set.
1159 */
1160 pkgAcqChangelog(pkgAcquire * const Owner, std::string const &URI,
1161 char const * const SrcName, char const * const SrcVersion,
1162 std::string const &DestDir="", std::string const &DestFilename="");
1163
1164 virtual ~pkgAcqChangelog();
1165
1166private:
1167 APT_HIDDEN void Init(std::string const &DestDir, std::string const &DestFilename);
1168};
1169 /*}}}*/
92fcbfc1 1170/** \brief Retrieve an arbitrary file to the current directory. {{{
3174e150
MV
1171 *
1172 * The file is retrieved even if it is accessed via a URL type that
1173 * normally is a NOP, such as "file". If the download fails, the
1174 * partial file is renamed to get a ".FAILED" extension.
1175 */
36375005
AL
1176class pkgAcqFile : public pkgAcquire::Item
1177{
6c55f07a 1178 void * const d;
60323ed7 1179
3174e150
MV
1180 /** \brief How many times to retry the download, set from
1181 * Acquire::Retries.
1182 */
08cfc005 1183 unsigned int Retries;
448c38bd 1184
77278c2b
MV
1185 /** \brief Should this file be considered a index file */
1186 bool IsIndexFile;
1187
448c38bd 1188 HashStringList const ExpectedHashes;
36375005 1189 public:
3b302846
DK
1190 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE;
1191 virtual bool HashesRequired() const APT_OVERRIDE;
448c38bd 1192
36375005 1193 // Specialized action members
3b302846 1194 virtual void Failed(std::string const &Message,pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
448c38bd 1195 virtual void Done(std::string const &Message, HashStringList const &CalcHashes,
3b302846
DK
1196 pkgAcquire::MethodConfig const * const Cnf) APT_OVERRIDE;
1197 virtual std::string DescURI() const APT_OVERRIDE {return Desc.URI;};
1198 virtual std::string Custom600Headers() const APT_OVERRIDE;
3174e150
MV
1199
1200 /** \brief Create a new pkgAcqFile object.
1201 *
1202 * \param Owner The pkgAcquire object with which this object is
1203 * associated.
1204 *
1205 * \param URI The URI to download.
1206 *
b3501edb
DK
1207 * \param Hashes The hashsums of the file to download, if they are known;
1208 * otherwise empty list.
3174e150
MV
1209 *
1210 * \param Size The size of the file to download, if it is known;
1211 * otherwise 0.
1212 *
1213 * \param Desc A description of the file being downloaded.
1214 *
1215 * \param ShortDesc A brief description of the file being
1216 * downloaded.
39c7baef
MV
1217 *
1218 * \param DestDir The directory the file should be downloaded into.
1219 *
1220 * \param DestFilename The filename+path the file is downloaded to.
1221 *
77278c2b
MV
1222 * \param IsIndexFile The file is considered a IndexFile and cache-control
1223 * headers like "cache-control: max-age=0" are send
39c7baef 1224 *
255c9e4b
DK
1225 * If DestFilename is empty, download to DestDir/\<basename\> if
1226 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
39c7baef
MV
1227 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1228 * is the absolute name to which the file should be downloaded.
3174e150 1229 */
39c7baef 1230
448c38bd
DK
1231 pkgAcqFile(pkgAcquire * const Owner, std::string const &URI, HashStringList const &Hashes, unsigned long long const Size,
1232 std::string const &Desc, std::string const &ShortDesc,
1233 std::string const &DestDir="", std::string const &DestFilename="",
1234 bool const IsIndexFile=false);
c8a4ce6c 1235 virtual ~pkgAcqFile();
36375005 1236};
92fcbfc1 1237 /*}}}*/
3174e150
MV
1238/** @} */
1239
0118833a 1240#endif