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