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