summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-04-16 14:43:08 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-04-16 14:43:08 +0200
commitd0cfa8adbdd74ad7e363019739c77e713dc982e5 (patch)
treecb27f24f5af0b2d600aa9fbfa4d8048fe12947ae /apt-pkg
parent5572f6bdcb947e11f32e2a035438d9d3899ad46d (diff)
make the TotalFiles more reliable in apt-get update
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc25
-rw-r--r--apt-pkg/acquire-item.h10
-rw-r--r--apt-pkg/acquire.cc16
3 files changed, 46 insertions, 5 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 30743addf..6f6b3d59f 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -55,7 +55,8 @@ using namespace std;
/* */
pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), FileSize(0),
PartialSize(0), Mode(0), ID(0), Complete(false),
- Local(false), QueueCounter(0)
+ Local(false), QueueCounter(0),
+ ExpectedAdditionalItems(0)
{
Owner->Add(this);
Status = StatIdle;
@@ -1257,6 +1258,9 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner, /*{{{*/
Rename(Final,LastGoodSig);
}
+ // we expect the indextargets + one additional Release file
+ ExpectedAdditionalItems = IndexTargets->size() + 1;
+
QueueURI(Desc);
}
/*}}}*/
@@ -1309,6 +1313,9 @@ void pkgAcqMetaSig::Done(string Message,unsigned long long Size,string MD5,
Complete = true;
+ // at this point pkgAcqMetaIndex takes over
+ ExpectedAdditionalItems = 0;
+
// put the last known good file back on i-m-s hit (it will
// be re-verified again)
// Else do nothing, we have the new file in DestFile then
@@ -1326,6 +1333,9 @@ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
{
string Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
+ // at this point pkgAcqMetaIndex takes over
+ ExpectedAdditionalItems = 0;
+
// if we get a network error we fail gracefully
if(Status == StatTransientNetworkError)
{
@@ -1376,6 +1386,9 @@ pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire *Owner, /*{{{*/
Desc.ShortDesc = ShortDesc;
Desc.URI = URI;
+ // we expect more item
+ ExpectedAdditionalItems = IndexTargets->size();
+
QueueURI(Desc);
}
/*}}}*/
@@ -1554,6 +1567,9 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
}
}
+ // at this point the real Items are loaded in the fetcher
+ ExpectedAdditionalItems = 0;
+
for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin();
Target != IndexTargets->end();
++Target)
@@ -1784,6 +1800,10 @@ pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire *Owner, /*{{{*/
{
SigFile = DestFile;
+ // index targets + (worst case:) Release/Release.gpg
+ ExpectedAdditionalItems = IndexTargets->size() + 2;
+
+
// keep the old InRelease around in case of transistent network errors
string const Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
if (RealFileExists(Final) == true)
@@ -1826,6 +1846,9 @@ string pkgAcqMetaClearSig::Custom600Headers()
/*}}}*/
void pkgAcqMetaClearSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
{
+ // we failed, we will not get additional items from this method
+ ExpectedAdditionalItems = 0;
+
if (AuthPass == false)
{
// Remove the 'old' InRelease file if we try Release.gpg now as otherwise
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index f48d2a0d7..c12d8d63a 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -166,6 +166,16 @@ class pkgAcquire::Item : public WeakPointable
* \sa pkgAcquire
*/
unsigned int QueueCounter;
+
+ /** \brief The number of additional fetch items that are expected
+ * once this item is done.
+ *
+ * Some items like pkgAcqMeta{Index,Sig} will queue additional
+ * items. This variable can be set by the methods if it knows
+ * in advance how many items to expect to get a more accurate
+ * progress.
+ */
+ unsigned int ExpectedAdditionalItems;
/** \brief The name of the file into which the retrieved object
* will be written.
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index a187a00ae..2b427ccd3 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -832,6 +832,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
if ((*I)->Local == true)
continue;
+ // see if the method tells us to expect more
+ TotalItems += (*I)->ExpectedAdditionalItems;
+
TotalBytes += (*I)->FileSize;
if ((*I)->Complete == true)
CurrentBytes += (*I)->FileSize;
@@ -901,12 +904,17 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
-
+ // calculate the percentage, if we have too little data assume 0%
+ int Percent;
+ if (TotalBytes < 1*1024)
+ Percent = 0;
+ else
+ Percent = (CurrentBytes/float(TotalBytes)*100.0);
// build the status str
status << "dlstatus:" << i
- << ":" << (CurrentBytes/float(TotalBytes)*100.0)
- << ":" << msg
- << endl;
+ << ":" << Percent
+ << ":" << msg
+ << endl;
std::string const dlstatus = status.str();
FileFd::Write(fd, dlstatus.c_str(), dlstatus.size());