New submission from Christopher Hunt <chrah...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue37700>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to