From 1dca8dc55c1fcf4bda07a7e8285de7f225448697 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 16 Apr 2014 15:28:23 +0200 Subject: [PATCH] load the size from the metaindex into the fetcher to have even more accurate progress information --- apt-pkg/acquire-item.cc | 15 ++++++++++++--- apt-pkg/acquire-item.h | 4 ++-- apt-pkg/acquire.cc | 5 ++++- apt-pkg/indexrecords.cc | 2 +- apt-pkg/indexrecords.h | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 6f6b3d59f..d5f8b0cc9 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -936,7 +936,7 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, Init(URI, URIDesc, ShortDesc); } pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target, - HashString const &ExpectedHash, indexRecords const *MetaIndexParser) + HashString const &ExpectedHash, indexRecords *MetaIndexParser) : Item(Owner), RealURI(Target->URI), ExpectedHash(ExpectedHash) { // autoselect the compression method @@ -963,6 +963,11 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target, else Verify = true; + // load the filesize + indexRecords::checkSum *Record = MetaIndexParser->Lookup(string(Target->MetaKey)); + if(Record) + FileSize = Record->Size; + Init(Target->URI, Target->Description, Target->ShortDesc); } /*}}}*/ @@ -1176,9 +1181,13 @@ pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, { } pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const *Target, - HashString const &ExpectedHash, indexRecords const *MetaIndexParser) + HashString const &ExpectedHash, indexRecords *MetaIndexParser) : pkgAcqIndex(Owner, Target, ExpectedHash, MetaIndexParser) { + // load the filesize + indexRecords::checkSum *Record = MetaIndexParser->Lookup(string(Target->MetaKey)); + if(Record) + FileSize = Record->Size; } /*}}}*/ // AcqIndexTrans::Custom600Headers - Insert custom request headers /*{{{*/ @@ -1575,7 +1584,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ ++Target) { HashString ExpectedIndexHash; - const indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey); + indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey); bool compressedAvailable = false; if (Record == NULL) { diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index c12d8d63a..bf5cb09c8 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -756,7 +756,7 @@ class pkgAcqIndex : public pkgAcquire::Item std::string ShortDesc, HashString ExpectedHash, std::string compressExt=""); pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target, - HashString const &ExpectedHash, indexRecords const *MetaIndexParser); + HashString const &ExpectedHash, indexRecords *MetaIndexParser); void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc); }; /*}}}*/ @@ -788,7 +788,7 @@ class pkgAcqIndexTrans : public pkgAcqIndex 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); + HashString const &ExpectedHash, indexRecords *MetaIndexParser); }; /*}}}*/ /** \brief Information about an index file. */ /*{{{*/ diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 2b427ccd3..9fc40752f 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -905,8 +905,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) // calculate the percentage, if we have too little data assume 0% + // FIXME: the 5k is totally arbitrary + // FIXME2: instead, use a algorithm where 50% is based on total bytes + // and the other 50% on total files int Percent; - if (TotalBytes < 1*1024) + if (TotalBytes < 5*1024) Percent = 0; else Percent = (CurrentBytes/float(TotalBytes)*100.0); diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 5353d1098..68ebdce08 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -53,7 +53,7 @@ APT_PURE time_t indexRecords::GetValidUntil() const return this->ValidUntil; } -APT_PURE const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) +APT_PURE indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) { std::map::const_iterator sum = Entries.find(MetaKey); if (sum == Entries.end()) diff --git a/apt-pkg/indexrecords.h b/apt-pkg/indexrecords.h index e31f889ad..2260a4ae1 100644 --- a/apt-pkg/indexrecords.h +++ b/apt-pkg/indexrecords.h @@ -41,7 +41,7 @@ class indexRecords indexRecords(const std::string ExpectedDist); // Lookup function - virtual const checkSum *Lookup(const std::string MetaKey); + virtual checkSum *Lookup(const std::string MetaKey); /** \brief tests if a checksum for this file is available */ bool Exists(std::string const &MetaKey) const; std::vector MetaKeys(); -- 2.45.2