Revision d58df7c0

b/kamaki/clients/pithos/__init__.py
315 315
            hash_gen = hash_cb(nblocks)
316 316
            hash_gen.next()
317 317

  
318
        for i in range(nblocks):
318
        for i in xrange(nblocks):
319 319
            block = readall(fileobj, min(blocksize, size - offset))
320 320
            bytes = len(block)
321
            if bytes <= 0:
322
                break
321 323
            hash = _pithos_hash(block, blockhash)
322 324
            hashes.append(hash)
323 325
            hmap[hash] = (offset, bytes)
324 326
            offset += bytes
325 327
            if hash_cb:
326 328
                hash_gen.next()
327
        msg = ('Failed to calculate uploaded blocks:'
328
               ' Offset and object size do not match')
329
        msg = ('Failed to calculate uploading blocks: '
330
               'read bytes(%s) != requested size (%s)' % (offset, size))
329 331
        assert offset == size, msg
330 332

  
331 333
    def _upload_missing_blocks(self, missing, hmap, fileobj, upload_gen=None):
b/kamaki/clients/utils/__init__.py
94 94

  
95 95
def readall(openfile, size, retries=7):
96 96
    """Read a file until size is reached"""
97
    from os import fstat
98
    actual_size = fstat(openfile.fileno()).st_size - openfile.tell()
99
    size = actual_size if actual_size < size else size
100 97
    remains = size if size > 0 else 0
101 98
    buf = ''
102 99
    for i in range(retries):
103
        buf += openfile.read(remains)
104
        remains = size - len(buf)
105
        if remains:
106
            continue
100
        tmp_buf = openfile.read(remains)
101
        if tmp_buf:
102
            buf += tmp_buf
103
            remains -= len(tmp_buf)
104
            if remains > 0:
105
                continue
107 106
        return buf
108 107
    raise IOError('Failed to read %s bytes from file' % size)

Also available in: Unified diff