From cccef6ca60c2775e918d964fdad1afc1dcad4d0e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 29 Apr 2019 20:05:38 +0200 Subject: acq: worker: Move CurrentSize, TotalSize, ResumePoint to CurrentItem These status fields belong to the current item, move them there. This prepares us for eventually having multiple current items. --- apt-pkg/acquire-worker.cc | 16 +++++++--------- apt-pkg/acquire-worker.h | 15 --------------- apt-pkg/acquire.cc | 6 +++--- apt-pkg/acquire.h | 15 +++++++++++++++ apt-private/acqprogress.cc | 14 +++++++------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index b36186121..8ebee5797 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -44,7 +44,7 @@ using namespace std; // Worker::Worker - Constructor for Queue startup /*{{{*/ pkgAcquire::Worker::Worker(Queue *Q, MethodConfig *Cnf, pkgAcquireStatus *log) : d(NULL), OwnerQ(Q), Log(log), Config(Cnf), Access(Cnf->Access), - CurrentItem(nullptr), CurrentSize(0), TotalSize(0) + CurrentItem(nullptr) { Construct(); } @@ -369,12 +369,12 @@ bool pkgAcquire::Worker::RunMessages() } CurrentItem = Itm; - CurrentSize = 0; - TotalSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10); - ResumePoint = strtoull(LookupTag(Message,"Resume-Point","0").c_str(), NULL, 10); + Itm->CurrentSize = 0; + Itm->TotalSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10); + Itm->ResumePoint = strtoull(LookupTag(Message,"Resume-Point","0").c_str(), NULL, 10); for (auto const Owner: Itm->Owners) { - Owner->Start(Message, TotalSize); + Owner->Start(Message, Itm->TotalSize); // Display update before completion if (Log != nullptr) { @@ -918,7 +918,7 @@ void pkgAcquire::Worker::Pulse() struct stat Buf; if (stat(CurrentItem->Owner->DestFile.c_str(),&Buf) != 0) return; - CurrentSize = Buf.st_size; + CurrentItem->CurrentSize = Buf.st_size; } /*}}}*/ // Worker::ItemDone - Called when the current item is finished /*{{{*/ @@ -926,9 +926,7 @@ void pkgAcquire::Worker::Pulse() /* */ void pkgAcquire::Worker::ItemDone() { - CurrentItem = 0; - CurrentSize = 0; - TotalSize = 0; + CurrentItem = nullptr; Status = string(); } /*}}}*/ diff --git a/apt-pkg/acquire-worker.h b/apt-pkg/acquire-worker.h index 11e54b060..b6d1628f9 100644 --- a/apt-pkg/acquire-worker.h +++ b/apt-pkg/acquire-worker.h @@ -251,21 +251,6 @@ class pkgAcquire::Worker : public WeakPointable */ std::string Status; - /** \brief How many bytes of the file have been downloaded. Zero - * if the current progress of the file cannot be determined. - */ - unsigned long long CurrentSize; - - /** \brief The total number of bytes to be downloaded. Zero if the - * total size of the final is unknown. - */ - unsigned long long TotalSize; - - /** \brief How much of the file was already downloaded prior to - * starting this worker. - */ - unsigned long long ResumePoint; - /** \brief Tell the subprocess to download the given item. * * \param Item the item to queue up. diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 3abebc8d4..87bb13e39 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -1284,13 +1284,13 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) { if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false) { - CurrentBytes += I->CurrentSize; - ResumeSize += I->ResumePoint; + CurrentBytes += I->CurrentItem->CurrentSize; + ResumeSize += I->CurrentItem->ResumePoint; // Files with unknown size always have 100% completion if (I->CurrentItem->Owner->FileSize == 0 && I->CurrentItem->Owner->Complete == false) - TotalBytes += I->CurrentSize; + TotalBytes += I->CurrentItem->CurrentSize; } } diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index 4d564daf5..a5c10fd92 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -425,6 +425,21 @@ class pkgAcquire::Queue /** \brief The underlying items interested in the download */ std::vector Owners; + /** \brief How many bytes of the file have been downloaded. Zero + * if the current progress of the file cannot be determined. + */ + unsigned long long CurrentSize = 0; + + /** \brief The total number of bytes to be downloaded. Zero if the + * total size of the final is unknown. + */ + unsigned long long TotalSize = 0; + + /** \brief How much of the file was already downloaded prior to + * starting this worker. + */ + unsigned long long ResumePoint = 0; + typedef std::vector::const_iterator owner_iterator; /** \brief Assign the ItemDesc portion of this QItem from diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 6cf200f5b..b37934cd4 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -221,21 +221,21 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) enum {Long = 0,Medium,Short} Mode = Medium; // Add the current progress if (Mode == Long) - S << " " << std::to_string(I->CurrentSize); + S << " " << std::to_string(I->CurrentItem->CurrentSize); else { - if (Mode == Medium || I->TotalSize == 0) - S << " " << SizeToStr(I->CurrentSize) << "B"; + if (Mode == Medium || I->CurrentItem->TotalSize == 0) + S << " " << SizeToStr(I->CurrentItem->CurrentSize) << "B"; } // Add the total size and percent - if (I->TotalSize > 0 && I->CurrentItem->Owner->Complete == false) + if (I->CurrentItem->TotalSize > 0 && I->CurrentItem->Owner->Complete == false) { if (Mode == Short) - ioprintf(S, " %.0f%%", (I->CurrentSize*100.0)/I->TotalSize); + ioprintf(S, " %.0f%%", (I->CurrentItem->CurrentSize*100.0)/I->CurrentItem->TotalSize); else - ioprintf(S, "/%sB %.0f%%", SizeToStr(I->TotalSize).c_str(), - (I->CurrentSize*100.0)/I->TotalSize); + ioprintf(S, "/%sB %.0f%%", SizeToStr(I->CurrentItem->TotalSize).c_str(), + (I->CurrentItem->CurrentSize*100.0)/I->CurrentItem->TotalSize); } S << "]"; } -- cgit v1.2.3