mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
shutil.move() will raise an exception when trying to move a directory into
itself. Closes bug #919012 . Thanks Johannes Gijsbers.
This commit is contained in:
parent
b46ed71d70
commit
1c3fa18be7
4 changed files with 24 additions and 2 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue