Fix the mtime when gzipping in S3Boto3Storage
@@ -389,7 +389,11 @@ class S3Boto3Storage(Storage):
"""Gzip a given string content."""
content.seek(0)
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:
