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