Skip to content

shutil.copyfile() rejects device symlinks with follow_symlinks=False #154726

Description

@lkk7

Bug report

Bug description:

I think it's a regression from #142693.

copyfile() rejects a symlink to a device even when follow_symlinks=False.

import os
import shutil
import tempfile

with tempfile.TemporaryDirectory() as directory:
    src = os.path.join(directory, "src")
    dst = os.path.join(directory, "dst")
    os.symlink("/dev/null", src)
    shutil.copyfile(src, dst, follow_symlinks=False)
  • Current behavior: shutil.SpecialFileError: .../src is a character device
  • Expected: dst is created as a symlink to /dev/null

The docs say:

If follow_symlinks is false and src is a symbolic link, a new symbolic link will be created instead of copying the file src points to.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions