[Python-checkins] cpython (merge 3.4 -> default): Issue #20876: correctly close temporary file in

antoine.pitrou python-checkins at python.org
Sun Mar 8 00:18:35 CET 2015


https://hg.python.org/cpython/rev/5406ed13bd6e
changeset:   94896:5406ed13bd6e
parent:      94894:88a5c1698ca4
parent:      94895:40e8a8e83ed0
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sun Mar 08 00:18:29 2015 +0100
summary:
  Issue #20876: correctly close temporary file in test.support.fs_is_case_insensitive()

files:
  Lib/test/support/__init__.py |  19 +++++++++----------
  1 files changed, 9 insertions(+), 10 deletions(-)


diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2134,16 +2134,15 @@
 
 def fs_is_case_insensitive(directory):
     """Detects if the file system for the specified directory is case-insensitive."""
-    base_fp, base_path = tempfile.mkstemp(dir=directory)
-    case_path = base_path.upper()
-    if case_path == base_path:
-        case_path = base_path.lower()
-    try:
-        return os.path.samefile(base_path, case_path)
-    except FileNotFoundError:
-        return False
-    finally:
-        os.unlink(base_path)
+    with tempfile.NamedTemporaryFile(dir=directory) as base:
+        base_path = base.name
+        case_path = base_path.upper()
+        if case_path == base_path:
+            case_path = base_path.lower()
+        try:
+            return os.path.samefile(base_path, case_path)
+        except FileNotFoundError:
+            return False
 
 
 class SuppressCrashReport:

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list