--- portage-2.2_rc43/pym/portage/update.py.orig 2009-09-25 06:29:54.000000000 +0300 +++ portage-2.2_rc43/pym/portage/update.py 2009-12-05 11:38:46.000000000 +0200 @@ -185,45 +185,53 @@ protect_mask - list of paths from CONFIG_PROTECT_MASK update_iter - list of update commands as returned from parse_updates()""" - config_root = normalize_path(config_root) + def decodeFS(y): + return (_unicode_decode(y, encoding=_encodings['fs'], errors='strict')) + + def encodeFS(x): + return (_unicode_encode(x, encoding=_encodings['fs'], errors='strict')) + + # os.path.* and normalize_path works with fs-encoded + # so combine only fs-encoded pathnames + config_root = normalize_path(encodeFS(config_root)) update_files = {} file_contents = {} myxfiles = ["package.mask", "package.unmask", \ "package.keywords", "package.use"] myxfiles += [os.path.join("profile", x) for x in myxfiles] - abs_user_config = os.path.join(config_root, USER_CONFIG_PATH) - recursivefiles = [] + myxfiles = [encodeFS(x) for x in myxfiles] + abs_user_config = os.path.join(config_root, encodeFS(USER_CONFIG_PATH)) + recursivefiles = [] # pairs of (bytes, string) for x in myxfiles: config_file = os.path.join(abs_user_config, x) if os.path.isdir(config_file): for parent, dirs, files in os.walk(config_file): for y in dirs: + # do not descent to hidden folders or those with wrong name encoding try: - y = _unicode_decode(y, - encoding=_encodings['fs'], errors='strict') + y_decoded = decodeFS(y) except UnicodeDecodeError: dirs.remove(y) continue - if y.startswith("."): + if y_decoded.startswith("."): dirs.remove(y) for y in files: + # add only visible files with right name encoding try: - y = _unicode_decode(y, - encoding=_encodings['fs'], errors='strict') + y_decoded = decodeFS(y) except UnicodeDecodeError: continue - if y.startswith("."): + if y_decoded.startswith("."): continue - recursivefiles.append( - os.path.join(parent, y)[len(abs_user_config) + 1:]) + y = os.path.join(parent, y)[len(abs_user_config) + 1:] + recursivefiles.append((y, decodeFS(y))) else: - recursivefiles.append(x) + recursivefiles.append((x, decodeFS(x))) myxfiles = recursivefiles - for x in myxfiles: + for (x, y) in myxfiles: try: - file_contents[x] = codecs.open( - _unicode_encode(os.path.join(abs_user_config, x), - encoding=_encodings['fs'], errors='strict'), + file_contents[y] = codecs.open( + os.path.join(abs_user_config, x), mode='r', encoding=_encodings['content'], errors='replace').readlines() except IOError: