Skip to content
Closed
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
8 changes: 6 additions & 2 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,20 @@ def _fastcopy_sendfile(fsrc, fdst):
# should not make any difference, also in case the file content
# changes while being copied.
try:
blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MiB
filesize = os.fstat(infd).st_size
blocksize = max(filesize, 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.
if sys.maxsize < 2 ** 32:
blocksize = min(blocksize, 2 ** 30)

offset = 0
while True:
# We explicitly limit ourselves to filesize to avoid odd behavior
# on some systems. https://github.com/python/cpython/issues/87909
while offset < filesize:
try:
sent = os.sendfile(outfd, infd, offset, blocksize)
except OSError as err:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Avoid an unusual case in :func:`shutil.copyfile` where the ``sendfile``
system call might return an error on some kernels and filesystems after all
data was transferred.