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

Collapse All | Expand All

(-)portage-2.2_rc43/pym/portage/update.py.orig (-16 / +24 lines)
Lines 185-229 Link Here
185
	protect_mask - list of paths from CONFIG_PROTECT_MASK
185
	protect_mask - list of paths from CONFIG_PROTECT_MASK
186
	update_iter - list of update commands as returned from parse_updates()"""
186
	update_iter - list of update commands as returned from parse_updates()"""
187
187
188
	config_root = normalize_path(config_root)
188
	def decodeFS(y):
189
		return (_unicode_decode(y, encoding=_encodings['fs'], errors='strict'))
190
191
	def encodeFS(x):
192
		return (_unicode_encode(x, encoding=_encodings['fs'], errors='strict'))
193
194
	# os.path.* and normalize_path works with fs-encoded
195
	# so combine only fs-encoded pathnames
196
	config_root = normalize_path(encodeFS(config_root))
189
	update_files = {}
197
	update_files = {}
190
	file_contents = {}
198
	file_contents = {}
191
	myxfiles = ["package.mask", "package.unmask", \
199
	myxfiles = ["package.mask", "package.unmask", \
192
		"package.keywords", "package.use"]
200
		"package.keywords", "package.use"]
193
	myxfiles += [os.path.join("profile", x) for x in myxfiles]
201
	myxfiles += [os.path.join("profile", x) for x in myxfiles]
194
	abs_user_config = os.path.join(config_root, USER_CONFIG_PATH)
202
	myxfiles = [encodeFS(x) for x in myxfiles]
195
	recursivefiles = []
203
	abs_user_config = os.path.join(config_root, encodeFS(USER_CONFIG_PATH))
204
	recursivefiles = [] # pairs of (bytes, string)
196
	for x in myxfiles:
205
	for x in myxfiles:
197
		config_file = os.path.join(abs_user_config, x)
206
		config_file = os.path.join(abs_user_config, x)
198
		if os.path.isdir(config_file):
207
		if os.path.isdir(config_file):
199
			for parent, dirs, files in os.walk(config_file):
208
			for parent, dirs, files in os.walk(config_file):
200
				for y in dirs:
209
				for y in dirs:
210
					# do not descent to hidden folders or those with wrong name encoding
201
					try:
211
					try:
202
						y = _unicode_decode(y,
212
						y_decoded = decodeFS(y)
203
							encoding=_encodings['fs'], errors='strict')
204
					except UnicodeDecodeError:
213
					except UnicodeDecodeError:
205
						dirs.remove(y)
214
						dirs.remove(y)
206
						continue
215
						continue
207
					if y.startswith("."):
216
					if y_decoded.startswith("."):
208
						dirs.remove(y)
217
						dirs.remove(y)
209
				for y in files:
218
				for y in files:
219
					# add only visible files with right name encoding 
210
					try:
220
					try:
211
						y = _unicode_decode(y,
221
						y_decoded = decodeFS(y)
212
							encoding=_encodings['fs'], errors='strict')
213
					except UnicodeDecodeError:
222
					except UnicodeDecodeError:
214
						continue
223
						continue
215
					if y.startswith("."):
224
					if y_decoded.startswith("."):
216
						continue
225
						continue
217
					recursivefiles.append(
226
					y = os.path.join(parent, y)[len(abs_user_config) + 1:]
218
						os.path.join(parent, y)[len(abs_user_config) + 1:])
227
					recursivefiles.append((y, decodeFS(y)))
219
		else:
228
		else:
220
			recursivefiles.append(x)
229
			recursivefiles.append((x, decodeFS(x)))
221
	myxfiles = recursivefiles
230
	myxfiles = recursivefiles
222
	for x in myxfiles:
231
	for (x, y) in myxfiles:
223
		try:
232
		try:
224
			file_contents[x] = codecs.open(
233
			file_contents[y] = codecs.open(
225
				_unicode_encode(os.path.join(abs_user_config, x),
234
				os.path.join(abs_user_config, x),
226
				encoding=_encodings['fs'], errors='strict'),
227
				mode='r', encoding=_encodings['content'],
235
				mode='r', encoding=_encodings['content'],
228
				errors='replace').readlines()
236
				errors='replace').readlines()
229
		except IOError:
237
		except IOError:

Return to bug 295805