python / python/cpython

`shutil.copytree` fails on bcachefs case insensitive directories

Open
#144,220 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Linked PRs
  • gh-145869

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review linked PR gh-145869 first, then start at shutil.copytree and _copytree in shutil.py. Reproduce the case-insensitive bcachefs failure using the commands and Python example in the report; done means the reported copy operation handles the filesystem attribute correctly without raising the shown Directory not empty error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.