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
ccab9a6d
Commit
ccab9a6d
authored
Jul 29, 2011
by
Charles-François Natali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12464: tempfile.TemporaryDirectory.cleanup() should not follow symlinks:
fix it. Patch by Petri Lehtinen.
parent
2f5fe8bd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
1 deletion
+27
-1
Lib/tempfile.py
Lib/tempfile.py
+2
-1
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+21
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tempfile.py
View file @
ccab9a6d
...
@@ -661,6 +661,7 @@ class TemporaryDirectory(object):
...
@@ -661,6 +661,7 @@ class TemporaryDirectory(object):
_listdir
=
staticmethod
(
_os
.
listdir
)
_listdir
=
staticmethod
(
_os
.
listdir
)
_path_join
=
staticmethod
(
_os
.
path
.
join
)
_path_join
=
staticmethod
(
_os
.
path
.
join
)
_isdir
=
staticmethod
(
_os
.
path
.
isdir
)
_isdir
=
staticmethod
(
_os
.
path
.
isdir
)
_islink
=
staticmethod
(
_os
.
path
.
islink
)
_remove
=
staticmethod
(
_os
.
remove
)
_remove
=
staticmethod
(
_os
.
remove
)
_rmdir
=
staticmethod
(
_os
.
rmdir
)
_rmdir
=
staticmethod
(
_os
.
rmdir
)
_os_error
=
_os
.
error
_os_error
=
_os
.
error
...
@@ -672,7 +673,7 @@ class TemporaryDirectory(object):
...
@@ -672,7 +673,7 @@ class TemporaryDirectory(object):
for
name
in
self
.
_listdir
(
path
):
for
name
in
self
.
_listdir
(
path
):
fullname
=
self
.
_path_join
(
path
,
name
)
fullname
=
self
.
_path_join
(
path
,
name
)
try
:
try
:
isdir
=
self
.
_isdir
(
fullname
)
isdir
=
self
.
_isdir
(
fullname
)
and
not
self
.
_islink
(
fullname
)
except
self
.
_os_error
:
except
self
.
_os_error
:
isdir
=
False
isdir
=
False
if
isdir
:
if
isdir
:
...
...
Lib/test/test_tempfile.py
View file @
ccab9a6d
...
@@ -964,6 +964,27 @@ class test_TemporaryDirectory(TC):
...
@@ -964,6 +964,27 @@ class test_TemporaryDirectory(TC):
finally
:
finally
:
os
.
rmdir
(
dir
)
os
.
rmdir
(
dir
)
@
support
.
skip_unless_symlink
def
test_cleanup_with_symlink_to_a_directory
(
self
):
# cleanup() should not follow symlinks to directories (issue #12464)
d1
=
self
.
do_create
()
d2
=
self
.
do_create
()
# Symlink d1/foo -> d2
os
.
symlink
(
d2
.
name
,
os
.
path
.
join
(
d1
.
name
,
"foo"
))
# This call to cleanup() should not follow the "foo" symlink
d1
.
cleanup
()
self
.
assertFalse
(
os
.
path
.
exists
(
d1
.
name
),
"TemporaryDirectory %s exists after cleanup"
%
d1
.
name
)
self
.
assertTrue
(
os
.
path
.
exists
(
d2
.
name
),
"Directory pointed to by a symlink was deleted"
)
self
.
assertEqual
(
os
.
listdir
(
d2
.
name
),
[
'test.txt'
],
"Contents of the directory pointed to by a symlink "
"were deleted"
)
d2
.
cleanup
()
@
support
.
cpython_only
@
support
.
cpython_only
def
test_del_on_collection
(
self
):
def
test_del_on_collection
(
self
):
# A TemporaryDirectory is deleted when garbage collected
# A TemporaryDirectory is deleted when garbage collected
...
...
Misc/ACKS
View file @
ccab9a6d
...
@@ -526,6 +526,7 @@ Vincent Legoll
...
@@ -526,6 +526,7 @@ Vincent Legoll
Kip Lehman
Kip Lehman
Joerg Lehmann
Joerg Lehmann
Robert Lehmann
Robert Lehmann
Petri Lehtinen
Luke Kenneth Casson Leighton
Luke Kenneth Casson Leighton
Marc-Andre Lemburg
Marc-Andre Lemburg
John Lenton
John Lenton
...
...
Misc/NEWS
View file @
ccab9a6d
...
@@ -41,6 +41,9 @@ Core and Builtins
...
@@ -41,6 +41,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #12464: tempfile.TemporaryDirectory.cleanup() should not follow
symlinks: fix it. Patch by Petri Lehtinen.
- Issue #8887: "pydoc somebuiltin.somemethod" (or help('somebuiltin.somemethod')
- Issue #8887: "pydoc somebuiltin.somemethod" (or help('somebuiltin.somemethod')
in Python code) now finds the doc of the method.
in Python code) now finds the doc of the method.
...
...
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