Skip to content

Commit 54d8f1b

Browse files
committed
Reenable use of sendfile in shutil module on Solaris
python#86009 python#23893
1 parent f066f26 commit 54d8f1b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Doc/library/shutil.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ the use of userspace buffers in Python as in "``outfd.write(infd.read())``".
459459

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

462-
On Linux :func:`os.sendfile` is used.
462+
On Linux and Solaris :func:`os.sendfile` is used.
463463

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

472472
.. versionchanged:: 3.8
473473

474+
.. versionchanged:: 3.12
475+
Solaris now uses :func:`os.sendfile` rather than no fast-copy operation.
476+
474477
.. _shutil-copytree-example:
475478

476479
copytree example

Lib/shutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import nt
5151

5252
COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 64 * 1024
53-
_USE_CP_SENDFILE = hasattr(os, "sendfile") and sys.platform.startswith("linux")
53+
_USE_CP_SENDFILE = hasattr(os, "sendfile") and sys.platform.startswith(("linux", "sunos"))
5454
_HAS_FCOPYFILE = posix and hasattr(posix, "_fcopyfile") # macOS
5555

5656
# CMD defaults in Windows 10
@@ -114,7 +114,7 @@ def _fastcopy_fcopyfile(fsrc, fdst, flags):
114114
def _fastcopy_sendfile(fsrc, fdst):
115115
"""Copy data from one regular mmap-like fd to another by using
116116
high-performance sendfile(2) syscall.
117-
This should work on Linux >= 2.6.33 only.
117+
This should work on Linux >= 2.6.33 and Solaris only.
118118
"""
119119
# Note: copyfileobj() is left alone in order to not introduce any
120120
# unexpected breakage. Possible risks by using zero-copy calls
@@ -271,7 +271,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
271271
return dst
272272
except _GiveupOnFastCopy:
273273
pass
274-
# Linux
274+
# Linux / Solaris
275275
elif _USE_CP_SENDFILE:
276276
try:
277277
_fastcopy_sendfile(fsrc, fdst)

0 commit comments

Comments
 (0)