summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2014-02-09 14:48:11 +0000
committerJannis Leidel <jannis@leidel.info>2014-02-09 14:48:11 +0000
commitf90be002d9d3c10b87c74741986e2cbf9f2b858e (patch)
tree4ed6b418bdfb0a3d52661395e4440a93cc25f1b1
parent6a9ed7d403a5f90a7c7354097aae99b74e8ce215 (diff)
Fixed #20780 -- Get rid of stale symlinks when using collectstatic.
Thanks to John Giannelos for the initial patch.
-rw-r--r--django/contrib/staticfiles/management/commands/collectstatic.py2
-rw-r--r--tests/staticfiles_tests/tests.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
index 02e95d56b9..a820fed638 100644
--- a/django/contrib/staticfiles/management/commands/collectstatic.py
+++ b/django/contrib/staticfiles/management/commands/collectstatic.py
@@ -275,6 +275,8 @@ class Command(NoArgsCommand):
except OSError:
pass
try:
+ if os.path.lexists(full_path):
+ os.unlink(full_path)
os.symlink(source_path, full_path)
except AttributeError:
import platform
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
index 9261503726..95852acd09 100644
--- a/tests/staticfiles_tests/tests.py
+++ b/tests/staticfiles_tests/tests.py
@@ -694,6 +694,15 @@ class TestCollectionLinks(CollectionTestCase, TestDefaults):
"""
self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt')))
+ def test_broken_symlink(self):
+ """
+ Test broken symlink gets deleted.
+ """
+ path = os.path.join(settings.STATIC_ROOT, 'test.txt')
+ os.unlink(path)
+ self.run_collectstatic()
+ self.assertTrue(os.path.islink(path))
+
class TestServeStatic(StaticFilesTestCase):
"""