Commits

Martin Scharrer committed 69a4c71

Added recalc of MD5 and SHA1 headers, incl. correct handling of empty files.

  • Participants
  • Parent commits 26a41cb

Comments (0)

Files changed (1)

File py/SvnDumpLoad/Format.py

 """
 
 import sys
+import hashlib
 
 NL = '\n'
 
         self._headers['Content-length'] = "0"
         super(RecordWithContent, self).recalc_headers()
         if self.has_text_content():
-            self._headers['Text-content-length'] = str(len(self._content))
-            self._headers['Content-length'] = str(int(self._headers['Content-length']) + int(self._headers['Text-content-length']))
+            textlength = len(self._content)
+            self._headers['Text-content-length'] = str(textlength)
+            self._headers['Content-length'] = str(int(self._headers.get('Content-length',0)) + textlength)
+            self._headers['Text-content-md5'] = hashlib.md5( self._content ).hexdigest()
+            self._headers['Text-content-sha1'] = hashlib.sha1( self._content ).hexdigest()
         else:
-            for header in ('Text-content-length','Text-content-md5','Text-content-sha1'):
-                if header in self._headers:
-                    del self._headers[header]
+            # Only set Text-content-length of content-less node if header was already present
+            if 'Text-content-length' in self._headers:
+                self._headers['Text-content-length'] = "0"
+            if 'Text-content-md5' in self._headers:
+                self._headers['Text-content-md5'] = hashlib.md5( self._content ).hexdigest()
+            if 'Text-content-sha1' in self._headers:
+                self._headers['Text-content-sha1'] = hashlib.sha1( self._content ).hexdigest()
 
     def write(self, outfile):
         RecordWithProperties.write(self, outfile)