Skip to content

shutil.copyfile raises SpecialFileError for symlink to fifo #81882

Open

Description

@chrahunt
mannequin
BPO 37701
Nosy @eryksun, @chrahunt
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:36:51.237>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'shutil.copyfile raises SpecialFileError for symlink to fifo'
    updated_at = <Date 2021-12-15.03:45:07.003>
    user = 'https://github.com/chrahunt'

    bugs.python.org fields:

    activity = <Date 2021-12-15.03:45:07.003>
    actor = 'chrahunt'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-07-29.04:36:51.237>
    creator = 'chrahunt'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37701
    keywords = ['patch']
    message_count = 4.0
    messages = ['348597', '348598', '408346', '408584']
    nosy_count = 2.0
    nosy_names = ['eryksun', 'chrahunt']
    pr_nums = ['16575']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37701'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. chrahunt commented on Jul 29, 2019

      chrahuntmannequin
      MannequinAuthor

      Currently shutil.copyfile raises SpecialFileError when src is a link to a fifo. To reproduce:

          import os
          import shutil
          import tempfile
          
          
          d = tempfile.mkdtemp()
          fifo = os.path.join(d, 'fifo')
          link_to_fifo = os.path.join(d, 'link-to-fifo')
          copy_of_link_to_fifo = os.path.join(d, 'copy-of-link-to-fifo')
          
          
          os.mkfifo(fifo)
          os.symlink(fifo, link_to_fifo)
          shutil.copyfile(link_to_fifo, copy_of_link_to_fifo)

      Example output:

          Traceback (most recent call last):
            File "repro.py", line 14, in <module>
              shutil.copyfile(link_to_fifo, copy_of_link_to_fifo)
            File "/home/chris/.pyenv/versions/3.7.2/lib/python3.7/shutil.py", line 115, in copyfile
              raise SpecialFileError("`%s` is a named pipe" % fn)
          shutil.SpecialFileError: `/tmp/user/1000/tmpxhigll5g/link-to-fifo` is a named pipe

      I would have expected this to copy the symlink without complaint. Raising a SpecialFileError would be OK if follow_symlinks was False.

    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

      Likewise when the destination is a symlink - though in that case the value of follow_symlinks should probably not matter.

    4. eryksun commented on Dec 11, 2021

      @eryksun
      Contributor

      Raising a SpecialFileError would be OK if follow_symlinks was False.

      I expect it to fail if follow_symlinks is True, which is the default value. I expect it to succeed with follow_symlinks=False, which should create a shallow copy of just the symlink, regardless of its target. Instead, what happens is that it calls shutil._stat(fn) on both src and dst, regardless of follow_symlinks. I think the call should be shutil._stat(fn, follow_symlinks). This requires updating shutil._stat() to pass the value to fn.stat() and os.stat().

    5. chrahunt commented on Dec 15, 2021

      chrahuntmannequin
      MannequinAuthor

      I expect it to fail if follow_symlinks is True, which is the default value. I expect it to succeed with follow_symlinks=False, which should create a shallow copy of just the symlink, regardless of its target.

      I agree, thanks for the correction.

    6. transferred this issue fromon Apr 10, 2022
    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

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard 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