[Lsb-messages] /var/www/bzr/lsb/devel/appbat r1012: fixed problem from previous (endless loop), switch to getter for hash

Mats Wichmann mats at linuxfoundation.org
Sat Dec 31 20:46:12 UTC 2016


------------------------------------------------------------
revno: 1012
committer: Mats Wichmann <mats at linuxfoundation.org>
branch nick: appbat
timestamp: Sat 2016-12-31 13:46:12 -0700
message:
  fixed problem from previous (endless loop), switch to getter for hash
modified:
  extras/entitycheck.py
  extras/entitycheck_new.py
-------------- next part --------------
=== modified file 'extras/entitycheck.py'
--- a/extras/entitycheck.py	2016-12-31 18:00:44 +0000
+++ b/extras/entitycheck.py	2016-12-31 20:46:12 +0000
@@ -88,13 +88,13 @@
 class Entity(object):
     """Entity class instantiated for each entity read from the entity file."""
 
+    hashfunc = hashlib.md5
     BLOCKSIZE = 1024 * 1024
 
     def __init__(self, name, fname):
         self.name = name
         self.fname = fname
         self.fullpath = ''
-        self.hash = None
 
     @classmethod
     def from_re_match(cls, match):
@@ -114,15 +114,15 @@
         """Entity class "string" is "\tfilename", as that's what some things want to print"""
         return '\t%s' % self.fname
 
-    def dohash(self):
-        """Generate and store hash for this entity's filename"""
+    @property
+    def hash(self):
+        """Getter for hash generates on the fly"""
         f = open(self.fullpath, "rb")
-        cksum = hashlib.md5()
-        while True:
-            for block in iter(partial(f.read, Entity.BLOCKSIZE), ''):
-                cksum.update(block)
+        cksum = self.hashfunc()
+        for block in iter(partial(f.read, Entity.BLOCKSIZE), ''):
+            cksum.update(block)
         f.close()
-        self.hash = cksum.hexdigest()
+        return cksum.hexdigest()
 
     def delete_file(self):
         """Delete this entity's file, if it exists"""
@@ -382,8 +382,6 @@
             missing.append(item)
         else:
             found.append(item)
-            if check_sums or generate_sums:
-                item.dohash()
     return found, missing
 
 

=== modified file 'extras/entitycheck_new.py'
--- a/extras/entitycheck_new.py	2016-12-31 18:00:44 +0000
+++ b/extras/entitycheck_new.py	2016-12-31 20:46:12 +0000
@@ -92,7 +92,6 @@
         self.name = name
         self.fname = fname
         self.fullpath = ''
-        self.hash = None
 
     @classmethod
     def from_re_match(cls, match):
@@ -112,14 +111,14 @@
         """Entity class "string" is "\tfilename", as that's what some things want to print"""
         return '\t%s' % self.fname
 
-
-    def dohash(self):
-        """Generate and store hash for this entity's filename"""
+    @property
+    def hash(self):
+        """Getter for hash generates on the fly"""
         with open(self.fullpath, "rb") as f:
             cksum = self.hashfunc()
             for block in iter(partial(f.read, Entity.BLOCKSIZE), ''):
                 cksum.update(block)
-        self.hash = cksum.hexdigest()
+        return cksum.hexdigest()
 
     def delete_file(self):
         """Delete this entity's file, if it exists"""
@@ -362,8 +361,6 @@
             missing.append(item)
         else:
             found.append(item)
-            if check_sums or generate_sums:
-                item.dohash()
     return found, missing
 
 



More information about the lsb-messages mailing list