From 16278c58d114f6c960e67b8eb65d0f4edba8f35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 7 Oct 2018 12:10:14 +0200 Subject: [PATCH] misc: skip unmodified files in collectstatic (#27025) --- wcs/qommon/management/commands/collectstatic.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wcs/qommon/management/commands/collectstatic.py b/wcs/qommon/management/commands/collectstatic.py index d7fe8a451..e4c11f30f 100644 --- a/wcs/qommon/management/commands/collectstatic.py +++ b/wcs/qommon/management/commands/collectstatic.py @@ -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)) -- 2.19.1