Skip to content

Commit

Permalink
Fix the mtime when gzipping in S3Boto3Storage (jschneier#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
rehandalal authored and nitely committed Jul 30, 2018
1 parent d70ac77 commit 903cfe7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ def _compress_content(self, content):
"""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:
Expand Down

0 comments on commit 903cfe7

Please sign in to comment.