Skip to content
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
6 changes: 3 additions & 3 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,13 @@ def put_file(self, lpath, rpath, callback=_DEFAULT_CALLBACK, **kwargs):
return None

with open(lpath, "rb") as f1:
callback.set_size(f1.seek(0, 2))
size = f1.seek(0, 2)
callback.set_size(size)
f1.seek(0)

self.mkdirs(self._parent(os.fspath(rpath)), exist_ok=True)
with self.open(rpath, "wb", **kwargs) as f2:
data = True
while data:
while f2.tell() < size:
Copy link
Contributor

Choose a reason for hiding this comment

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

why not f1.tell() < size? If f2.write() silently failed to write a chunk, then this would go into an infinite loop where f1.read() thinks it's done but f2 never gets the whole file

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, that really shouldn't happen, but I'd be OK with your suggestion. Do you want to make that follow-on PR?

data = f1.read(self.blocksize)
segment_len = f2.write(data)
callback.relative_update(segment_len)
Expand Down
4 changes: 3 additions & 1 deletion fsspec/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ def test_dummy_callbacks_file(tmpdir):
source.write_text("x" * 100, "utf-8")

fs.put_file(source, file, callback=callback)
assert callback.events == imitate_transfer(size, 10)

# -1 here since put_file no longer has final zero-size put
assert callback.events == imitate_transfer(size, 10)[:-1]
callback.events.clear()

fs.get_file(file, destination, callback=callback)
Expand Down