| Index: build/android/pylib/utils/md5sum.py
|
| diff --git a/build/android/pylib/utils/md5sum.py b/build/android/pylib/utils/md5sum.py
|
| index da3cd15c785b0da5a2382816078d6817f63fc7aa..4d7d0b0020454018821f285ad4f4acc21a7202ef 100644
|
| --- a/build/android/pylib/utils/md5sum.py
|
| +++ b/build/android/pylib/utils/md5sum.py
|
| @@ -5,6 +5,7 @@
|
| import collections
|
| import logging
|
| import os
|
| +import re
|
| import tempfile
|
| import types
|
|
|
| @@ -12,8 +13,6 @@ from pylib import cmd_helper
|
| from pylib import constants
|
| from pylib.utils import device_temp_file
|
|
|
| -HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path'])
|
| -
|
| MD5SUM_DEVICE_LIB_PATH = '/data/local/tmp/md5sum/'
|
| MD5SUM_DEVICE_BIN_PATH = MD5SUM_DEVICE_LIB_PATH + 'md5sum_bin'
|
|
|
| @@ -21,6 +20,8 @@ MD5SUM_DEVICE_SCRIPT_FORMAT = (
|
| 'test -f {path} -o -d {path} '
|
| '&& LD_LIBRARY_PATH={md5sum_lib} {device_pie_wrapper} {md5sum_bin} {path}')
|
|
|
| +_STARTS_WITH_CHECKSUM_RE = re.compile(r'^\s*[0-9a-fA-f]{32}\s+')
|
| +
|
|
|
| def CalculateHostMd5Sums(paths):
|
| """Calculates the MD5 sum value for all items in |paths|.
|
| @@ -28,7 +29,7 @@ def CalculateHostMd5Sums(paths):
|
| Args:
|
| paths: A list of host paths to md5sum.
|
| Returns:
|
| - A list of named tuples with 'hash' and 'path' attributes.
|
| + A dict mapping paths to their respective md5sum checksums.
|
| """
|
| if isinstance(paths, basestring):
|
| paths = [paths]
|
| @@ -36,7 +37,8 @@ def CalculateHostMd5Sums(paths):
|
| out = cmd_helper.GetCmdOutput(
|
| [os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host')] +
|
| [p for p in paths])
|
| - return [HashAndPath(*l.split(None, 1)) for l in out.splitlines()]
|
| +
|
| + return _ParseMd5SumOutput(out.splitlines())
|
|
|
|
|
| def CalculateDeviceMd5Sums(paths, device):
|
| @@ -45,7 +47,7 @@ def CalculateDeviceMd5Sums(paths, device):
|
| Args:
|
| paths: A list of device paths to md5sum.
|
| Returns:
|
| - A list of named tuples with 'hash' and 'path' attributes.
|
| + A dict mapping paths to their respective md5sum checksums.
|
| """
|
| if isinstance(paths, basestring):
|
| paths = [paths]
|
| @@ -72,5 +74,11 @@ def CalculateDeviceMd5Sums(paths, device):
|
| device.adb.Push(md5sum_script_file.name, md5sum_device_script_file.name)
|
| out = device.RunShellCommand(['sh', md5sum_device_script_file.name])
|
|
|
| - return [HashAndPath(*l.split(None, 1)) for l in out if l]
|
| + return _ParseMd5SumOutput(out)
|
| +
|
| +
|
| +def _ParseMd5SumOutput(out):
|
| + hash_and_path = (l.split(None, 1) for l in out
|
| + if l and _STARTS_WITH_CHECKSUM_RE.match(l))
|
| + return dict((p, h) for h, p in hash_and_path)
|
|
|
|
|