diff options
authorZac Medico <zmedico@gentoo.org>2015-04-01 15:27:42 -0700
committerZac Medico <zmedico@gentoo.org>2015-04-01 16:14:52 -0700
commitf9a2d7025e22f5e1711f39c4740a020f6f0d2c8f (patch)
parentbinarytree.move_ent: fix binpkg-multi-instance _pkg_paths corruption (bug 545... (diff)
dispatch-conf: fix unicode handling (bug 545270)
This avoids UnicodeDecodeError problems by using UTF-8 encoding regardless of the locale. X-Gentoo-Bug: 545270 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=545270
2 files changed, 6 insertions, 7 deletions
diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index b6799104f..678a66d7c 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -11,12 +11,11 @@
# dialog menus
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
import atexit
import io
import re
-import shutil
import sys
from stat import ST_GID, ST_MODE, ST_UID
@@ -27,7 +26,7 @@ if osp.isfile(osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), ".porta
sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
import portage
portage._internal_caller = True
-from portage import os
+from portage import os, shutil
from portage import _encodings, _unicode_decode
from portage.dispatch_conf import diffstatusoutput, diff_mixed_wrapper
from portage.process import find_binary, spawn
@@ -403,7 +402,9 @@ class dispatch:
newconfigs.sort ()
for nconf in newconfigs:
- nconf = nconf.rstrip ()
+ # Use strict mode here, because we want to know if it fails,
+ # and portage only merges files with valid UTF-8 encoding.
+ nconf = _unicode_decode(nconf, errors='strict').rstrip()
conf = re.sub (r'\._cfg\d+_', '', nconf)
dirname = os.path.dirname(nconf)
conf_map = {
diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
index 790eacb83..98939fd23 100644
--- a/pym/portage/dispatch_conf.py
+++ b/pym/portage/dispatch_conf.py
@@ -10,15 +10,13 @@ from __future__ import print_function, unicode_literals
import io
import functools
-import os
-import shutil
import stat
import subprocess
import sys
import tempfile
import portage
-from portage import _encodings
+from portage import _encodings, os, shutil
from portage.env.loaders import KeyValuePairFileLoader
from portage.localization import _
from portage.util import shlex_split, varexpand