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

Thanks to John Giannelos for the initial patch.
This commit is contained in:
Jannis Leidel 2014-02-09 14:48:11 +00:00
parent 6a9ed7d403
commit f90be002d9
2 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -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):
"""