mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
SF bug 728097: tmpnam problems on windows 2.3b, breaks test.test_os.
tmpnam() appears essentially useless on Windows, and it finally broke the test for Irmen de Jong. Read the long new comment in test_tmpnam() for details. Since the MS implementation is insane, it might be good if we supplied a different implementation. Bugfix candidate.
This commit is contained in:
parent
bf89b3a1f7
commit
5501b5e3d7
2 changed files with 27 additions and 2 deletions
|
|
@ -1025,7 +1025,11 @@ paths returned by \function{tmpnam()}; no automatic cleanup is
|
||||||
provided.
|
provided.
|
||||||
\warning{Use of \function{tmpnam()} is vulnerable to symlink attacks;
|
\warning{Use of \function{tmpnam()} is vulnerable to symlink attacks;
|
||||||
consider using \function{tmpfile()} instead.}
|
consider using \function{tmpfile()} instead.}
|
||||||
Availability: \UNIX, Windows.
|
Availability: \UNIX, Windows. This function probably shouldn't be used
|
||||||
|
on Windows, though: Microsoft's implementation of \function{tmpnam()}
|
||||||
|
always creates a name in the root directory of the current drive, and
|
||||||
|
that's generally a poor location for a temp file (depending on
|
||||||
|
privileges, you may not even be able to open a file using this name).
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{datadesc}{TMP_MAX}
|
\begin{datadesc}{TMP_MAX}
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,32 @@ class TemporaryFileTests(unittest.TestCase):
|
||||||
self.assert_(s == "foobar")
|
self.assert_(s == "foobar")
|
||||||
|
|
||||||
def test_tmpnam(self):
|
def test_tmpnam(self):
|
||||||
|
import sys
|
||||||
if not hasattr(os, "tmpnam"):
|
if not hasattr(os, "tmpnam"):
|
||||||
return
|
return
|
||||||
warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
|
warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
|
||||||
r"test_os$")
|
r"test_os$")
|
||||||
self.check_tempfile(os.tmpnam())
|
name = os.tmpnam()
|
||||||
|
if sys.platform in ("win32",):
|
||||||
|
# The Windows tmpnam() seems useless. From the MS docs:
|
||||||
|
#
|
||||||
|
# The character string that tmpnam creates consists of
|
||||||
|
# the path prefix, defined by the entry P_tmpdir in the
|
||||||
|
# file STDIO.H, followed by a sequence consisting of the
|
||||||
|
# digit characters '0' through '9'; the numerical value
|
||||||
|
# of this string is in the range 1 - 65,535. Changing the
|
||||||
|
# definitions of L_tmpnam or P_tmpdir in STDIO.H does not
|
||||||
|
# change the operation of tmpnam.
|
||||||
|
#
|
||||||
|
# The really bizarre part is that, at least under MSVC6,
|
||||||
|
# P_tmpdir is "\\". That is, the path returned refers to
|
||||||
|
# the root of the current drive. That's a terrible place to
|
||||||
|
# put temp files, and, depending on privileges, the user
|
||||||
|
# may not even be able to open a file in the root directory.
|
||||||
|
self.failIf(os.path.exists(name),
|
||||||
|
"file already exists for temporary file")
|
||||||
|
else:
|
||||||
|
self.check_tempfile(name)
|
||||||
|
|
||||||
# Test attributes on return values from os.*stat* family.
|
# Test attributes on return values from os.*stat* family.
|
||||||
class StatAttributeTests(unittest.TestCase):
|
class StatAttributeTests(unittest.TestCase):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue