From 87d78241a2fc85e5715fb51c554fe06e91deee58 Mon Sep 17 00:00:00 2001 From: Sztrovacsek Date: Sat, 7 Mar 2015 14:15:26 +0100 Subject: [PATCH] Fixed #23986 -- Fixed collectstatic --clear failure if STATIC_ROOT dir doesn't exist. --- .../contrib/staticfiles/management/commands/collectstatic.py | 3 +++ tests/staticfiles_tests/tests.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index 1ed7127f96..0c3f4e15fd 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -199,6 +199,9 @@ class Command(BaseCommand): """ Deletes the given relative path using the destination storage backend. """ + if not self.storage.exists(path): + return + dirs, files = self.storage.listdir(path) for f in files: fpath = os.path.join(path, f) diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index c65187d132..9cfabecbb2 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -301,6 +301,10 @@ class TestCollectionClear(CollectionTestCase): def test_cleared_not_found(self): self.assertFileNotFound('cleared.txt') + def test_dir_not_exists(self, **kwargs): + shutil.rmtree(settings.STATIC_ROOT) + super(TestCollectionClear, self).run_collectstatic(clear=True) + class TestCollectionExcludeNoDefaultIgnore(CollectionTestCase, TestDefaults): """