Skip to content

Commit ff8e4fe

Browse files
authoredNov 6, 2024··
Fix a bug in the _upload_file_part_concurrent method (#910)
1 parent f3f63cb commit ff8e4fe

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed
 

‎s3fs/core.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1275,17 +1275,14 @@ async def _upload_chunk(chunk, part_number):
12751275
chunks.append(chunk)
12761276
if not chunks:
12771277
break
1278-
if len(chunks) > 1:
1279-
out.extend(
1280-
await asyncio.gather(
1281-
*[
1282-
_upload_chunk(chunk, len(out) + i)
1283-
for i, chunk in enumerate(chunks, 1)
1284-
]
1285-
)
1278+
out.extend(
1279+
await asyncio.gather(
1280+
*[
1281+
_upload_chunk(chunk, len(out) + i)
1282+
for i, chunk in enumerate(chunks, 1)
1283+
]
12861284
)
1287-
else:
1288-
out.append(await _upload_chunk(chunk, len(out) + 1))
1285+
)
12891286
return out
12901287

12911288
async def _get_file(

‎s3fs/tests/test_s3fs.py

+18
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,24 @@ def test_put_file_with_callback(s3, tmpdir, size):
10171017
assert cb.size == os.stat(test_file).st_size
10181018
assert cb.value == cb.size
10191019

1020+
assert s3.size(test_bucket_name + "/temp") == 11 * size
1021+
1022+
1023+
@pytest.mark.parametrize("factor", [1, 5, 6])
1024+
def test_put_file_does_not_truncate(s3, tmpdir, factor):
1025+
test_file = str(tmpdir.join("test.json"))
1026+
1027+
chunksize = 5 * 2**20
1028+
block = b"x" * chunksize
1029+
1030+
with open(test_file, "wb") as f:
1031+
f.write(block * factor)
1032+
1033+
s3.put_file(
1034+
test_file, test_bucket_name + "/temp", max_concurrency=5, chunksize=chunksize
1035+
)
1036+
assert s3.size(test_bucket_name + "/temp") == factor * chunksize
1037+
10201038

10211039
@pytest.mark.parametrize("size", [2**10, 2**20, 10 * 2**20])
10221040
def test_pipe_cat_big(s3, size):

0 commit comments

Comments
 (0)
Please sign in to comment.