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

Collapse All | Expand All

(-)a/pym/portage.py (-6 / +1 lines)
Lines 6130-6140 class dblink: Link Here
6130
			#A directory is specified.  Figure out protection paths, listdir() it and process it.
6130
			#A directory is specified.  Figure out protection paths, listdir() it and process it.
6131
			mergelist = listdir(join(srcroot, stufftomerge))
6131
			mergelist = listdir(join(srcroot, stufftomerge))
6132
			offset=stufftomerge
6132
			offset=stufftomerge
6133
			# We need mydest defined up here to calc. protection paths.  This is now done once per
6134
			# directory rather than once per file merge.  This should really help merge performance.
6135
			# Trailing / ensures that protects/masks with trailing /'s match.
6136
			mytruncpath = join(destroot, offset).rstrip(sep) + sep
6137
			myppath=self.isprotected(mytruncpath)
6138
		else:
6133
		else:
6139
			mergelist=stufftomerge
6134
			mergelist=stufftomerge
6140
			offset=""
6135
			offset=""
Lines 6312-6318 class dblink: Link Here
6312
						# or by a symlink to an existing regular file;
6307
						# or by a symlink to an existing regular file;
6313
						# now, config file management may come into play.
6308
						# now, config file management may come into play.
6314
						# we only need to tweak mydest if cfg file management is in play.
6309
						# we only need to tweak mydest if cfg file management is in play.
6315
						if myppath:
6310
						if self.isprotected(mydest):
6316
							# we have a protection path; enable config file management.
6311
							# we have a protection path; enable config file management.
6317
							destmd5=portage_checksum.perform_md5(mydest,calc_prelink=1)
6312
							destmd5=portage_checksum.perform_md5(mydest,calc_prelink=1)
6318
							cycled=0
6313
							cycled=0
(-)a/pym/portage_util.py (-9 / +41 lines)
Lines 7-13 from portage_exception import PortageExc Link Here
7
import portage_exception
7
import portage_exception
8
from portage_dep import isvalidatom
8
from portage_dep import isvalidatom
9
9
10
import sys,string,shlex,os,errno
10
import os, errno, shlex, stat, string, sys
11
try:
11
try:
12
	import cPickle
12
	import cPickle
13
except ImportError:
13
except ImportError:
Lines 829-861 class ConfigProtect(object): Link Here
829
		self.updateprotect()
829
		self.updateprotect()
830
830
831
	def updateprotect(self):
831
	def updateprotect(self):
832
		#do some config file management prep
832
		"""Update internal state for isprotected() calls.  Nonexistent paths
833
		are ignored."""
833
		self.protect = []
834
		self.protect = []
835
		self._dirs = set()
834
		for x in self.protect_list:
836
		for x in self.protect_list:
835
			ppath = normalize_path(
837
			ppath = normalize_path(
836
				os.path.join(self.myroot, x.lstrip(os.path.sep))) + os.path.sep
838
				os.path.join(self.myroot, x.lstrip(os.path.sep)))
837
			if os.path.isdir(ppath):
839
			mystat = None
840
			try:
841
				if stat.S_ISDIR(os.lstat(ppath).st_mode):
842
					self._dirs.add(ppath)
838
				self.protect.append(ppath)
843
				self.protect.append(ppath)
844
			except OSError:
845
				# If it doesn't exist, there's no need to protect it.
846
				pass
839
847
840
		self.protectmask = []
848
		self.protectmask = []
841
		for x in self.mask_list:
849
		for x in self.mask_list:
842
			ppath = normalize_path(
850
			ppath = normalize_path(
843
				os.path.join(self.myroot, x.lstrip(os.path.sep))) + os.path.sep
851
				os.path.join(self.myroot, x.lstrip(os.path.sep)))
844
			if os.path.isdir(ppath):
852
			mystat = None
853
			try:
854
				if stat.S_ISDIR(os.lstat(ppath).st_mode):
855
					self._dirs.add(ppath)
845
				self.protectmask.append(ppath)
856
				self.protectmask.append(ppath)
846
			#if it doesn't exist, silently skip it
857
			except OSError:
858
				# If it doesn't exist, there's no need to mask it.
859
				pass
847
860
848
	def isprotected(self, obj):
861
	def isprotected(self, obj):
849
		"""Checks if obj is in the current protect/mask directories. Returns
862
		"""Returns True if obj is protected, False otherwise.  The caller must
850
		0 on unprotected/masked, and 1 on protected."""
863
		ensure that obj is normalized with a single leading slash.  A trailing
864
		slash is optional for directories."""
851
		masked = 0
865
		masked = 0
852
		protected = 0
866
		protected = 0
867
		sep = os.path.sep
853
		for ppath in self.protect:
868
		for ppath in self.protect:
854
			if len(ppath) > masked and obj.startswith(ppath):
869
			if len(ppath) > masked and obj.startswith(ppath):
870
				if ppath in self._dirs:
871
					if obj != ppath and not obj.startswith(ppath + sep):
872
						# /etc/foo does not match /etc/foobaz
873
						continue
874
				elif obj != ppath:
875
					# force exact match when CONFIG_PROTECT lists a
876
					# non-directory
877
					continue
855
				protected = len(ppath)
878
				protected = len(ppath)
856
				#config file management
879
				#config file management
857
				for pmpath in self.protectmask:
880
				for pmpath in self.protectmask:
858
					if len(pmpath) >= protected and obj.startswith(pmpath):
881
					if len(pmpath) >= protected and obj.startswith(pmpath):
882
						if pmpath in self._dirs:
883
							if obj != pmpath and \
884
								not obj.startswith(pmpath + sep):
885
								# /etc/foo does not match /etc/foobaz
886
								continue
887
						elif obj != pmpath:
888
							# force exact match when CONFIG_PROTECT_MASK lists
889
							# a non-directory
890
							continue
859
						#skip, it's in the mask
891
						#skip, it's in the mask
860
						masked = len(pmpath)
892
						masked = len(pmpath)
861
		return protected > masked
893
		return protected > masked

Return to bug 14321