This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shutil.copyfile does not raise SpecialFileError for socket files
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: chrahunt, chris.jerdonek, potomak
Priority: normal Keywords: patch

Created on 2019-07-29 04:22 by chrahunt, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 16575 open AWhetter, 2019-10-04 00:50
Messages (3)
msg348595 - (view) Author: Christopher Hunt (chrahunt) * Date: 2019-07-29 04:22
Currently shutil.copyfile only raises SpecialFileError for named pipes. When trying to use the function to copy a socket file, the exception raised depends on the platform, for example:

macOS: "[Errno 102] Operation not supported on socket: '/Users/guido/src/mypy/dmypy.sock'"
HP-UX: "[Errno 223] Operation not supported: 'example/foo'"
Solaris: "[Errno 122] Operation not supported on transport endpoint: 'example/foo'"
AIX: "[Errno 64] Operation not supported on socket: '../../example/foo'"
Linux: "[Errno 6] No such device or address: 'example/foo'"

This can be reproduced like:

    import os
    import shutil
    import socket
    import tempfile

    d = tempfile.mkdtemp()
    src = os.path.join(d, "src")
    dest = os.path.join(d, "dest")
    sock = socket.socket(socket.AF_UNIX)
    sock.bind(src)

    shutil.copyfile(src, dest)

Making shutil.copyfile raise SpecialFileError for socket files would improve the interface of this function since the same class of error could be ignored. This is mostly useful with shutil.copytree, which defaults to copyfile for its copy function.
msg348596 - (view) Author: Christopher Hunt (chrahunt) * Date: 2019-07-29 04:24
See also: the comment from https://github.com/python/cpython/blob/e1b900247227dad49d8231f1d028872412230ab4/Lib/shutil.py#L245:

> # XXX What about other special files? (sockets, devices...)
msg348602 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2019-07-29 08:41
This issue is being filed after coming up in pip's tracker here (in a comment by Guido): https://github.com/pypa/pip/issues/5306#issuecomment-383355379
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81881
2021-12-11 18:41:20iritkatrielsetversions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8
2019-10-04 00:50:33AWhettersetkeywords: + patch
stage: patch review
pull_requests: + pull_request16167
2019-08-04 14:48:44potomaksetnosy: + potomak
2019-07-29 08:41:13chris.jerdoneksetnosy: + chris.jerdonek
messages: + msg348602
2019-07-29 04:24:03chrahuntsetmessages: + msg348596
2019-07-29 04:22:16chrahuntcreate