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