Skip to content

bug fix #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qiniu/auth/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

class Client(rpc.Client):
up_token = None

def __init__(self, up_token, host=None):
if host is None:
host = conf.UP_HOST
if host.startswith("http://"):
host = host[7:]
self.up_token = up_token
super(Client, self).__init__(host)

Expand Down
15 changes: 9 additions & 6 deletions qiniu/resumable_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ def put(uptoken, key, f, fsize, extra):
if extra.chunk_size is None:
extra.chunk_size = _chunk_size

client = auth.up.Client(uptoken)
for i in xrange(0, block_cnt):
try_time = extra.try_times
read_length = _block_size
if (i+1)*_block_size > fsize:
read_length = fsize - i*_block_size
data_slice = f.read(read_length)
while True:
err = resumable_block_put(client, data_slice, i, extra)
err = resumable_block_put(data_slice, i, extra, uptoken)
if err is None:
break

Expand All @@ -101,34 +100,38 @@ def put(uptoken, key, f, fsize, extra):
return None, err_put_failed
print err, ".. retry"

return mkfile(client, key, fsize, extra)
mkfile_client = auth.up.Client(uptoken, extra.progresses[-1]["host"])
return mkfile(mkfile_client, key, fsize, extra)

# ----------------------------------------------------------

def resumable_block_put(client, block, index, extra):
def resumable_block_put(block, index, extra, uptoken):
block_size = len(block)

mkblk_client = auth.up.Client(uptoken, conf.UP_HOST)
if extra.progresses[index] is None or "ctx" not in extra.progresses[index]:
end_pos = extra.chunk_size-1
if block_size < extra.chunk_size:
end_pos = block_size-1
chunk = block[: end_pos]
crc32 = gen_crc32(chunk)
chunk = bytearray(chunk)
extra.progresses[index], err = mkblock(client, block_size, chunk)
extra.progresses[index], err = mkblock(mkblk_client, block_size, chunk)
if not extra.progresses[index]["crc32"] == crc32:
return err_unmatched_checksum
if err is not None:
extra.notify_err(index, end_pos + 1, err)
return err
extra.notify(index, end_pos + 1, extra.progresses[index])

bput_client = auth.up.Client(uptoken, extra.progresses[index]["host"])
while extra.progresses[index]["offset"] < block_size:
offset = extra.progresses[index]["offset"]
chunk = block[offset: offset+extra.chunk_size-1]
crc32 = gen_crc32(chunk)
chunk = bytearray(chunk)
extra.progresses[index], err = putblock(client, extra.progresses[index], chunk)

extra.progresses[index], err = putblock(bput_client, extra.progresses[index], chunk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

每次bput应该用上次bput(mkblk)反回的uphost

if not extra.progresses[index]["crc32"] == crc32:
return err_unmatched_checksum
if err is not None:
Expand Down