Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
591ec3a9
Commit
591ec3a9
authored
Jul 25, 2015
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21697: shutil.copytree() now correctly handles symbolic links that point to directories.
Patch by Eduardo Seabra and Thomas Kluyver.
parent
daf14ad2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
Lib/shutil.py
Lib/shutil.py
+5
-1
Lib/test/test_shutil.py
Lib/test/test_shutil.py
+20
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/shutil.py
View file @
591ec3a9
...
...
@@ -321,7 +321,11 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
if
not
os
.
path
.
exists
(
linkto
)
and
ignore_dangling_symlinks
:
continue
# otherwise let the copy occurs. copy2 will raise an error
copy_function
(
srcname
,
dstname
)
if
os
.
path
.
isdir
(
srcname
):
copytree
(
srcname
,
dstname
,
symlinks
,
ignore
,
copy_function
)
else
:
copy_function
(
srcname
,
dstname
)
elif
os
.
path
.
isdir
(
srcname
):
copytree
(
srcname
,
dstname
,
symlinks
,
ignore
,
copy_function
)
else
:
...
...
Lib/test/test_shutil.py
View file @
591ec3a9
...
...
@@ -895,6 +895,26 @@ class TestShutil(unittest.TestCase):
shutil
.
copytree
(
src_dir
,
dst_dir
,
symlinks
=
True
)
self
.
assertIn
(
'test.txt'
,
os
.
listdir
(
dst_dir
))
@
support
.
skip_unless_symlink
def
test_copytree_symlink_dir
(
self
):
src_dir
=
self
.
mkdtemp
()
dst_dir
=
os
.
path
.
join
(
self
.
mkdtemp
(),
'destination'
)
os
.
mkdir
(
os
.
path
.
join
(
src_dir
,
'real_dir'
))
with
open
(
os
.
path
.
join
(
src_dir
,
'real_dir'
,
'test.txt'
),
'w'
):
pass
os
.
symlink
(
os
.
path
.
join
(
src_dir
,
'real_dir'
),
os
.
path
.
join
(
src_dir
,
'link_to_dir'
),
target_is_directory
=
True
)
shutil
.
copytree
(
src_dir
,
dst_dir
,
symlinks
=
False
)
self
.
assertFalse
(
os
.
path
.
islink
(
os
.
path
.
join
(
dst_dir
,
'link_to_dir'
)))
self
.
assertIn
(
'test.txt'
,
os
.
listdir
(
os
.
path
.
join
(
dst_dir
,
'link_to_dir'
)))
dst_dir
=
os
.
path
.
join
(
self
.
mkdtemp
(),
'destination2'
)
shutil
.
copytree
(
src_dir
,
dst_dir
,
symlinks
=
True
)
self
.
assertTrue
(
os
.
path
.
islink
(
os
.
path
.
join
(
dst_dir
,
'link_to_dir'
)))
self
.
assertIn
(
'test.txt'
,
os
.
listdir
(
os
.
path
.
join
(
dst_dir
,
'link_to_dir'
)))
def
_copy_file
(
self
,
method
):
fname
=
'test.txt'
tmpdir
=
self
.
mkdtemp
()
...
...
Misc/NEWS
View file @
591ec3a9
...
...
@@ -66,6 +66,9 @@ Core and Builtins
Library
-------
-
Issue
#
21697
:
shutil
.
copytree
()
now
correctly
handles
symbolic
links
that
point
to
directories
.
Patch
by
Eduardo
Seabra
and
Thomas
Kluyver
.
-
Issue
#
24620
:
Random
.
setstate
()
now
validates
the
value
of
state
last
element
.
-
Issue
#
22153
:
Improve
unittest
docs
.
Patch
from
Martin
Panter
and
evilzero
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment