Skip to content

shutil.copyfile does not raise SpecialFileError for socket files #81881

Description

@chrahunt
mannequin
BPO 37700
Nosy @cjerdonek, @chrahunt, @potomak
PRs
  • gh-81881: Raise a shutil.SpecialFileError when copying a Unix socket #16575
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-07-29.04:22:16.840>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'shutil.copyfile does not raise SpecialFileError for socket files'
    updated_at = <Date 2021-12-11.18:41:20.112>
    user = 'https://github.com/chrahunt'

    bugs.python.org fields:

    activity = <Date 2021-12-11.18:41:20.112>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-07-29.04:22:16.840>
    creator = 'chrahunt'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37700
    keywords = ['patch']
    message_count = 3.0
    messages = ['348595', '348596', '348602']
    nosy_count = 3.0
    nosy_names = ['chris.jerdonek', 'chrahunt', 'potomak']
    pr_nums = ['16575']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37700'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    Activity

    1. chrahunt commented on Jul 29, 2019

      chrahuntmannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jul 29, 2019
    3. chrahunt commented on Jul 29, 2019

      chrahuntmannequin
      MannequinAuthor

      See also: the comment from

      # XXX What about other special files? (sockets, devices...)
      :

      XXX What about other special files? (sockets, devices...)

    4. cjerdonek commented on Jul 29, 2019

      @cjerdonek
      Member

      This issue is being filed after coming up in pip's tracker here (in a comment by Guido): pypa/pip#5306 (comment)

    5. transferred this issue fromon Apr 10, 2022
    6. added a commit that references this issue on Jun 30, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions