From c688460df6239539d2b5a1fc8c51778086fe7c35 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 22 Feb 2015 17:49:29 +0100 Subject: [PATCH] Removed rmtree_errorhandler. The stated reason for its introduction in d18d37ce no longer applies since Django's code repository was switched from Subversion to git. Furthermore it never had any effect because shutil.rmtree ignores its onerror argument when ignore_errors is True. The reason for its use in template management commands is unclear. --- django/core/management/templates.py | 4 +--- django/utils/_os.py | 27 --------------------------- tests/staticfiles_tests/tests.py | 6 ++---- 3 files changed, 3 insertions(+), 34 deletions(-) diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 6648fafde9..22391c721e 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -15,7 +15,6 @@ from django.core.management.base import BaseCommand, CommandError from django.core.management.utils import handle_extensions from django.template import Context, Template from django.utils import archive -from django.utils._os import rmtree_errorhandler from django.utils.six.moves.urllib.request import urlretrieve from django.utils.version import get_docs_version @@ -172,8 +171,7 @@ class TemplateCommand(BaseCommand): if path.isfile(path_to_remove): os.remove(path_to_remove) else: - shutil.rmtree(path_to_remove, - onerror=rmtree_errorhandler) + shutil.rmtree(path_to_remove) def handle_template(self, template, subdir): """ diff --git a/django/utils/_os.py b/django/utils/_os.py index f5efeab80f..a874214a58 100644 --- a/django/utils/_os.py +++ b/django/utils/_os.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import os -import stat import sys import tempfile from os.path import abspath, dirname, isabs, join, normcase, normpath, sep @@ -10,12 +9,6 @@ from django.core.exceptions import SuspiciousFileOperation from django.utils import six from django.utils.encoding import force_text -try: - WindowsError = WindowsError -except NameError: - class WindowsError(Exception): - pass - if six.PY2: fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() @@ -86,26 +79,6 @@ def safe_join(base, *paths): return final_path -def rmtree_errorhandler(func, path, exc_info): - """ - On Windows, some files are read-only (e.g. in in .svn dirs), so when - rmtree() tries to remove them, an exception is thrown. - We catch that here, remove the read-only attribute, and hopefully - continue without problems. - """ - exctype, value = exc_info[:2] - # looking for a windows error - if exctype is not WindowsError or 'Access is denied' not in str(value): - raise - # file type should currently be read only - if ((os.stat(path).st_mode & stat.S_IREAD) != stat.S_IREAD): - raise - # convert to read/write - os.chmod(path, stat.S_IWRITE) - # use the original function to repeat the operation - func(path) - - def symlinks_supported(): """ A function to check if creating symlinks are supported in the diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index 9f5635a8c2..eafbdc9b9f 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -20,7 +20,7 @@ from django.core.management import call_command from django.template import Context, Template from django.test import TestCase, override_settings from django.utils import six -from django.utils._os import rmtree_errorhandler, symlinks_supported, upath +from django.utils._os import symlinks_supported, upath from django.utils.encoding import force_text from django.utils.functional import empty @@ -106,9 +106,7 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase): self.patched_settings = self.settings(STATIC_ROOT=temp_dir) self.patched_settings.enable() self.run_collectstatic() - # Use our own error handler that can handle .svn dirs on Windows - self.addCleanup(shutil.rmtree, temp_dir, - ignore_errors=True, onerror=rmtree_errorhandler) + self.addCleanup(shutil.rmtree, temp_dir) def tearDown(self): self.patched_settings.disable()