[android] Ignore extra files on the client when comparing md5sum output.

BUG=None
TEST=None
NOTRY=True

Review URL: https://chromiumcodereview.appspot.com/19675006

git-svn-id: http://src.chromium.org/svn/trunk/src/build@212337 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
craigdh@chromium.org 2013-07-18 13:18:02 +00:00
Родитель 4079645a6c
Коммит 2da081dd99
1 изменённых файлов: 30 добавлений и 7 удалений

Просмотреть файл

@ -183,8 +183,18 @@ def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None):
def _ComputeFileListHash(md5sum_output):
"""Returns a list of MD5 strings from the provided md5sum output."""
return [line.split(' ')[0] for line in md5sum_output]
"""Returns a list of tuples from the provided md5sum output.
Args:
md5sum_output: output directly from md5sum binary.
Returns:
List of namedtuples (hash, path).
"""
HashAndPath = collections.namedtuple('HashAndPath', ['hash', 'path'])
split_lines = [line.split(' ') for line in md5sum_output]
assert all(len(s) == 2 for s in split_lines), 'Invalid md5sum output'
return [HashAndPath._make(s) for s in split_lines]
def _HasAdbPushSucceeded(command_output):
@ -742,17 +752,30 @@ class AndroidCommands(object):
cmd = (MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper + ' ' +
MD5SUM_DEVICE_PATH + ' ' + device_path)
hashes_on_device = _ComputeFileListHash(
device_hash_tuples = _ComputeFileListHash(
self.RunShellCommand(cmd, timeout_time=2 * 60))
assert os.path.exists(local_path), 'Local path not found %s' % local_path
md5sum_output = cmd_helper.GetCmdOutput(
['%s/md5sum_bin_host' % self._md5sum_build_dir, local_path])
hashes_on_host = _ComputeFileListHash(md5sum_output.splitlines())
host_hash_tuples = _ComputeFileListHash(md5sum_output.splitlines())
if ignore_paths:
hashes_on_device = [h.split()[0] for h in hashes_on_device]
hashes_on_host = [h.split()[0] for h in hashes_on_host]
# Ignore extra files on the device.
if len(device_hash_tuples) > len(host_hash_tuples):
host_files = [os.path.relpath(os.path.normpath(p.path),
os.path.normpath(local_path)) for p in host_hash_tuples]
def _host_has(fname):
return any(path in fname for path in host_files)
hashes_on_device = [h.hash for h in device_hash_tuples if
_host_has(h.path)]
else:
hashes_on_device = [h.hash for h in device_hash_tuples]
# Compare md5sums between host and device files.
hashes_on_host = [h.hash for h in host_hash_tuples]
hashes_on_device.sort()
hashes_on_host.sort()
return hashes_on_device == hashes_on_host
def PushIfNeeded(self, local_path, device_path):