Bug #280259 - Use codecs.open() when reading the Packages file inside
authorZac Medico <zmedico@gentoo.org>
Tue, 4 Aug 2009 06:45:46 +0000 (06:45 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 4 Aug 2009 06:45:46 +0000 (06:45 -0000)
binarytree.inject(), in order to avoid a UnicodeDecodeError when the
file is later written as a unicode stream (via atomic_ofstream).

svn path=/main/trunk/; revision=13889

pym/portage/dbapi/bintree.py

index 41da32d3929f97b603f51a732038963e3d71255b..2b4dd1834a06383ac7a5727381e2ef9b23910007 100644 (file)
@@ -21,6 +21,7 @@ from portage.localization import _
 
 from portage import dep_expand, listdir, _check_distfile, _movefile
 
+import codecs
 import os, errno, stat
 import re
 from itertools import chain, izip
@@ -847,7 +848,8 @@ class binarytree(object):
                                created_symlink = True
                        pkgindex = self._new_pkgindex()
                        try:
-                               f = open(self._pkgindex_file)
+                               f = codecs.open(self._pkgindex_file,
+                                       encoding='utf_8', errors='replace')
                        except EnvironmentError:
                                pass
                        else: