Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #20780 -- Get rid of stale symlinks when using collectstatic.

Thanks to John Giannelos for the initial patch.
  • Loading branch information...
commit f90be002d9d3c10b87c74741986e2cbf9f2b858e 1 parent 6a9ed7d
@jezdez jezdez authored
View
2  django/contrib/staticfiles/management/commands/collectstatic.py
@@ -275,6 +275,8 @@ def link_file(self, path, prefixed_path, source_storage):
except OSError:
pass
try:
+ if os.path.lexists(full_path):
+ os.unlink(full_path)
os.symlink(source_path, full_path)
except AttributeError:
import platform
View
9 tests/staticfiles_tests/tests.py
@@ -694,6 +694,15 @@ def test_links_created(self):
"""
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):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.