diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-05-30 06:05:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-30 06:05:41 (GMT) |
commit | 413d955f8ec88a7183f91d7ad8b0ff7def803de3 (patch) | |
tree | 5e82b37895fa363bf445df67f61a56ff5553de61 /Lib/shutil.py | |
parent | a16387ab2d85f19665920bb6ff91a7e57f59dd2a (diff) | |
download | cpython-413d955f8ec88a7183f91d7ad8b0ff7def803de3.zip cpython-413d955f8ec88a7183f91d7ad8b0ff7def803de3.tar.gz cpython-413d955f8ec88a7183f91d7ad8b0ff7def803de3.tar.bz2 |
bpo-36610: shutil.copyfile(): use sendfile() on Linux only (GH-13675)
...and avoid using it on Solaris as it can raise EINVAL if offset is equal or bigger than the size of the file
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 2dfae87..dae916b 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -50,7 +50,7 @@ elif _WINDOWS: import nt COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 64 * 1024 -_HAS_SENDFILE = posix and hasattr(os, "sendfile") +_USE_CP_SENDFILE = hasattr(os, "sendfile") and sys.platform.startswith("linux") _HAS_FCOPYFILE = posix and hasattr(posix, "_fcopyfile") # macOS __all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2", @@ -111,7 +111,7 @@ def _fastcopy_fcopyfile(fsrc, fdst, flags): def _fastcopy_sendfile(fsrc, fdst): """Copy data from one regular mmap-like fd to another by using high-performance sendfile(2) syscall. - This should work on Linux >= 2.6.33 and Solaris only. + This should work on Linux >= 2.6.33 only. """ # Note: copyfileobj() is left alone in order to not introduce any # unexpected breakage. Possible risks by using zero-copy calls @@ -122,7 +122,7 @@ def _fastcopy_sendfile(fsrc, fdst): # GzipFile (which decompresses data), HTTPResponse (which decodes # chunks). # - possibly others (e.g. encrypted fs/partition?) - global _HAS_SENDFILE + global _USE_CP_SENDFILE try: infd = fsrc.fileno() outfd = fdst.fileno() @@ -152,7 +152,7 @@ def _fastcopy_sendfile(fsrc, fdst): # sendfile() on this platform (probably Linux < 2.6.33) # does not support copies between regular files (only # sockets). - _HAS_SENDFILE = False + _USE_CP_SENDFILE = False raise _GiveupOnFastCopy(err) if err.errno == errno.ENOSPC: # filesystem is full @@ -260,8 +260,8 @@ def copyfile(src, dst, *, follow_symlinks=True): return dst except _GiveupOnFastCopy: pass - # Linux / Solaris - elif _HAS_SENDFILE: + # Linux + elif _USE_CP_SENDFILE: try: _fastcopy_sendfile(fsrc, fdst) return dst |