Skip to content

shutil.copytree fails on bcachefs case insensitive directories #144220

@neVERberleRfellerER

Description

@neVERberleRfellerER

Bug report

Bug description:

On bcachefs create case insensitive directory with some file inside:

mkdir ncs
chattr +F ncs
touch ncs/something.txt

then do this

import shutil
shutil.copytree("ncs/", "target/")

fails with

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import shutil; shutil.copytree("ncs/", "target/")
                   ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/shutil.py", line 654, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
                     ignore=ignore, copy_function=copy_function,
                     ignore_dangling_symlinks=ignore_dangling_symlinks,
                     dirs_exist_ok=dirs_exist_ok)
  File "/usr/lib/python3.14/shutil.py", line 608, in _copytree
    raise Error(errors)
shutil.Error: [('ncs/', 'target/', "[Errno 39] Directory not empty: 'target/'")]

This is because of

listxattr("ncs/", "bcachefs.casefold\0bcachefs_effec"..., 256) = 46
getxattr("ncs/", "bcachefs.casefold", "1", 128) = 1
setxattr("target/", "bcachefs.casefold", "1", 1, 0) = -1 ENOTEMPTY (Directory not empty)
getcwd("/home/user/_x", 1024)           = 14

happening after contents were copied and case insensitivity can't be enabled afterwards.
Note: On ext4 copytree results in a directory without casefolding flag.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

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