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

(-)pym/portage_util.py (-9 / +45 lines)
Lines 7-13 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 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.  A trailing / is
833
		automatically added to paths that are identified as directories by lstat
834
		calls (works for actual directories and symlinks to directories).  All
835
		other paths that exist will not have a trailing /.  Non-existant paths
836
		are ignored.  The merge phase must call this method each time that a
837
		symlink to a directory is merged!"""
833
		self.protect = []
838
		self.protect = []
839
		self._dirs = set()
834
		for x in self.protect_list:
840
		for x in self.protect_list:
835
			ppath = normalize_path(
841
			ppath = normalize_path(
836
				os.path.join(self.myroot, x.lstrip(os.path.sep))) + os.path.sep
842
				os.path.join(self.myroot, x.lstrip(os.path.sep)))
837
			if os.path.isdir(ppath):
843
			mystat = None
844
			try:
845
				if stat.S_ISDIR(os.lstat(ppath).st_mode):
846
					self._dirs.add(ppath)
838
				self.protect.append(ppath)
847
				self.protect.append(ppath)
848
			except OSError:
849
				# If it doesn't exist, there's no need to protect it.
850
				pass
839
851
840
		self.protectmask = []
852
		self.protectmask = []
841
		for x in self.mask_list:
853
		for x in self.mask_list:
842
			ppath = normalize_path(
854
			ppath = normalize_path(
843
				os.path.join(self.myroot, x.lstrip(os.path.sep))) + os.path.sep
855
				os.path.join(self.myroot, x.lstrip(os.path.sep)))
844
			if os.path.isdir(ppath):
856
			mystat = None
857
			try:
858
				if stat.S_ISDIR(os.lstat(ppath).st_mode):
859
					self._dirs.add(ppath)
845
				self.protectmask.append(ppath)
860
				self.protectmask.append(ppath)
846
			#if it doesn't exist, silently skip it
861
			except OSError:
862
				# If it doesn't exist, there's no need to mask it.
863
				pass
847
864
848
	def isprotected(self, obj):
865
	def isprotected(self, obj):
849
		"""Checks if obj is in the current protect/mask directories. Returns
866
		"""Returns True if obj is protected, False otherwise.  The caller must
850
		0 on unprotected/masked, and 1 on protected."""
867
		ensure that obj is normalized with a single leading slash.  A trailing
868
		slash is optional for directories."""
851
		masked = 0
869
		masked = 0
852
		protected = 0
870
		protected = 0
871
		sep = os.path.sep
853
		for ppath in self.protect:
872
		for ppath in self.protect:
854
			if len(ppath) > masked and obj.startswith(ppath):
873
			if len(ppath) > masked and obj.startswith(ppath):
874
				if ppath in self._dirs:
875
					if obj != ppath and not obj.startswith(ppath + sep):
876
						# /etc/foo does not match /etc/foobaz
877
						continue
878
				elif obj != ppath:
879
					# force exact match when CONFIG_PROTECT lists a
880
					# non-directory
881
					continue
855
				protected = len(ppath)
882
				protected = len(ppath)
856
				#config file management
883
				#config file management
857
				for pmpath in self.protectmask:
884
				for pmpath in self.protectmask:
858
					if len(pmpath) >= protected and obj.startswith(pmpath):
885
					if len(pmpath) >= protected and obj.startswith(pmpath):
886
						if pmpath in self._dirs:
887
							if obj != pmpath and \
888
								not obj.startswith(pmpath + sep):
889
								# /etc/foo does not match /etc/foobaz
890
								continue
891
						elif obj != pmpath:
892
							# force exact match when CONFIG_PROTECT_MASK lists
893
							# a non-directory
894
							continue
859
						#skip, it's in the mask
895
						#skip, it's in the mask
860
						masked = len(pmpath)
896
						masked = len(pmpath)
861
		return protected > masked
897
		return protected > masked
(-)pym/portage.py (+4 lines)
Lines 6234-6239 Link Here
6234
					print "!!! Failed to move file."
6234
					print "!!! Failed to move file."
6235
					print "!!!",mydest,"->",myto
6235
					print "!!!",mydest,"->",myto
6236
					sys.exit(1)
6236
					sys.exit(1)
6237
				if os.path.isdir(mydest):
6238
					# CONFIG_PROTECT logic must be notified to account for a
6239
					# new symlink to a previously existing directory.
6240
					self.updateprotect()
6237
			elif stat.S_ISDIR(mymode):
6241
			elif stat.S_ISDIR(mymode):
6238
				# we are merging a directory
6242
				# we are merging a directory
6239
				if mydmode!=None:
6243
				if mydmode!=None:

Return to bug 14321