From 6f751e02cccfe3c99338ef54663ebf16c85d3a6a Mon Sep 17 00:00:00 2001 From: Martin Durant Date: Wed, 22 Dec 2021 09:04:45 -0500 Subject: [PATCH 1/2] Make put_file continue on zero-read --- fsspec/spec.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fsspec/spec.py b/fsspec/spec.py index a7eaa24a6..14e6dbbd4 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -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: data = f1.read(self.blocksize) segment_len = f2.write(data) callback.relative_update(segment_len) From d299fc4c545cdbd4408ebee2050d1b76286bc36d Mon Sep 17 00:00:00 2001 From: Martin Durant Date: Wed, 22 Dec 2021 09:21:48 -0500 Subject: [PATCH 2/2] fix test --- fsspec/tests/test_spec.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fsspec/tests/test_spec.py b/fsspec/tests/test_spec.py index 07e1a2e86..760b248ac 100644 --- a/fsspec/tests/test_spec.py +++ b/fsspec/tests/test_spec.py @@ -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)