]> granicus.if.org Git - python/commitdiff
Patch #810914: Return absolute path for mkstemp. Fixes #810408.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 12 Oct 2003 17:37:01 +0000 (17:37 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 12 Oct 2003 17:37:01 +0000 (17:37 +0000)
This should not be backported to 2.3, as it might break backwards
compatibility.

Lib/tempfile.py
Lib/test/test_tempfile.py
Misc/NEWS

index 756d8c87273e765cfe3a8b07ce63c69a6682c238..472fd83155b201c78fba655f7061239413408dff 100644 (file)
@@ -214,7 +214,7 @@ def _mkstemp_inner(dir, pre, suf, flags):
         try:
             fd = _os.open(file, flags, 0600)
             _set_cloexec(fd)
-            return (fd, file)
+            return (fd, _os.path.abspath(file))
         except OSError, e:
             if e.errno == _errno.EEXIST:
                 continue # try again
index 8df3856039e77b1b22110e57c5875044a445c5e2..d88d50f6176f5d59242da8779cceade948ca7339 100644 (file)
@@ -49,7 +49,8 @@ class TC(unittest.TestCase):
         npre  = nbase[:len(pre)]
         nsuf  = nbase[len(nbase)-len(suf):]
 
-        self.assertEqual(ndir, dir,
+        # check for equality of the absolute paths!
+        self.assertEqual(os.path.abspath(ndir), os.path.abspath(dir),
                          "file '%s' not in directory '%s'" % (name, dir))
         self.assertEqual(npre, pre,
                          "file '%s' does not begin with '%s'" % (nbase, pre))
@@ -384,6 +385,10 @@ class test_mkstemp(TC):
             dir = tempfile.gettempdir()
         try:
             (fd, name) = tempfile.mkstemp(dir=dir, prefix=pre, suffix=suf)
+            (ndir, nbase) = os.path.split(name)
+            adir = os.path.abspath(dir)
+            self.assertEqual(adir, ndir,
+                "Directory '%s' incorrectly returned as '%s'" % (adir, ndir))
         except:
             self.failOnException("mkstemp")
 
@@ -400,6 +405,7 @@ class test_mkstemp(TC):
         self.do_create(suf="b")
         self.do_create(pre="a", suf="b")
         self.do_create(pre="aa", suf=".txt")
+        self.do_create(dir=".")
 
     def test_choose_directory(self):
         # mkstemp can create directories in a user-selected directory
index 21d0701d0280fa06e97502013fd1618fbfc7abd0..0ee896d5533ced16604c19cf78c6d1958b4bed1b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,8 @@ Extension modules
 Library
 -------
 
+- tmpfile.mkstemp now returns an absolute path even if dir is relative.
+
 - urlparse is RFC 2396 compliant.
 
 - The fieldnames argument to the csv module's DictReader constructor is now