[New-bugs-announce] [issue37700] shutil.copyfile does not raise SpecialFileError for socket files

Christopher Hunt report at bugs.python.org
Mon Jul 29 00:22:16 EDT 2019


New submission from Christopher Hunt <chrahunt at gmail.com>:

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.

----------
components: Library (Lib)
messages: 348595
nosy: chrahunt
priority: normal
severity: normal
status: open
title: shutil.copyfile does not raise SpecialFileError for socket files
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37700>
_______________________________________


More information about the New-bugs-announce mailing list