Skip to content

Commit 8870f96

Browse files
committed
Merge pull request #110 from SunRunAway/develop
resumblePut can put 0-size file
2 parents 28a2174 + 1774db1 commit 8870f96

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

qiniu/resumable_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def put(uptoken, key, f, fsize, extra):
106106
return None, err_put_failed
107107
print err, ".. retry"
108108

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

112113

qiniu/test/resumable_io_test.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import binascii
1313
import urllib
1414
import shutil
15+
import StringIO
1516

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

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

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

121+
def test_put_0(self):
122+
if is_travis:
123+
return
124+
125+
f = StringIO.StringIO('')
126+
127+
policy = rs.PutPolicy(bucket)
128+
extra = resumable_io.PutExtra(bucket)
129+
extra.bucket = bucket
130+
extra.params = {"x:foo": "test"}
131+
key = "sdk_py_resumable_block_7_%s" % r(9)
132+
ret, err = resumable_io.put(policy.token(), key, f, 0, extra)
133+
134+
assert err is None, err
135+
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
136+
self.assertEqual(
137+
ret["hash"], "Fg==", "hash not match")
138+
rs.Client().delete(bucket, key)
139+
120140

121141
if __name__ == "__main__":
122142
if not is_travis:

0 commit comments

Comments
 (0)