[yum-git] 2 commits - yum/packages.py

James Antill james at linux.duke.edu
Sat Mar 1 19:33:37 UTC 2008


 yum/packages.py |   83 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 63 insertions(+), 20 deletions(-)

New commits:
commit c6b1e0d324df95a98632b2022dbb829650fcc7bf
Author: James Antill <james at and.org>
Date:   Sat Mar 1 14:27:49 2008 -0500

    Deal with rpm file states, add "fake problems" for multilib comparisons

diff --git a/yum/packages.py b/yum/packages.py
index d31737a..424103f 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -865,7 +865,8 @@ class _PkgVerifyProb:
             return 1
         type2sort = {'type' :  1, 'symlink' : 2, 'checksum' : 3, 'size'    :  4,
                      'user' :  4, 'group'   : 5, 'mode' : 6, 'genchecksum' :  7,
-                     'mtime' : 8, 'missing' : 9, 'permissions-missing'     : 10}
+                     'mtime' : 8, 'missing' : 9, 'permissions-missing'     : 10,
+                     'state' : 11, 'missingok' : 12, 'ghost' : 13}
         ret = cmp(type2sort[self.type], type2sort[other.type])
         if not ret:
             for attr in ['disk_value', 'database_value', 'file_types']:
@@ -911,6 +912,11 @@ class YumInstalledPackage(YumHeaderPackage):
             if stat.S_ISBLK(mode):  return "block device"
             return "<unknown>"
 
+        statemap = {rpm.RPMFILE_STATE_REPLACED : 'replaced',
+                    rpm.RPMFILE_STATE_NOTINSTALLED : 'not installed',
+                    rpm.RPMFILE_STATE_WRONGCOLOR : 'wrong color',
+                    rpm.RPMFILE_STATE_NETSHARED : 'netshared'}
+
         fi = self.hdr.fiFromHeader()
         results = {} # fn = problem_obj?
 
@@ -932,15 +938,6 @@ class YumInstalledPackage(YumHeaderPackage):
                 if not matched: 
                     continue
 
-            if all:
-                vflags = -1
-            else:
-                if flags & rpm.RPMFILE_MISSINGOK:
-                    continue # rpm just skips missing ok, so we do too
-
-                if flags & rpm.RPMFILE_GHOST:
-                    continue
-            
             ftypes = []
             if flags & rpm.RPMFILE_CONFIG:
                 ftypes.append('configuration')
@@ -960,6 +957,28 @@ class YumInstalledPackage(YumHeaderPackage):
             # elif flags & rpm.RPMFILE_POLICY:
             #    ftypes.append('policy')
                 
+            if all:
+                vflags = -1
+
+            if state != rpm.RPMFILE_STATE_NORMAL:
+                if state in statemap:
+                    ftypes.append("state=" + statemap[state])
+                else:
+                    ftypes.append("state=<unknown>")
+                results[fn] = [_PkgVerifyProb('state',
+                                              'state is not normal',
+                                              ftypes)]
+                continue
+
+            if flags & rpm.RPMFILE_MISSINGOK:
+                results[fn] = [_PkgVerifyProb('missingok', 'missing but ok',
+                                              ftypes)]
+                continue # rpm just skips missing ok, so we do too
+
+            if flags & rpm.RPMFILE_GHOST:
+                results[fn] = [_PkgVerifyProb('ghost', 'ghost file',ftypes)]
+                continue
+
             # do check of file status on system
             problems = []
             if os.path.exists(fn):
commit 115c2eaf299e2d6e3824f2112cca267168516f82
Author: James Antill <james at and.org>
Date:   Sat Mar 1 13:15:38 2008 -0500

    Obey verify flags, for extra "excludes"

diff --git a/yum/packages.py b/yum/packages.py
index 43544cd..d31737a 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -878,7 +878,17 @@ class _PkgVerifyProb:
                 if ret:
                     break
         return ret
-        
+
+# From: lib/rpmvf.h ... not in rpm *sigh*
+_RPMVERIFY_MD5      = (1 << 0)
+_RPMVERIFY_FILESIZE = (1 << 1)
+_RPMVERIFY_LINKTO   = (1 << 2)
+_RPMVERIFY_USER     = (1 << 3)
+_RPMVERIFY_GROUP    = (1 << 4)
+_RPMVERIFY_MTIME    = (1 << 5)
+_RPMVERIFY_MODE     = (1 << 6)
+_RPMVERIFY_RDEV     = (1 << 7)
+
 _installed_repo = FakeRepository('installed')
 _installed_repo.cost = 0
 class YumInstalledPackage(YumHeaderPackage):
@@ -893,12 +903,13 @@ class YumInstalledPackage(YumHeaderPackage):
            returns a tuple """
         def _ftype(mode):
             """ Given a "mode" return the name of the type of file. """
+            if stat.S_ISREG(mode):  return "file"
             if stat.S_ISDIR(mode):  return "directory"
             if stat.S_ISLNK(mode):  return "symlink"
             if stat.S_ISFIFO(mode): return "fifo"
             if stat.S_ISCHR(mode):  return "character device"
             if stat.S_ISBLK(mode):  return "block device"
-            return "file"
+            return "<unknown>"
 
         fi = self.hdr.fiFromHeader()
         results = {} # fn = problem_obj?
@@ -921,11 +932,15 @@ class YumInstalledPackage(YumHeaderPackage):
                 if not matched: 
                     continue
 
-            if not all and flags & rpm.RPMFILE_GHOST:
-                continue
-            if not all and flags & rpm.RPMFILE_MISSINGOK:
-                continue # rpm just skips missing ok, so we do too
+            if all:
+                vflags = -1
+            else:
+                if flags & rpm.RPMFILE_MISSINGOK:
+                    continue # rpm just skips missing ok, so we do too
 
+                if flags & rpm.RPMFILE_GHOST:
+                    continue
+            
             ftypes = []
             if flags & rpm.RPMFILE_CONFIG:
                 ftypes.append('configuration')
@@ -962,14 +977,15 @@ class YumInstalledPackage(YumHeaderPackage):
                 ftype    = _ftype(mode)
                 my_ftype = _ftype(my_st.st_mode)
 
-                if ftype != my_ftype:
+                if vflags & _RPMVERIFY_RDEV and ftype != my_ftype:
                     prob = _PkgVerifyProb('type', 'file type does not match',
                                           ftypes)
                     prob.database_value = ftype
                     prob.disk_value = my_ftype
                     problems.append(prob)
 
-                if ftype == "symlink" and my_ftype == "symlink":
+                if (ftype == "symlink" and my_ftype == "symlink" and
+                    vflags & _RPMVERIFY_LINKTO):
                     fnl    = fi.FLink() # fi.foo is magic, don't think about it
                     my_fnl = os.readlink(fn)
                     if my_fnl != fnl:
@@ -991,19 +1007,21 @@ class YumInstalledPackage(YumHeaderPackage):
                 if my_ftype == "symlink":
                     check_perms = False
 
-                if check_content and my_st.st_mtime != mtime:
+                if (check_content and vflags & _RPMVERIFY_MTIME and
+                    my_st.st_mtime != mtime):
                     prob = _PkgVerifyProb('mtime', 'mtime does not match',
                                           ftypes)
                     prob.database_value = mtime
                     prob.disk_value     = my_st.st_mtime
                     problems.append(prob)
 
-                if check_perms and my_user != user:
+                if check_perms and vflags & _RPMVERIFY_USER and my_user != user:
                     prob = _PkgVerifyProb('user', 'user does not match', ftypes)
                     prob.database_value = user
                     prob.disk_value = my_user
                     problems.append(prob)
-                if check_perms and my_group != group:
+                if (check_perms and vflags & _RPMVERIFY_GROUP and
+                    my_group != group):
                     prob = _PkgVerifyProb('group', 'group does not match',
                                           ftypes)
                     prob.database_value = group
@@ -1014,14 +1032,18 @@ class YumInstalledPackage(YumHeaderPackage):
                 if 'ghost' in ftypes: # This is what rpm does
                     my_mode &= 0777
                     mode    &= 0777
-                if check_perms and my_mode != mode:
+                if check_perms and vflags & _RPMVERIFY_MODE and my_mode != mode:
                     prob = _PkgVerifyProb('mode', 'mode does not match', ftypes)
                     prob.database_value = mode
                     prob.disk_value     = my_st.st_mode
                     problems.append(prob)
 
-                # don't checksum files that don't have a csum in the rpmdb :)
-                if check_content and csum:
+                # Note that because we might get the _size_ from prelink,
+                # we need to do the checksum, even if we just throw it away,
+                # just so we get the size correct.
+                if (check_content and
+                    ((have_prelink and vflags & _RPMVERIFY_FILESIZE) or
+                     (csum and vflags & _RPMVERIFY_MD5))):
                     try:
                         my_csum = misc.checksum('md5', fn)
                         gen_csum = True
@@ -1029,7 +1051,7 @@ class YumInstalledPackage(YumHeaderPackage):
                         # Don't have permission?
                         gen_csum = False
 
-                    if not gen_csum:
+                    if csum and vflags & _RPMVERIFY_MD5 and not gen_csum:
                         prob = _PkgVerifyProb('genchecksum',
                                               'checksum not available', ftypes)
                         prob.database_value = csum
@@ -1045,15 +1067,17 @@ class YumInstalledPackage(YumHeaderPackage):
                         my_csum = misc.checksum('md5', fp)
                         my_st_size = fp.read_size
 
-                    if gen_csum and my_csum != csum:
+                    if (csum and vflags & _RPMVERIFY_MD5 and gen_csum and
+                        my_csum != csum):
                         prob = _PkgVerifyProb('checksum',
                                               'checksum does not match', ftypes)
                         prob.database_value = csum
                         prob.disk_value     = my_csum
                         problems.append(prob)
 
-                # Size might be got from prelink ... *sigh*
-                if check_content and my_st_size != size:
+                # Size might be got from prelink ... *sigh*.
+                if (check_content and vflags & _RPMVERIFY_FILESIZE and
+                    my_st_size != size):
                     prob = _PkgVerifyProb('size', 'size does not match', ftypes)
                     prob.database_value = size
                     prob.disk_value     = my_st.st_size



More information about the Yum-cvs-commits mailing list