Mercurial > hg
comparison mercurial/archival.py @ 13102:2956945c3bee stable
archival: don't set gzip filename header when there's no filename
This mainly affects hgweb, which can generate tar.gz archives without
filenames. Without this change, the header would be set to ".gz",
which can confuse Safari into extracting the file and renaming it to
"gz" when "Open 'safe' files after downloading" is enabled.
file(1) before:
hg-crew-5e51254ad4d4.tar.gz: gzip compressed data, was ".gz", last modified: Thu Dec 2 11:46:20 2010, max compression
after:
hg-crew-5e51254ad4d4.tar.gz: gzip compressed data, last modified: Thu Dec 2 11:46:20 2010, max compression
author | Brodie Rao <brodie@bitheap.org> |
---|---|
date | Tue, 07 Dec 2010 19:47:53 +1100 |
parents | f00953d9533c |
children | 5dac0d04b838 |
comparison
equal
deleted
inserted
replaced
13100:66d7a1250c9b | 13102:2956945c3bee |
---|---|
68 def _write_gzip_header(self): | 68 def _write_gzip_header(self): |
69 self.fileobj.write('\037\213') # magic header | 69 self.fileobj.write('\037\213') # magic header |
70 self.fileobj.write('\010') # compression method | 70 self.fileobj.write('\010') # compression method |
71 # Python 2.6 deprecates self.filename | 71 # Python 2.6 deprecates self.filename |
72 fname = getattr(self, 'name', None) or self.filename | 72 fname = getattr(self, 'name', None) or self.filename |
73 if fname and fname.endswith('.gz'): | |
74 fname = fname[:-3] | |
73 flags = 0 | 75 flags = 0 |
74 if fname: | 76 if fname: |
75 flags = gzip.FNAME | 77 flags = gzip.FNAME |
76 self.fileobj.write(chr(flags)) | 78 self.fileobj.write(chr(flags)) |
77 gzip.write32u(self.fileobj, long(self.timestamp)) | 79 gzip.write32u(self.fileobj, long(self.timestamp)) |