X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/afd7b358f94efddb83a2911ec1a21e7280074b1e..a473295d01ed9c599926d9a8c212d4e1a404f78b:/apt-pkg/acquire.h diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index ae555df22..1fae662f8 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -1,11 +1,10 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire.h,v 1.29.2.1 2003/12/24 23:09:17 mdz Exp $ /* ###################################################################### Acquire - File Acquiration - This module contians the Acquire system. It is responsible for bringing + This module contains the Acquire system. It is responsible for bringing files into the local pathname space. It deals with URIs for files and URI handlers responsible for downloading or finding the URIs. @@ -68,16 +67,23 @@ #include #include +#include -#include #include +#include -using std::vector; -using std::string; - - +#include #include +#include + +#ifndef APT_10_CLEANER_HEADERS #include +#endif + +#ifndef APT_8_CLEANER_HEADERS +using std::vector; +using std::string; +#endif class pkgAcquireStatus; @@ -95,7 +101,7 @@ class pkgAcquire /** \brief FD of the Lock file we acquire in Setup (if any) */ int LockFD; /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; public: @@ -105,10 +111,11 @@ class pkgAcquire struct MethodConfig; struct ItemDesc; friend class Item; + friend class pkgAcqMetaBase; friend class Queue; - typedef vector::iterator ItemIterator; - typedef vector::const_iterator ItemCIterator; + typedef std::vector::iterator ItemIterator; + typedef std::vector::const_iterator ItemCIterator; protected: @@ -117,7 +124,7 @@ class pkgAcquire * This is built monotonically as items are created and only * emptied when the download shuts down. */ - vector Items; + std::vector Items; /** \brief The head of the list of active queues. * @@ -202,7 +209,7 @@ class pkgAcquire * \return the string-name of the queue in which a fetch request * for the given URI should be placed. */ - string QueueName(string URI,MethodConfig const *&Config); + std::string QueueName(std::string URI,MethodConfig const *&Config); /** \brief Build up the set of file descriptors upon which select() should * block. @@ -229,8 +236,15 @@ class pkgAcquire * * \param WSet The set of file descriptors that are ready for * output. + * + * \return false if there is an error condition on one of the fds */ - virtual void RunFds(fd_set *RSet,fd_set *WSet); + bool RunFdsSane(fd_set *RSet,fd_set *WSet); + + // just here for compatbility, needs to be removed on the next + // ABI/API break. RunFdsSane() is what should be used as it + // returns if there is an error condition on one of the fds + virtual void RunFds(fd_set *RSet,fd_set *WSet); /** \brief Check for idle queues with ready-to-fetch items. * @@ -248,7 +262,7 @@ class pkgAcquire * * \return the method whose name is Access, or \b NULL if no such method exists. */ - MethodConfig *GetConfig(string Access); + MethodConfig *GetConfig(std::string Access); /** \brief Provides information on how a download terminated. */ enum RunResult { @@ -281,24 +295,26 @@ class pkgAcquire */ void Shutdown(); - /** \brief Get the first #Worker object. + /** \brief Get the first Worker object. * * \return the first active worker in this download process. */ inline Worker *WorkersBegin() {return Workers;}; - /** \brief Advance to the next #Worker object. + /** \brief Advance to the next Worker object. * * \return the worker immediately following I, or \b NULL if none * exists. */ - Worker *WorkerStep(Worker *I); + Worker *WorkerStep(Worker *I) APT_PURE; /** \brief Get the head of the list of items. */ inline ItemIterator ItemsBegin() {return Items.begin();}; + inline ItemCIterator ItemsBegin() const {return Items.begin();}; /** \brief Get the end iterator of the list of items. */ inline ItemIterator ItemsEnd() {return Items.end();}; + inline ItemCIterator ItemsEnd() const {return Items.end();}; // Iterate over queued Item URIs class UriIterator; @@ -319,7 +335,7 @@ class pkgAcquire * * \return \b true if the directory exists and is readable. */ - bool Clean(string Dir); + bool Clean(std::string Dir); /** \return the total size in bytes of all the items included in * this download. @@ -345,14 +361,24 @@ class pkgAcquire * long as the pkgAcquire object does. * \param Lock defines a lock file that should be acquired to ensure * only one Acquire class is in action at the time or an empty string - * if no lock file should be used. + * if no lock file should be used. If set also all needed directories + * will be created. */ - bool Setup(pkgAcquireStatus *Progress = NULL, string const &Lock = ""); + APT_DEPRECATED_MSG("Use constructors, .SetLog and .GetLock as needed") bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = ""); void SetLog(pkgAcquireStatus *Progress) { Log = Progress; } + /** \brief acquire lock and perform directory setup + * + * \param Lock defines a lock file that should be acquired to ensure + * only one Acquire class is in action at the time or an empty string + * if no lock file should be used. If set also all needed directories + * will be created and setup. + */ + bool GetLock(std::string const &Lock); + /** \brief Construct a new pkgAcquire. */ - pkgAcquire(pkgAcquireStatus *Log) __deprecated; + explicit pkgAcquire(pkgAcquireStatus *Log); pkgAcquire(); /** \brief Destroy this pkgAcquire object. @@ -362,6 +388,8 @@ class pkgAcquire */ virtual ~pkgAcquire(); + private: + APT_HIDDEN void Initialize(); }; /** \brief Represents a single download source from which an item @@ -371,13 +399,13 @@ class pkgAcquire */ struct pkgAcquire::ItemDesc : public WeakPointable { - /** \brief The URI from which to download this item. */ - string URI; - /** brief A description of this item. */ - string Description; - /** brief A shorter description of this item. */ - string ShortDesc; - /** brief The underlying item which is to be downloaded. */ + /** \brief URI from which to download this item. */ + std::string URI; + /** \brief description of this item. */ + std::string Description; + /** \brief shorter description of this item. */ + std::string ShortDesc; + /** \brief underlying item which is to be downloaded. */ Item *Owner; }; /*}}}*/ @@ -392,7 +420,7 @@ class pkgAcquire::Queue friend class pkgAcquire::Worker; /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; /** \brief The next queue in the pkgAcquire object's list of queues. */ Queue *Next; @@ -400,13 +428,18 @@ class pkgAcquire::Queue protected: /** \brief A single item placed in this queue. */ - struct QItem : pkgAcquire::ItemDesc + struct QItem : public ItemDesc { /** \brief The next item in the queue. */ QItem *Next; /** \brief The worker associated with this item, if any. */ pkgAcquire::Worker *Worker; + /** \brief The underlying items interested in the download */ + std::vector Owners; + + typedef std::vector::const_iterator owner_iterator; + /** \brief Assign the ItemDesc portion of this QItem from * another ItemDesc */ @@ -415,12 +448,28 @@ class pkgAcquire::Queue URI = I.URI; Description = I.Description; ShortDesc = I.ShortDesc; + Owners.clear(); + Owners.push_back(I.Owner); Owner = I.Owner; }; + + /** @return the sum of all expected hashes by all owners */ + HashStringList GetExpectedHashes() const; + + /** @return smallest maximum size of all owners */ + unsigned long long GetMaximumSize() const; + + /** \brief get partial files in order */ + void SyncDestinationFiles() const; + + /** @return the custom headers to use for this item */ + std::string Custom600Headers() const; + /** @return the maximum priority of this item */ + int APT_HIDDEN GetPriority() const; }; - + /** \brief The name of this queue. */ - string Name; + std::string Name; /** \brief The head of the list of items contained in this queue. * @@ -475,7 +524,7 @@ class pkgAcquire::Queue * \return the first item in the queue whose URI is #URI and that * is being downloaded by #Owner. */ - QItem *FindItem(string URI,pkgAcquire::Worker *Owner); + QItem *FindItem(std::string URI,pkgAcquire::Worker *Owner) APT_PURE; /** Presumably this should start downloading an item? * @@ -538,7 +587,7 @@ class pkgAcquire::Queue * \param Name The name of the new queue. * \param Owner The download process that owns the new queue. */ - Queue(string Name,pkgAcquire *Owner); + Queue(std::string const &Name,pkgAcquire * const Owner); /** Shut down all the worker processes associated with this queue * and empty the queue. @@ -550,7 +599,7 @@ class pkgAcquire::Queue class pkgAcquire::UriIterator { /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; /** The next queue to iterate over. */ pkgAcquire::Queue *CurQ; @@ -571,7 +620,7 @@ class pkgAcquire::UriIterator } }; - inline pkgAcquire::ItemDesc const *operator ->() const {return CurItem;}; + inline pkgAcquire::Queue::QItem const *operator ->() const {return CurItem;}; inline bool operator !=(UriIterator const &rhs) const {return rhs.CurQ != CurQ || rhs.CurItem != CurItem;}; inline bool operator ==(UriIterator const &rhs) const {return rhs.CurQ == CurQ && rhs.CurItem == CurItem;}; @@ -579,22 +628,15 @@ class pkgAcquire::UriIterator * * \param Q The queue over which this UriIterator should iterate. */ - UriIterator(pkgAcquire::Queue *Q) : CurQ(Q), CurItem(0) - { - while (CurItem == 0 && CurQ != 0) - { - CurItem = CurQ->Items; - CurQ = CurQ->Next; - } - } - virtual ~UriIterator() {}; + explicit UriIterator(pkgAcquire::Queue *Q); + virtual ~UriIterator(); }; /*}}}*/ /** \brief Information about the properties of a single acquire method. {{{*/ struct pkgAcquire::MethodConfig { /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; /** \brief The next link on the acquire method list. * @@ -603,10 +645,10 @@ struct pkgAcquire::MethodConfig MethodConfig *Next; /** \brief The name of this acquire method (e.g., http). */ - string Access; + std::string Access; /** \brief The implementation version of this acquire method. */ - string Version; + std::string Version; /** \brief If \b true, only one download queue should be created for this * method. @@ -645,8 +687,7 @@ struct pkgAcquire::MethodConfig */ MethodConfig(); - /* \brief Destructor, empty currently */ - virtual ~MethodConfig() {}; + virtual ~MethodConfig(); }; /*}}}*/ /** \brief A monitor object for downloads controlled by the pkgAcquire class. {{{ @@ -656,7 +697,7 @@ struct pkgAcquire::MethodConfig class pkgAcquireStatus { /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; protected: @@ -708,6 +749,10 @@ class pkgAcquireStatus /** \brief The number of items that have been successfully downloaded. */ unsigned long CurrentItems; + /** \brief The estimated percentage of the download (0-100) + */ + double Percent; + public: /** \brief If \b true, the download scheduler should call Pulse() @@ -748,7 +793,7 @@ class pkgAcquireStatus * \todo This is a horrible blocking monster; it should be CPSed * with prejudice. */ - virtual bool MediaChange(string Media,string Drive) = 0; + virtual bool MediaChange(std::string Media,std::string Drive) = 0; /** \brief Invoked when an item is confirmed to be up-to-date. @@ -788,7 +833,7 @@ class pkgAcquireStatus /** \brief Initialize all counters to 0 and the time to the current time. */ pkgAcquireStatus(); - virtual ~pkgAcquireStatus() {}; + virtual ~pkgAcquireStatus(); }; /*}}}*/ /** @} */