Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 28228 | Differences between
and this patch

Collapse All | Expand All

(-)portage.py.org (+64 lines)
Lines 4175-4180 Link Here
4175
		self.dbdir=os.path.normpath(myroot+"///var/db/pkg/"+cat+"/"+pkg)
4175
		self.dbdir=os.path.normpath(myroot+"///var/db/pkg/"+cat+"/"+pkg)
4176
		self.myroot=myroot
4176
		self.myroot=myroot
4177
		self.updateprotect()
4177
		self.updateprotect()
4178
		self.contentscache=[]
4178
4179
4179
	def getpath(self):
4180
	def getpath(self):
4180
		"return path to location of db information (for >>> informational display)"
4181
		"return path to location of db information (for >>> informational display)"
Lines 4213-4218 Link Here
4213
	def getcontents(self):
4214
	def getcontents(self):
4214
		if not os.path.exists(self.dbdir+"/CONTENTS"):
4215
		if not os.path.exists(self.dbdir+"/CONTENTS"):
4215
			return None
4216
			return None
4217
		if self.contentscache != []:
4218
			return self.contentscache
4216
		pkgfiles={}
4219
		pkgfiles={}
4217
		myc=open(self.dbdir+"/CONTENTS","r")
4220
		myc=open(self.dbdir+"/CONTENTS","r")
4218
		mylines=myc.readlines()
4221
		mylines=myc.readlines()
Lines 4253-4258 Link Here
4253
			except (KeyError,IndexError):
4256
			except (KeyError,IndexError):
4254
				print "portage: CONTENTS line",pos,"corrupt!"
4257
				print "portage: CONTENTS line",pos,"corrupt!"
4255
			pos += 1
4258
			pos += 1
4259
		self.contentscache=pkgfiles
4256
		return pkgfiles
4260
		return pkgfiles
4257
4261
4258
	def updateprotect(self):
4262
	def updateprotect(self):
Lines 4499-4509 Link Here
4499
		if myebuildpath and os.path.exists(myebuildpath):
4503
		if myebuildpath and os.path.exists(myebuildpath):
4500
			a=doebuild(myebuildpath,"postrm",self.myroot)
4504
			a=doebuild(myebuildpath,"postrm",self.myroot)
4501
4505
4506
	def isowner(self,filename,destroot):
4507
		""" check if filename is a new file or belongs to this package
4508
		(for this or a previous version)"""
4509
		destfile = os.path.normpath(destroot+"/"+filename)
4510
		if not os.path.exists(destfile):
4511
			return True
4512
		if self.getcontents() and filename in self.getcontents().keys():
4513
			return True
4514
		
4515
		return False
4516
4502
	def treewalk(self,srcroot,destroot,inforoot,myebuild):
4517
	def treewalk(self,srcroot,destroot,inforoot,myebuild):
4503
		global settings
4518
		global settings
4504
		# srcroot = ${D}; destroot=where to merge, ie. ${ROOT}, inforoot=root of db entry,
4519
		# srcroot = ${D}; destroot=where to merge, ie. ${ROOT}, inforoot=root of db entry,
4505
		# secondhand = list of symlinks that have been skipped due to their target not existing (will merge later),
4520
		# secondhand = list of symlinks that have been skipped due to their target not existing (will merge later),
4506
		"this is going to be the new merge code"
4521
		"this is going to be the new merge code"
4522
4523
		# check for package collisions
4524
		# need to wait for python-2.3 to use os.walk(), use popen until then
4525
		if "collision-protect" in features:
4526
			myfilelist = os.popen("find "+srcroot+" -type f", "r").readlines()
4527
			stopmerge=False
4528
			starttime=time.time()
4529
			i=0
4530
			# this is a ugly hack to get the other versions of the same package,
4531
			# feel free to improve
4532
			otherpkg=[self.cat+"/"+mydir.split("/")[-1] for mydir in os.listdir(self.myroot+"var/db/pkg/"+self.cat)]
4533
			otherversions=filter(lambda a: a[1] == catpkgsplit(self.pkg)[1], [catpkgsplit(p) for p in otherpkg])
4534
			otherversions=map(lambda a: (a[1]+"-"+a[2]+"-"+a[3]).replace("-r0",""), otherversions)
4535
			otherversions.remove(self.pkg)	# we already checked this package
4536
			mypkglist=[]
4537
			for v in otherversions:
4538
				# should we check for same SLOT here ?
4539
				mypkglist.append(dblink(self.cat,v,destroot))
4540
			
4541
			print green("*")+" checking "+str(len(myfilelist))+" files for package collisions"
4542
			for f in myfilelist:
4543
				i=i+1
4544
				if i % 1000 == 0:
4545
					print str(i)+" files checked ..."
4546
				f=f[len(srcroot)-1:-1]
4547
				isowned = False
4548
				for ver in [self]+mypkglist:
4549
					if (ver.isowner(f, destroot) or ver.isprotected(f)):
4550
						isowned = True
4551
						break
4552
				if not isowned:
4553
					print "existing file "+f+" is not owned by this package"
4554
					stopmerge=True
4555
			print green("*")+" spend "+str(time.time()-starttime)+" seconds checking for file collisions"
4556
			if stopmerge:
4557
				print red("*")+" This package is blocked because it wants to overwrite"
4558
				print red("*")+" files belonging to other packages (see messages above)."
4559
				print red("*")+" If you have no clue what this is all about report it "
4560
				print red("*")+" as a bug for this package on http://bugs.gentoo.org"
4561
				print
4562
				print red("package "+self.cat+"/"+self.pkg+" NOT merged")
4563
				print
4564
				# Why is the package already merged here db-wise? Shouldn't be the case
4565
				# only unmerge if it ia new package and has no contents
4566
				if not self.getcontents():
4567
					self.unmerge()
4568
					self.delete()
4569
				sys.exit(1)
4570
			
4507
		if not os.path.exists(self.dbdir):
4571
		if not os.path.exists(self.dbdir):
4508
			self.create()
4572
			self.create()
4509
		
4573
		

Return to bug 28228