Skip to content

Commit 9b65fa3

Browse files
committed
Reenable sendfile fast-copy syscall on Solaris
1 parent 2d9f252 commit 9b65fa3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Doc/library/shutil.rst

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

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

468-
On Linux :func:`os.sendfile` is used.
468+
On Linux and Solaris :func:`os.sendfile` is used.
469469

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

478478
.. versionchanged:: 3.8
479479

480+
.. versionchanged:: 3.10
481+
Solaris now uses :func:`os.sendfile` rather than no fast-copy operation.
482+
480483
.. _shutil-copytree-example:
481484

482485
copytree example

Lib/shutil.py

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

4848
# CMD defaults in Windows 10
@@ -106,7 +106,7 @@ def _fastcopy_fcopyfile(fsrc, fdst, flags):
106106
def _fastcopy_sendfile(fsrc, fdst):
107107
"""Copy data from one regular mmap-like fd to another by using
108108
high-performance sendfile(2) syscall.
109-
This should work on Linux >= 2.6.33 only.
109+
This should work on Linux >= 2.6.33 and Solaris only.
110110
"""
111111
# Note: copyfileobj() is left alone in order to not introduce any
112112
# unexpected breakage. Possible risks by using zero-copy calls
@@ -264,7 +264,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
264264
return dst
265265
except _GiveupOnFastCopy:
266266
pass
267-
# Linux
267+
# Linux / Solaris
268268
elif _USE_CP_SENDFILE:
269269
try:
270270
_fastcopy_sendfile(fsrc, fdst)
@@ -285,7 +285,6 @@ def copyfile(src, dst, *, follow_symlinks=True):
285285
raise FileNotFoundError(f'Directory does not exist: {dst}') from e
286286
else:
287287
raise
288-
289288
return dst
290289

291290
def copymode(src, dst, *, follow_symlinks=True):

0 commit comments

Comments
 (0)