diff options
author | Brett Cannon <bcannon@gmail.com> | 2004-06-19 21:11:35 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2004-06-19 21:11:35 (GMT) |
commit | 1c3fa18be76d1bcddb2de516913f46a32c5ed860 (patch) | |
tree | 475daa275d1e5576db99336f2397f6318f0275ea /Lib/shutil.py | |
parent | b46ed71d706d2f94552e13664c08706421263856 (diff) | |
download | cpython-1c3fa18be76d1bcddb2de516913f46a32c5ed860.zip cpython-1c3fa18be76d1bcddb2de516913f46a32c5ed860.tar.gz cpython-1c3fa18be76d1bcddb2de516913f46a32c5ed860.tar.bz2 |
shutil.move() will raise an exception when trying to move a directory into
itself.
Closes bug #919012 . Thanks Johannes Gijsbers.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 5341786..10b7a27 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -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)) |