[Rpm-metadata] [PATCH] Exclude filename from .gz files

Elia Pinto gitter.spiros at gmail.com
Tue Nov 29 09:58:31 UTC 2011


From: Elia Pinto <yersinia.spiros at gmail.com>

When you run createrepo, the original filenames,
including full path, of the files are stored
in the header of the .gz metadata

The path becomes part of the checksum of the gzip file
itself.  So, if you gunzip the file and re-gzip it,
you get a different checksum.

Based on the original observation of Dennis Gregorovic
---
 createrepo/utils.py |   20 ++++++--------------
 1 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/createrepo/utils.py b/createrepo/utils.py
index c5cec64..d52d070 100644
--- a/createrepo/utils.py
+++ b/createrepo/utils.py
@@ -40,22 +40,14 @@ def _(args):
 
 class GzipFile(gzip.GzipFile):
     def _write_gzip_header(self):
+        # Generate a header that is easily reproduced with gzip -9 -n on
+        # an unix-like system
         self.fileobj.write('\037\213')             # magic header
         self.fileobj.write('\010')                 # compression method
-        if hasattr(self, 'name'):
-            fname = self.name[:-3]
-        else:
-            fname = self.filename[:-3]
-        flags = 0
-        if fname:
-            flags = FNAME
-        self.fileobj.write(chr(flags))
-        write32u(self.fileobj, long(0))
-        self.fileobj.write('\002')
-        self.fileobj.write('\377')
-        if fname:
-            self.fileobj.write(fname + '\000')
-
+        self.fileobj.write('\000')                 # flags
+        write32u(self.fileobj, long(0))            # timestamp
+        self.fileobj.write('\002')                 # max compression
+        self.fileobj.write('\003')                 # UNIX
 
 def _gzipOpen(filename, mode="rb", compresslevel=9):
     return GzipFile(filename, mode, compresslevel)
-- 
1.7.1



More information about the Rpm-metadata mailing list