Skip to content

Commit 8f82d9a

Browse files
authored
bpo-41843: Reenable use of sendfile in shutil module on Solaris (GH-23893)
1 parent 426569e commit 8f82d9a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Doc/library/shutil.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ the use of userspace buffers in Python as in "``outfd.write(infd.read())``".
517517

518518
On macOS `fcopyfile`_ is used to copy the file content (not metadata).
519519

520-
On Linux :func:`os.sendfile` is used.
520+
On Linux and Solaris :func:`os.sendfile` is used.
521521

522522
On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB
523523
instead of 64 KiB) and a :func:`memoryview`-based variant of
@@ -529,6 +529,9 @@ file then shutil will silently fallback on using less efficient
529529

530530
.. versionchanged:: 3.8
531531

532+
.. versionchanged:: 3.14
533+
Solaris now uses :func:`os.sendfile`.
534+
532535
.. _shutil-copytree-example:
533536

534537
copytree example

Lib/shutil.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# This should never be removed, see rationale in:
4949
# https://bugs.python.org/issue43743#msg393429
5050
_USE_CP_SENDFILE = (hasattr(os, "sendfile")
51-
and sys.platform.startswith(("linux", "android")))
51+
and sys.platform.startswith(("linux", "android", "solaris")))
5252
_HAS_FCOPYFILE = posix and hasattr(posix, "_fcopyfile") # macOS
5353

5454
# CMD defaults in Windows 10
@@ -110,7 +110,7 @@ def _fastcopy_fcopyfile(fsrc, fdst, flags):
110110
def _fastcopy_sendfile(fsrc, fdst):
111111
"""Copy data from one regular mmap-like fd to another by using
112112
high-performance sendfile(2) syscall.
113-
This should work on Linux >= 2.6.33 only.
113+
This should work on Linux >= 2.6.33, Android and Solaris.
114114
"""
115115
# Note: copyfileobj() is left alone in order to not introduce any
116116
# unexpected breakage. Possible risks by using zero-copy calls
@@ -265,7 +265,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
265265
return dst
266266
except _GiveupOnFastCopy:
267267
pass
268-
# Linux
268+
# Linux / Android / Solaris
269269
elif _USE_CP_SENDFILE:
270270
try:
271271
_fastcopy_sendfile(fsrc, fdst)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Solaris now uses :func:`os.sendfile` fast-copy syscall for more efficient
2+
:mod:`shutil` file copy related functions.

0 commit comments

Comments
 (0)