#!/usr/bin/python -tt # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # copyright (c) 2008 Red Hat, Inc - written by Seth Vidal """Go through a yum packagesack and return the list of newest pkgs which possibly have conflicting files""" import yum import yum.Errors import yum.misc import sys import os import os.path # iterate all pkgs, build a filedict of filename = [list of pkg objects] # then go through that list, if any file has more than one pkg then put those # pkgs in another list # print out the file conflict and the pkgs which potentially conflict # later: work on whittling down the list by removing: # pkgs which are multilib sets # pkgs which have fully matching overlapping files (md5sums + timestamps) def pkg_names_match(pkglist): p = pkglist[0] for pkg in pkglist[1:]: if p.name != pkg.name: return False return True def sourcerpms_match(pkglist): p = pkglist[0] for pkg in pkglist[1:]: if p.sourcerpm != pkg.sourcerpm: return False return True def obsolete_each_other(pkglist): for pkga in pkglist: for pkgb in pkglist: if pkga == pkgb: continue if pkga.checkPrco('obsoletes', (pkgb.name, '=', (pkgb.epoch, pkgb.ver, pkgb.rel))): return True if pkgb.checkPrco('obsoletes', (pkga.name, '=', (pkga.epoch, pkga.ver, pkga.rel))): return True return False def is_real_conflict(fn, pkglist): checksums = {} # not a great check but it does toss out all the glibc.i686 vs glibc.i386 ones if pkg_names_match(pkglist): return False # if they have the same sourcerpm it is highly doubtful it is a legit conflict if sourcerpms_match(pkglist): return False if obsolete_each_other(pkglist): print "obsolete each other" return False for pkg in pkglist: print "Fetching Headers for %s" % pkg #download header # silliness for headers if not os.path.exists(pkg.repo.hdrdir): os.makedirs(pkg.repo.hdrdir) # make this into a proper error func check for urlgrabber routines # so we get the proper retries if not os.path.exists(pkg.localHdr()): try: hdr = pkg.returnLocalHeader() except yum.Errors.RepoError, e: pkg.repo.getHeader(pkg) else: pkg.repo.getHeader(pkg) #read in header try: hdr = pkg.returnLocalHeader() except yum.Errors.RepoError, e: print "Cannot retrieve header for %s" % pkg return True fi = hdr.fiFromHeader() for fitup in fi: if fitup[0] == fn: checksums[pkg]=fitup[-1] l = yum.misc.unique(checksums.values()) if len(l) > 1: return True return False my = yum.YumBase() my.conf.cachedir = yum.misc.getCacheDir() my.repos.setCacheDir(my.conf.cachedir) filedict = {} #dirdict = {} print 'Finding potential file conflicts' for pkg in my.pkgSack.returnNewestByNameArch(): for fn in pkg.filelist + pkg.ghostlist: if not filedict.has_key(fn): filedict[fn] = [] filedict[fn].append(pkg) # for fn in pkg.dirlist: # if not dirdict.has_key(fn): dirdict[fn] = [] # dirdict[fn].append(pkg) for fn in filedict.keys(): if len(filedict[fn]) < 2: del filedict[fn] print 'Done' print '%s potential file conflicts' % len(filedict.keys()) print 'Doing more advanced checks to see if these are real conflicts (patience is a virtue)' count = 1 for fn in filedict.keys(): print '%d checking on %s ...' % (count, fn), count += 1 if not is_real_conflict(fn, filedict[fn]): print ' no.' del filedict[fn] else: print ' yes.' print "conflicts: " for pkg in filedict[fn]: print ' %s-%s-%s.%s' % (pkg.name, pkg.ver, pkg.rel, pkg.arch) print 'Done' print 'Results' for fn in filedict.keys(): print fn for pkg in filedict[fn]: print ' %s-%s-%s.%s' % (pkg.name, pkg.ver, pkg.rel, pkg.arch)