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
e7eaa9e2
Commit
e7eaa9e2
authored
Jun 19, 2004
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shutil.move() will raise an exception when trying to move a directory into
itself. Closes bug #919012 . Thanks Johannes Gijsbers.
parent
35600731
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
2 deletions
+24
-2
Lib/shutil.py
Lib/shutil.py
+6
-0
Lib/test/test_shutil.py
Lib/test/test_shutil.py
+14
-2
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/shutil.py
View file @
e7eaa9e2
...
...
@@ -8,6 +8,7 @@ import os
import
sys
import
stat
import
exceptions
from
os.path
import
abspath
__all__
=
[
"copyfileobj"
,
"copyfile"
,
"copymode"
,
"copystat"
,
"copy"
,
"copy2"
,
"copytree"
,
"move"
,
"rmtree"
,
"Error"
]
...
...
@@ -164,8 +165,13 @@ def move(src, dst):
os
.
rename
(
src
,
dst
)
except
OSError
:
if
os
.
path
.
isdir
(
src
):
if
destinsrc
(
src
,
dst
):
raise
Error
,
"Cannot move a directory '%s' into itself '%s'."
%
(
src
,
dst
)
copytree
(
src
,
dst
,
symlinks
=
True
)
rmtree
(
src
)
else
:
copy2
(
src
,
dst
)
os
.
unlink
(
src
)
def
destinsrc
(
src
,
dst
):
return
abspath
(
dst
).
startswith
(
abspath
(
src
))
Lib/test/test_shutil.py
View file @
e7eaa9e2
...
...
@@ -3,6 +3,8 @@
import
unittest
import
shutil
import
tempfile
import
os
import
os.path
from
test
import
test_support
class
TestShutil
(
unittest
.
TestCase
):
...
...
@@ -12,11 +14,21 @@ class TestShutil(unittest.TestCase):
self
.
assertRaises
(
OSError
,
shutil
.
rmtree
,
filename
)
self
.
assertEqual
(
shutil
.
rmtree
(
filename
,
True
),
None
)
def
test_dont_move_dir_in_itself
(
self
):
src_dir
=
tempfile
.
mkdtemp
()
try
:
dst
=
os
.
path
.
join
(
src_dir
,
'foo'
)
self
.
assertRaises
(
shutil
.
Error
,
shutil
.
move
,
src_dir
,
dst
)
finally
:
try
:
os
.
rmdir
(
src_dir
)
except
:
pass
def
test_main
():
test_support
.
run_unittest
(
TestShutil
)
if
__name__
==
'__main__'
:
test_main
()
Misc/ACKS
View file @
e7eaa9e2
...
...
@@ -205,6 +205,7 @@ Christos Georgiou
Ben Gertzfield
Dinu Gherman
Jonathan Giddy
Johannes Gijsbers
Michael Gilfix
Chris Gonnerman
David Goodger
...
...
Misc/NEWS
View file @
e7eaa9e2
...
...
@@ -340,6 +340,9 @@ Extension modules
Library
-------
- Bug #919012: shutil.move() will not try to move a directory into itself.
Thanks Johannes Gijsbers.
- Bug #934282: pydoc.stripid() is now case-insensitive. Thanks Robin Becker.
- Bug #823209: cmath.log() now takes an optional base argument so that its
...
...
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