Commit 0922bbf1 authored by Yusuke Miyazaki's avatar Yusuke Miyazaki Committed by Tim Graham
Browse files

Fixed #25346 -- Allowed collectstatic to delete broken symlinks.

parent a3fffdca
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -218,6 +218,11 @@ class Command(BaseCommand):
                         smart_text(fpath), level=1)
            else:
                self.log("Deleting '%s'" % smart_text(fpath), level=1)
                full_path = self.storage.path(fpath)
                if not os.path.exists(full_path) and os.path.lexists(full_path):
                    # Delete broken symlinks
                    os.unlink(full_path)
                else:
                    self.storage.delete(fpath)
        for d in dirs:
            self.clear_dir(os.path.join(path, d))
+12 −2
Original line number Diff line number Diff line
@@ -323,8 +323,8 @@ class TestCollectionLinks(CollectionTestCase, TestDefaults):
    the standard file resolving tests here, to make sure using
    ``--link`` does not change the file-selection semantics.
    """
    def run_collectstatic(self):
        super(TestCollectionLinks, self).run_collectstatic(link=True)
    def run_collectstatic(self, clear=False):
        super(TestCollectionLinks, self).run_collectstatic(link=True, clear=clear)

    def test_links_created(self):
        """
@@ -340,3 +340,13 @@ class TestCollectionLinks(CollectionTestCase, TestDefaults):
        os.unlink(path)
        self.run_collectstatic()
        self.assertTrue(os.path.islink(path))

    def test_clear_broken_symlink(self):
        """
        With ``--clear``, broken symbolic links are deleted.
        """
        nonexistent_file_path = os.path.join(settings.STATIC_ROOT, 'nonexistent.txt')
        broken_symlink_path = os.path.join(settings.STATIC_ROOT, 'symlink.txt')
        os.symlink(nonexistent_file_path, broken_symlink_path)
        self.run_collectstatic(clear=True)
        self.assertFalse(os.path.lexists(broken_symlink_path))