def blockComputeFile( self, filename ): digest = "" if os.path.exists( filename ): size = os.path.getsize( filename ) if size == 0 : digest = self._zeroHash else: h = hashlib.sha256() remainder = size % self._blockSize count = size / self._blockSize if remainder > 0 : count = count + 1 try: with open( filename, "rb" ) as f: for _ in xrange( count ) : h.update( f.read( self._blockSize )) if self._delay > 0 : time.sleep( self._delay ) digest = h.hexdigest() except ( IOError, EOFError, OSError, SystemError) as e : debug.debug( "BlockComputeFile exception: %s" % e ) digest = None return digest
def addFile(self, p ): sha256 = "" timing = timer.Timer() try: debug.debug( "%s : %i" % ( p, os.path.getsize( p ))) timing.start() sha256 = self._checksum.blockComputeFile( p ) timing.stop() debug.debug( "sha256 : %s" % ( sha256 )) except ( IOError, EOFError, OSError, SystemError) as error: sha256 = "" #if the file goes away ignore that print "exception thrown in checksum calculation: %s for %s" % ( error, p ) self._filesCollection.updateChecksum( p, sha256, timing.elapsed())
def addFile(self, p): if not os.path.islink(p): return self._filesCollection.addFile(p) else: debug.debug("%s : is a symlink" % p) return None