Skip to content

Commit af44703

Browse files
committed
Reenable sendfile fast-copy syscall on Solaris
1 parent 931f443 commit af44703

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
@@ -503,7 +503,7 @@ the use of userspace buffers in Python as in "``outfd.write(infd.read())``".
503503

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

506-
On Linux :func:`os.sendfile` is used.
506+
On Linux and Solaris :func:`os.sendfile` is used.
507507

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

516516
.. versionchanged:: 3.8
517517

518+
.. versionchanged:: 3.10
519+
Solaris now uses :func:`os.sendfile` rather than no fast-copy operation.
520+
518521
.. _shutil-copytree-example:
519522

520523
copytree example

Lib/shutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 64 * 1024
4848
# This should never be removed, see rationale in:
4949
# https://bugs.python.org/issue43743#msg393429
50-
_USE_CP_SENDFILE = hasattr(os, "sendfile") and sys.platform.startswith("linux")
50+
_USE_CP_SENDFILE = hasattr(os, "sendfile") and sys.platform.startswith(("linux", "sunos"))
5151
_HAS_FCOPYFILE = posix and hasattr(posix, "_fcopyfile") # macOS
5252

5353
# CMD defaults in Windows 10
@@ -111,7 +111,7 @@ def _fastcopy_fcopyfile(fsrc, fdst, flags):
111111
def _fastcopy_sendfile(fsrc, fdst):
112112
"""Copy data from one regular mmap-like fd to another by using
113113
high-performance sendfile(2) syscall.
114-
This should work on Linux >= 2.6.33 only.
114+
This should work on Linux >= 2.6.33 and Solaris only.
115115
"""
116116
# Note: copyfileobj() is left alone in order to not introduce any
117117
# unexpected breakage. Possible risks by using zero-copy calls
@@ -266,7 +266,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
266266
return dst
267267
except _GiveupOnFastCopy:
268268
pass
269-
# Linux
269+
# Linux / Solaris
270270
elif _USE_CP_SENDFILE:
271271
try:
272272
_fastcopy_sendfile(fsrc, fdst)

0 commit comments

Comments
 (0)