Lib/shutil.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index 22bd86d..0e30da2 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -130,8 +130,10 @@ def _fastcopy_sendfile(fsrc, fdst): # should not make any difference, also in case the file content # changes while being copied. try: + filesize = os.fstat(infd).st_size blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MiB except OSError: + filesize = float('inf') blocksize = 2 ** 27 # 128MiB # On 32-bit architectures truncate to 1GiB to avoid OverflowError, # see bpo-38319. @@ -139,7 +141,7 @@ def _fastcopy_sendfile(fsrc, fdst): blocksize = min(blocksize, 2 ** 30) offset = 0 - while True: + while offset < filesize: try: sent = os.sendfile(outfd, infd, offset, blocksize) except OSError as err: