diff --git a/yum/packages.py b/yum/packages.py index 4cf42ad..8e69a0f 100644 --- a/yum/packages.py +++ b/yum/packages.py @@ -821,6 +821,54 @@ class YumInstalledPackage(YumHeaderPackage): fakerepo.cost = 0 YumHeaderPackage.__init__(self, fakerepo, hdr) + def verify(self, pattern=[]): + """verify that the installed files match the packaged checksum + optionally verify they match only if they are in the 'pattern' list + returns a tuple """ + fi = self.hdr.fiFromHeader() + results = {} # fn = problem_obj? + import pwd + import grp + for filetuple in fi: + #tuple is: (filename, fsize, mode, mtime, flags, frdev?, inode, link, + # state, vflags?, user, group, md5sum(or none for dirs) + (fn, size, mode, mtime, flags, dev, inode, link, state, vflags, + user, group, csum) = filetuple + if pattern: + matched = False + for p in pattern: + if fnmatch.fnmatch(fn, p): + matched = True + break + if not matched: + continue + # do check of file status on system + problems = [] + if not os.path.exists(fn): + problems.append('missing') + # stat + my_st = os.stat(fn) + my_user = pwd.getpwuid(my_st[stat.ST_UID])[0] + my_group = grp.getgrgid(my_st[stat.ST_GID])[0] + #my_mode need to parse the rpmfi mode string of doom + if my_st[stat.ST_MTIME] != mtime: + problems.append('mtime does not match') + if my_group != group: + problems.append('group mismatch') + if my_user != user: + problems.append('user mismatch') + + # checksum + if csum: # don't checksum files that don't have a csum in the rpmdb :) + my_csum = misc.checksum('md5', fn) + if my_csum != csum: + problems.append('checksum mismatch') + if problems: + results[fn] = problems + + return results + + class YumLocalPackage(YumHeaderPackage): """Class to handle an arbitrary package from a file path this inherits most things from YumInstalledPackage because