From b744e1c9be2f6d4ed82830d66bd8b72530ffcca1 Mon Sep 17 00:00:00 2001 From: Rehan Dalal Date: Mon, 31 Jul 2017 14:25:47 -0400 Subject: [PATCH] Fix the mtime when gzipping in S3Boto3Storage --- storages/backends/s3boto3.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/storages/backends/s3boto3.py b/storages/backends/s3boto3.py index 727782f76..4f3ae7062 100644 --- a/storages/backends/s3boto3.py +++ b/storages/backends/s3boto3.py @@ -388,7 +388,11 @@ def _decode_name(self, name): def _compress_content(self, content): """Gzip a given string content.""" zbuf = BytesIO() - zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf) + # The GZIP header has a modification time attribute (see http://www.zlib.org/rfc-gzip.html) + # This means each time a file is compressed it changes even if the other contents don't change + # For S3 this defeats detection of changes using MD5 sums on gzipped files + # Fixing the mtime at 0.0 at compression time avoids this problem + zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf, mtime=0.0) try: zfile.write(force_bytes(content.read())) finally: