http://bugs.gentoo.org/show_bug.cgi?id=100479

The problem here is that we are iterating through pkgfiles.keys() and inside 
the iteration loop we modify the obj variable so subsequent calls to 
pkgfiles[obj] may fail. The obvious solution is to use a separate variable for 
the pkgfiles key.  My patch introduces a new variable called objkey and 
replaces all pkgfiles[obj] calls with pkgfiles[objkey].
Index: pym/portage.py
===================================================================
--- pym/portage.py	(revision 2139)
+++ pym/portage.py	(working copy)
@@ -6230,8 +6230,8 @@
 			mydirs=[]
 			mysyms=[]
 			modprotect="/lib/modules/"
-			for obj in mykeys:
-				obj=os.path.normpath(obj)
+			for objkey in mykeys:
+				obj=os.path.normpath(objkey)
 				if obj[:2]=="//":
 					obj=obj[1:]
 				if not os.path.exists(obj):
@@ -6239,7 +6239,7 @@
 						#we skip this if we're dealing with a symlink
 						#because os.path.exists() will operate on the
 						#link target rather than the link itself.
-						print "--- !found "+str(pkgfiles[obj][0]), obj
+						print "--- !found "+str(pkgfiles[objkey][0]), obj
 						continue
 				# next line includes a tweak to protect modules from being unmerged,
 				# but we don't protect modules from being overwritten if they are
@@ -6247,26 +6247,26 @@
 				# functionality for /lib/modules. For portage-ng both capabilities
 				# should be able to be independently specified.
 				if self.isprotected(obj) or ((len(obj) > len(modprotect)) and (obj[0:len(modprotect)]==modprotect)):
-					print "--- cfgpro "+str(pkgfiles[obj][0]), obj
+					print "--- cfgpro "+str(pkgfiles[objkey][0]), obj
 					continue
 
 				lstatobj=os.lstat(obj)
 				lmtime=str(lstatobj[stat.ST_MTIME])
-				if (pkgfiles[obj][0] not in ("dir","fif","dev","sym")) and (lmtime != pkgfiles[obj][1]):
-					print "--- !mtime", pkgfiles[obj][0], obj
+				if (pkgfiles[objkey][0] not in ("dir","fif","dev","sym")) and (lmtime != pkgfiles[objkey][1]):
+					print "--- !mtime", pkgfiles[objkey][0], obj
 					continue
 
-				if pkgfiles[obj][0]=="dir":
+				if pkgfiles[objkey][0]=="dir":
 					if not os.path.isdir(obj):
 						print "--- !dir  ","dir", obj
 						continue
 					mydirs.append(obj)
-				elif pkgfiles[obj][0]=="sym":
+				elif pkgfiles[objkey][0]=="sym":
 					if not os.path.islink(obj):
 						print "--- !sym  ","sym", obj
 						continue
 					mysyms.append(obj)
-				elif pkgfiles[obj][0]=="obj":
+				elif pkgfiles[objkey][0]=="obj":
 					if not os.path.isfile(obj):
 						print "--- !obj  ","obj", obj
 						continue
@@ -6274,7 +6274,7 @@
 
 					# string.lower is needed because db entries used to be in upper-case.  The
 					# string.lower allows for backwards compatibility.
-					if mymd5 != string.lower(pkgfiles[obj][2]):
+					if mymd5 != string.lower(pkgfiles[objkey][2]):
 						print "--- !md5  ","obj", obj
 						continue
 					try:
@@ -6282,7 +6282,7 @@
 					except (OSError,IOError),e:
 						pass
 					print "<<<       ","obj",obj
-				elif pkgfiles[obj][0]=="fif":
+				elif pkgfiles[objkey][0]=="fif":
 					if not stat.S_ISFIFO(lstatobj[stat.ST_MODE]):
 						print "--- !fif  ","fif", obj
 						continue
@@ -6291,7 +6291,7 @@
 					except (OSError,IOError),e:
 						pass
 					print "<<<       ","fif",obj
-				elif pkgfiles[obj][0]=="dev":
+				elif pkgfiles[objkey][0]=="dev":
 					print "---       ","dev",obj
 
 			#Now, we need to remove symlinks and directories.  We'll repeatedly

Reply via email to