Mailinglist Archive: zypp-commit (232 mails)

< Previous Next >
[zypp-commit] <libzypp> master : Expect also 'Bs' when parsing download speed from aria2c (bnc #537870)
  • From: Ján Kupec <jkupec@xxxxxxx>
  • Date: Thu, 26 Nov 2009 16:04:41 +0100
  • Message-id: <E1NDfve-0001aO-Ox@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 6eb478accc0f106c946b23fc8fd848c738c996c6
Author: Ján Kupec <jkupec@xxxxxxx>
Date: Thu Nov 26 16:04:41 2009 +0100

Expect also 'Bs' when parsing download speed from aria2c (bnc #537870)
---
zypp/media/MediaAria2c.cc | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index 6174dcc..71442d0 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -319,6 +319,7 @@ void MediaAria2c::getFileCopy( const Pathname & filename ,
const Pathname & targ
// progress line like: [#1 SIZE:8.3MiB/10.1MiB(82%) CN:5
SPD:6899.88KiB/s]
// but since 1.4.0: [#1 SIZE:8.3MiB/10.1MiB(82%) CN:5 SPD:899.8KiBs]
// (bnc #513944) [#1 SIZE:8.3MiB/10.1MiB(82%) CN:5 SPD:3.8MiBs]
+ // [#1 SIZE:8.3MiB/10.1MiB(82%) CN:5 SPD:38Bs]
// we save it until we find a string with FILE: later
string progressLine;
int progress = 0;
@@ -389,14 +390,16 @@ void MediaAria2c::getFileCopy( const Pathname & filename
, const Pathname & targ

// get the speed
double current_speed = 0;
+ int factor = 1; // B/KiB/MiB multiplication factor
+
left_bound = progressLine.find("SPD:",0) + 4;
- count = progressLine.find("KiB",left_bound);
- bool kibs = true; // KiBs ? (MiBs if false)
- if ( count == string::npos ) // try MiBs
- {
- count = progressLine.find("MiBs",left_bound);
- kibs = false;
- }
+ if ((count = progressLine.find("KiB",left_bound)) !=
string::npos)
+ factor = 1024;
+ else if ((count = progressLine.find("MiB",left_bound)) !=
string::npos)
+ factor = 0x100000;
+ else
+ count = progressLine.find("Bs",left_bound);
+
if ( count != string::npos )
{ // convert the string to a double
count -= left_bound;
@@ -404,13 +407,15 @@ void MediaAria2c::getFileCopy( const Pathname & filename
, const Pathname & targ
try {
current_speed = boost::lexical_cast<double>(speedStr);
// convert to and work with bytes everywhere (bnc #537870)
- current_speed *= kibs ? 0x400 : 0x100000;
+ current_speed *= factor;
}
catch (const std::exception&) {
ERR << "Can't parse speed from '" << speedStr << "'" << endl;
current_speed = 0;
}
}
+ else
+ ERR << "Can't parse speed from '" << progressLine << "'" <<
endl;

// we have a new average speed
average_speed_count++;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages