summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-20 14:17:42 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-20 14:17:42 (GMT)
commit5235398323aeb40c3fda4ad2daea3beebb6ff11f (patch)
tree9e5be28b182abe13cb1ba64dad171d694517798f /Lib/shutil.py
parent56112895d69131ee4f34d4e3e9406614313df57f (diff)
downloadcpython-5235398323aeb40c3fda4ad2daea3beebb6ff11f.zip
cpython-5235398323aeb40c3fda4ad2daea3beebb6ff11f.tar.gz
cpython-5235398323aeb40c3fda4ad2daea3beebb6ff11f.tar.bz2
#1669: don't allow shutil.rmtree() to be called on a symlink.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index f00f9b7..0a40c57 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -156,6 +156,14 @@ def rmtree(path, ignore_errors=False, onerror=None):
elif onerror is None:
def onerror(*args):
raise
+ try:
+ if os.path.islink(path):
+ # symlinks to directories are forbidden, see bug #1669
+ raise OSError("Cannot call rmtree on a symbolic link")
+ except OSError:
+ onerror(os.path.islink, path, sys.exc_info())
+ # can't continue even if onerror hook returns
+ return
names = []
try:
names = os.listdir(path)