Fixed #17737 -- Stopped the collectstatic management command from copying the wrong file in repeated runs. Thanks, pigletto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17612 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2012-03-01 23:02:38 +00:00
parent 4557058083
commit 1c33c0a02a
2 changed files with 63 additions and 4 deletions

View File

@ -107,6 +107,8 @@ class Command(NoArgsCommand):
prefixed_path = os.path.join(storage.prefix, path) prefixed_path = os.path.join(storage.prefix, path)
else: else:
prefixed_path = path prefixed_path = path
if prefixed_path not in found_files:
found_files[prefixed_path] = (storage, path) found_files[prefixed_path] = (storage, path)
handler(path, prefixed_path, storage) handler(path, prefixed_path, storage)
@ -207,7 +209,9 @@ Type 'yes' to continue, or 'no' to cancel: """
self.clear_dir(os.path.join(path, d)) self.clear_dir(os.path.join(path, d))
def delete_file(self, path, prefixed_path, source_storage): def delete_file(self, path, prefixed_path, source_storage):
# Checks if the target file should be deleted if it already exists """
Checks if the target file should be deleted if it already exists
"""
if self.storage.exists(prefixed_path): if self.storage.exists(prefixed_path):
try: try:
# When was the target file modified last time? # When was the target file modified last time?

View File

@ -286,6 +286,61 @@ class TestCollectionDryRun(CollectionTestCase, TestNoFilesCreated):
super(TestCollectionDryRun, self).run_collectstatic(dry_run=True) super(TestCollectionDryRun, self).run_collectstatic(dry_run=True)
class TestCollectionFilesOverride(CollectionTestCase):
"""
Test overriding duplicated files by ``collectstatic`` management command.
Check for proper handling of apps order in INSTALLED_APPS even if file modification
dates are in different order:
'regressiontests.staticfiles_tests.apps.test',
'regressiontests.staticfiles_tests.apps.no_label',
"""
def setUp(self):
self.orig_path = os.path.join(TEST_ROOT, 'apps', 'no_label', 'static', 'file2.txt')
# get modification and access times for no_label/static/file2.txt
self.orig_mtime = os.path.getmtime(self.orig_path)
self.orig_atime = os.path.getatime(self.orig_path)
# prepare duplicate of file2.txt from no_label app
# this file will have modification time older than no_label/static/file2.txt
# anyway it should be taken to STATIC_ROOT because 'test' app is before
# 'no_label' app in INSTALLED_APPS
self.testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt')
with open(self.testfile_path, 'w+') as f:
f.write('duplicate of file2.txt')
os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
super(TestCollectionFilesOverride, self).setUp()
def tearDown(self):
if os.path.exists(self.testfile_path):
os.unlink(self.testfile_path)
# set back original modification time
os.utime(self.orig_path, (self.orig_atime, self.orig_mtime))
def test_ordering_override(self):
"""
Test if collectstatic takes files in proper order
"""
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
# run collectstatic again
self.run_collectstatic()
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
# and now change modification time of no_label/static/file2.txt
# test app is first in INSTALLED_APPS so file2.txt should remain unmodified
mtime = os.path.getmtime(self.testfile_path)
atime = os.path.getatime(self.testfile_path)
os.utime(self.orig_path, (mtime + 1, atime + 1))
# run collectstatic again
self.run_collectstatic()
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated): class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
""" """
Tests for #15035 Tests for #15035
@ -314,7 +369,7 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
"does/not/exist.png", "does/not/exist.png",
"/static/does/not/exist.png") "/static/does/not/exist.png")
self.assertStaticRenders("test/file.txt", self.assertStaticRenders("test/file.txt",
"/static/test/file.ea5bccaf16d5.txt") "/static/test/file.dad0999e4f8f.txt")
self.assertStaticRenders("cached/styles.css", self.assertStaticRenders("cached/styles.css",
"/static/cached/styles.93b1147e8552.css") "/static/cached/styles.93b1147e8552.css")
self.assertStaticRenders("path/", self.assertStaticRenders("path/",