From 6478e07a62ce968f33e71a345e561bce36923f8e Mon Sep 17 00:00:00 2001 From: Chillar Anand Date: Fri, 27 Jan 2017 00:24:16 +0530 Subject: Refs #23919 -- Replaced tempfile.mkdtemp() with TemporaryDirectory() context manager. --- django/utils/_os.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'django/utils') diff --git a/django/utils/_os.py b/django/utils/_os.py index 8309e08fbf..937ba82fbc 100644 --- a/django/utils/_os.py +++ b/django/utils/_os.py @@ -56,18 +56,13 @@ def symlinks_supported(): host platform and/or if they are allowed to be created (e.g. on Windows it requires admin permissions). """ - tmpdir = tempfile.mkdtemp() - original_path = os.path.join(tmpdir, 'original') - symlink_path = os.path.join(tmpdir, 'symlink') - os.makedirs(original_path) - try: - os.symlink(original_path, symlink_path) - supported = True - except (OSError, NotImplementedError, AttributeError): - supported = False - else: - os.remove(symlink_path) - finally: - os.rmdir(original_path) - os.rmdir(tmpdir) + with tempfile.TemporaryDirectory() as temp_dir: + original_path = os.path.join(temp_dir, 'original') + symlink_path = os.path.join(temp_dir, 'symlink') + os.makedirs(original_path) + try: + os.symlink(original_path, symlink_path) + supported = True + except (OSError, NotImplementedError): + supported = False return supported -- cgit v1.3