Skip to content

resumblePut can put 0-size file #110

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 1 commit into from
Jun 3, 2014
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
3 changes: 2 additions & 1 deletion qiniu/resumable_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def put(uptoken, key, f, fsize, extra):
return None, err_put_failed
print err, ".. retry"

mkfile_client = auth_up.Client(uptoken, extra.progresses[-1]["host"])
mkfile_host = extra.progresses[-1]["host"] if block_cnt else conf.UP_HOST
mkfile_client = auth_up.Client(uptoken, mkfile_host)
return mkfile(mkfile_client, key, fsize, extra)


Expand Down
24 changes: 22 additions & 2 deletions qiniu/test/resumable_io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import binascii
import urllib
import shutil
import StringIO

from qiniu import conf
from qiniu.auth import up
Expand Down Expand Up @@ -80,11 +81,11 @@ def test_put(self):
key = "sdk_py_resumable_block_5_%s" % r(9)
localfile = dst.name
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
dst.close()
os.remove(tmpf)

assert err is None, err
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
self.assertEqual(
ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match")
rs.Client().delete(bucket, key)
Expand All @@ -108,15 +109,34 @@ def test_put_4m(self):
key = "sdk_py_resumable_block_6_%s" % r(9)
localfile = dst.name
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
dst.close()
os.remove(tmpf)

assert err is None, err
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
self.assertEqual(
ret["hash"], "FnIVmMd_oaUV3MLDM6F9in4RMz2U", "hash not match")
rs.Client().delete(bucket, key)

def test_put_0(self):
if is_travis:
return

f = StringIO.StringIO('')

policy = rs.PutPolicy(bucket)
extra = resumable_io.PutExtra(bucket)
extra.bucket = bucket
extra.params = {"x:foo": "test"}
key = "sdk_py_resumable_block_7_%s" % r(9)
ret, err = resumable_io.put(policy.token(), key, f, 0, extra)

assert err is None, err
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
self.assertEqual(
ret["hash"], "Fg==", "hash not match")
rs.Client().delete(bucket, key)


if __name__ == "__main__":
if not is_travis:
Expand Down