Ticket #20780: 0001-Fix-collectstatic-link-when-dangling-symlink-exists.3.patch

File 0001-Fix-collectstatic-link-when-dangling-symlink-exists.3.patch, 2.0 KB (added by John Giannelos, 11 years ago)
  • django/contrib/staticfiles/management/commands/collectstatic.py

    From db585530c638497e6ed20bfe3ec68a0d306fbb94 Mon Sep 17 00:00:00 2001
    From: John Giannelos <johngiannelos@gmail.com>
    Date: Tue, 19 Nov 2013 19:04:37 +0200
    Subject: [PATCH] Fix collectstatic --link when dangling symlink exists
    
    ---
     django/contrib/staticfiles/management/commands/collectstatic.py | 7 ++++++-
     tests/staticfiles_tests/tests.py                                | 9 +++++++++
     2 files changed, 15 insertions(+), 1 deletion(-)
    
    diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
    index c1e9fa8..0d1bc24 100644
    a b Type 'yes' to continue, or 'no' to cancel: """  
    273273                os.makedirs(os.path.dirname(full_path))
    274274            except OSError:
    275275                pass
    276             os.symlink(source_path, full_path)
     276            try:
     277                if os.path.lexists(full_path):
     278                    os.unlink(full_path)
     279                os.symlink(source_path, full_path)
     280            except OSError:
     281                pass
    277282        if prefixed_path not in self.symlinked_files:
    278283            self.symlinked_files.append(prefixed_path)
    279284
  • tests/staticfiles_tests/tests.py

    diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
    index 39ce498..4c0b5d0 100644
    a b if sys.platform != 'win32':  
    625625            """
    626626            self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt')))
    627627
     628        def test_broken_symlink(self):
     629            """
     630            Test broken symlink gets deleted.
     631            """
     632            path = os.path.join(settings.STATIC_ROOT, 'test.txt')
     633            os.unlink(path)
     634            self.run_collectstatic()
     635            self.assertTrue(os.path.islink(path))
     636
    628637
    629638class TestServeStatic(StaticFilesTestCase):
    630639    """
Back to Top