[PATCH stable] archival: don't set gzip filename header when there's no filename

Brodie Rao brodie at bitheap.org
Tue Dec 7 02:55:04 CST 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1291711673 -39600
# Branch stable
# Node ID 9254f1fe8d7198959b13cdc3d88d2c4fde89d133
# Parent  5e51254ad4d4c80669f462e310b2677f2b3c54a7
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

diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -70,6 +70,8 @@ class tarit(object):
             self.fileobj.write('\010')                 # compression method
             # Python 2.6 deprecates self.filename
             fname = getattr(self, 'name', None) or self.filename
+            if fname and fname.endswith('.gz'):
+                fname = fname[:-3]
             flags = 0
             if fname:
                 flags = gzip.FNAME


More information about the Mercurial-devel mailing list