New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shutil.copytree doesn't seem to understand NTFS junctions, can truncates files when tricked #104046
Comments
A junction is like a Unix bind mount point. So, for comparison, let's take a look at the behavior of #!/usr/bin/bash
# repro.sh
# Create some important files
mkdir source
echo 'print("world")' > source/hello.py
# Create a project with a bind mount to the source folder
mkdir -p project1/test
mount --bind source project1/test
# Create a second project with a bind mount to the source folder
mkdir -p project2/test
mount --bind source project2/test
ls -1shR > before.txt
# Case 1: Copy project1 to a whole new folder.
# This will copy the files, but will lose the mount point even though we asked
# to copy symlinks. After the copy project3/test/hello.py and source/hello.py
# will be individual files; changes to one do not affect the other.
python -c 'import shutil; shutil.copytree("project1", "project3", dirs_exist_ok=True, symlinks=True)'
ls -1shR > case1.txt
# Case 2: Copy 2 folders with identical bind mounts already in place on top of
# each other. This fails because the _samefile(src, dst) call in
# shutil.copyfile() is true for "hello.py".
python -c 'import shutil; shutil.copytree("project1", "project2", dirs_exist_ok=True, symlinks=True)'
ls -1shR > case2.txt
umount project1/test
umount project2/test As expected for case 1,
For case 2, on the other hand, trying to copy the "project1" bind mount onto the "project2" bind mount fails because "hello.py" is the same file.
Aside from the bad formatting of the error message, the interesting part is that it's comparing a source path that's an Lines 204 to 216 in d448fcb
On Windows, the values of On Windows, Footnotes
|
Note that if the Windows batch script is changed to use |
Bug report
Minimal repro extracted from Blender Issue #99766 , When copying a folder containing a directory junction some odd behavior can be observed.
When called with
symlinks=True
when copying a folder, the junction will be lost even though the documentation statesIf symlinks is true, symbolic links in the source tree are represented as symbolic links in the new tree and the metadata of the original links will be copied as far as the platform allows;
while junctions vs symlinks generally can lead to a passionate debate which, for the sake of simplicity i'd like to skip over, and rather compare the behavior to the build in copy tools in windows, xcopy also loses the junction, so while it's inconvenient it's not completely unexpected behavior,shutil.copytree
gets a pass here in my book.However... there is some destructive behavior
shutil.copytree
has xcopy does not, when copying to folders on top of each other with both already containing a junction point pointing to the same folder.with a directory structure like this
When calling
shutil.copytree
to copyProject1
on top ofProject2
it will try to create a new fileProject2/test/Hello.py
which truncates the originalsource/Hello.py
which is a bit more destructive than I would have liked.Repro:
While the example is squarely in the "seems far fetched, why would you even do that!?" category, sadly this was extracted from a real life scenario where people did lose their work Blender Issue #99766
Your environment
The text was updated successfully, but these errors were encountered: