Skip to content

Commit

Permalink
solve a bug when the 'write' method in an implementation does not ret… (
Browse files Browse the repository at this point in the history
#1072)

* solve a bug when the 'write' method in an implementation does not return the actual length of written data (the case of SFTP with paramiko)

* add a test for put_file

* typo

* rpath must be a new file

* remove extra tabs
  • Loading branch information
ghislainp committed Oct 13, 2022
1 parent 30b2da7 commit 7077f7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fsspec/implementations/tests/test_sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ def netloc(ssh):
return userpass + netloc


def test_put_file(ssh, tmp_path, root_path):

tmp_file = tmp_path / "a.txt"
with open(tmp_file, mode="w") as fd:
fd.write("blabla")

f = fsspec.get_filesystem_class("sftp")(**ssh)
f.put_file(lpath=tmp_file, rpath=root_path + "a.txt")


def test_simple_with_tar(ssh, netloc, tmp_path, root_path):

files_to_pack = ["a.txt", "b.txt"]
Expand Down
4 changes: 4 additions & 0 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ def get_file(
while data:
data = f1.read(self.blocksize)
segment_len = outfile.write(data)
if segment_len is None:
segment_len = len(data)
callback.relative_update(segment_len)
if not isfilelike(lpath):
outfile.close()
Expand Down Expand Up @@ -861,6 +863,8 @@ def put_file(self, lpath, rpath, callback=_DEFAULT_CALLBACK, **kwargs):
while f1.tell() < size:
data = f1.read(self.blocksize)
segment_len = f2.write(data)
if segment_len is None:
segment_len = len(data)
callback.relative_update(segment_len)

def put(self, lpath, rpath, recursive=False, callback=_DEFAULT_CALLBACK, **kwargs):
Expand Down

0 comments on commit 7077f7f

Please sign in to comment.