unify cookie generation for solv/pysolv/rbsolv/p5solv
[platform/upstream/libsolv.git] / examples / pysolv
index f529d5d..479aba2 100755 (executable)
@@ -53,9 +53,22 @@ def calc_cookie_file(filename):
 
 def calc_cookie_fp(fp):
     chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256)
+    chksum.add("1.1");
     chksum.add_fp(fp)
     return chksum.raw()
 
+def calc_cookie_ext(f, cookie):
+    chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256)
+    chksum.add("1.1");
+    chksum.add(cookie)
+    if f:
+       chksum.add_fstat(f.fileno())
+    extcookie = chksum.raw()
+    # compatibility to c code
+    if ord(extcookie[0]) == 0:
+       extcookie[0] = chr(1)
+    return extcookie
+
 class repo_generic(dict):
     def __init__(self, name, type, attribs = {}):
         for k in attribs:
@@ -225,21 +238,6 @@ class repo_generic(dict):
             return False
         return True
 
-    def genextcookie(self, f):
-        chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256)
-        chksum.add(self['cookie'])
-        if f:
-            stat = os.fstat(f.fileno())
-            chksum.add(str(stat[ST_DEV]))
-            chksum.add(str(stat[ST_INO]))
-            chksum.add(str(stat[ST_SIZE]))
-            chksum.add(str(stat[ST_MTIME]))
-        extcookie = chksum.raw()
-        # compatibility to c code
-        if ord(extcookie[0]) == 0:
-            extcookie[0] = chr(1)
-        self['extcookie'] = extcookie
-        
     def writecachedrepo(self, ext, info=None):
         try:
             if not os.path.isdir("/var/cache/solv"):
@@ -255,7 +253,7 @@ class repo_generic(dict):
                 self.handle.write_first_repodata(f)
             if self.type != 'system' and not ext:
                 if 'extcookie' not in self:
-                    self.genextcookie(f)
+                   self['extcookie'] = calc_cookie_ext(f, self['cookie'])
                 f.write(self['extcookie'])
             if not ext:
                 f.write(self['cookie'])