Fix percent done on resumed /clone.bundle

The Content-Length when resuming is the number of bytes that
remain in the file. To compute the total size as expected by
the progress meter, we must add the bytes already stored.

While we are in this method fix uses of % operator to ensure
a tuple is always supplied.

Change-Id: Ic899231b5bc0ab43b3ddb1d29845f6390e820115
This commit is contained in:
Shawn O. Pearce 2012-08-01 17:41:26 -07:00
parent 2bc7f5cb3a
commit 9830553748

View File

@ -1564,7 +1564,7 @@ class Project(object):
try:
req = urllib2.Request(srcUrl)
if pos > 0:
req.add_header('Range', 'bytes=%d-' % pos)
req.add_header('Range', 'bytes=%d-' % (pos,))
try:
r = urllib2.urlopen(req)
@ -1583,7 +1583,7 @@ class Project(object):
msg = e.read()
if len(msg) > 0 and msg[-1] == '\n':
msg = msg[0:-1]
msg = ' (%s)' % msg
msg = ' (%s)' % (msg,)
except:
msg = ''
else:
@ -1601,7 +1601,7 @@ class Project(object):
p = None
try:
size = r.headers.get('content-length', 0)
size = pos + r.headers.get('content-length', 0)
unit = 1 << 10
if size and not quiet:
@ -1611,7 +1611,7 @@ class Project(object):
else:
desc = 'KB'
p = Progress(
'Downloading %s' % self.relpath,
'Downloading %s' % (self.relpath,),
int(size) / unit,
units=desc)
if pos > 0: