summaryrefslogtreecommitdiffstats
path: root/pym/portage/checksum.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-15 06:42:40 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-15 06:42:40 +0000
commitd23814e0195ac325f53189a0f2d1049637b5197b (patch)
tree05cbd9f7c30e3f56d05c13380ae6fbae3f7b51a2 /pym/portage/checksum.py
parentd4a1b1095779af81dcd786911d27a5bb862d8e91 (diff)
downloadportage-d23814e0195ac325f53189a0f2d1049637b5197b.tar.gz
portage-d23814e0195ac325f53189a0f2d1049637b5197b.tar.bz2
portage-d23814e0195ac325f53189a0f2d1049637b5197b.zip
In perform_checksum(), encode the filename with correct encoding before
passing to spawn (for prelink), and enable strict encoding behavior in _perform_md5_merge(). svn path=/main/trunk/; revision=14059
Diffstat (limited to 'pym/portage/checksum.py')
-rw-r--r--pym/portage/checksum.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 0e6a9d552..b22e62b61 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -120,7 +120,8 @@ def perform_md5(x, calc_prelink=0):
return perform_checksum(x, "MD5", calc_prelink)[0]
def _perform_md5_merge(x, **kwargs):
- return perform_md5(_unicode_encode(x, encoding=_merge_encoding), **kwargs)
+ return perform_md5(_unicode_encode(x,
+ encoding=_merge_encoding, errors='strict'), **kwargs)
def perform_all(x, calc_prelink=0):
mydict = {}
@@ -200,7 +201,10 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0):
def perform_checksum(filename, hashname="MD5", calc_prelink=0):
"""
- Run a specific checksum against a file.
+ Run a specific checksum against a file. The filename can
+ be either unicode or an encoded byte string. If filename
+ is unicode then a UnicodeDecodeError will be raised if
+ necessary.
@param filename: File to run the checksum against
@type filename: String
@@ -212,7 +216,11 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0):
@return: The hash and size of the data
"""
global prelink_capable
- myfilename = filename[:]
+ # Make sure filename is encoded with the correct encoding before
+ # it is passed to spawn (for prelink) and/or the hash function.
+ filename = _unicode_encode(filename,
+ encoding=_fs_encoding, errors='strict')
+ myfilename = filename
prelink_tmpfile = None
try:
if calc_prelink and prelink_capable:
@@ -234,8 +242,7 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0):
if hashname not in hashfunc_map:
raise portage.exception.DigestException(hashname + \
" hash function not available (needs dev-python/pycrypto)")
- myhash, mysize = hashfunc_map[hashname](_unicode_encode(myfilename,
- encoding=_fs_encoding, errors='strict'))
+ myhash, mysize = hashfunc_map[hashname](myfilename)
except (OSError, IOError), e:
if e.errno == errno.ENOENT:
raise portage.exception.FileNotFound(myfilename)