Move SFTPClient.get() termination condition to loop end.

Ensures callback always executes even for zero-len files.

Fixes #90
This commit is contained in:
Jeff Forcier 2012-10-14 21:46:50 -07:00
parent 8e5f774965
commit 1341e28882
2 changed files with 6 additions and 2 deletions

4
NEWS
View File

@ -15,6 +15,10 @@ Releases
v1.8.1 (DD MM YYYY)
-------------------
* #90: Ensure that callbacks handed to `SFTPClient.get()` always fire at least
once, even for zero-length files downloaded. Thanks to Github user `@enB` for
the catch.
v1.8.0 (3rd Oct 2012)
---------------------

View File

@ -612,12 +612,12 @@ class SFTPClient (BaseSFTP):
size = 0
while True:
data = fr.read(32768)
if len(data) == 0:
break
fl.write(data)
size += len(data)
if callback is not None:
callback(size, file_size)
if len(data) == 0:
break
finally:
fl.close()
finally: