misc: skip unmodified files in collectstatic (#27025)

This commit is contained in:
Frédéric Péters 2018-10-07 12:10:14 +02:00
parent 6a75f590be
commit c017939e20
1 changed files with 11 additions and 2 deletions

View File

@ -57,11 +57,20 @@ class Command(BaseCommand):
for filename in filenames:
dst_path = os.path.join(dst_base, basedir[len(directory)+1:])
dst_filename = os.path.join(dst_path, filename)
src_filename = os.path.join(basedir, filename)
src_mtime = int(os.stat(src_filename).st_mtime)
try:
dst_mtime = int(os.stat(dst_filename).st_mtime)
except OSError:
dst_mtime = 0
if src_mtime <= dst_mtime:
continue
if not os.path.exists(dst_path):
os.makedirs(dst_path)
if os.path.exists(dst_filename):
os.unlink(dst_filename)
if link:
os.symlink(os.path.join(basedir, filename), dst_filename)
os.symlink(src_filename, dst_filename)
else:
shutil.copy(os.path.join(basedir, filename), dst_filename)
shutil.copy2(src_filename, dst_filename)
os.utime(dst_filename, (src_mtime, src_mtime))