mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-26 00:17:47 -10:00
When I refactored hash_paths to add caching, I mixed things up such that for each file, we end up hashing: (u'$sha256sum', u'$topsrcdir/$relpath') $relpath when the intent was to hash: $sha256sum $relpath This change fixes it, such that now the index paths are independent of the source path, as originally intended.
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
from mozbuild.util import memoize
|
|
from mozpack.files import FileFinder
|
|
import mozpack.path as mozpath
|
|
import hashlib
|
|
|
|
|
|
@memoize
|
|
def _hash_path(path):
|
|
with open(path) as fh:
|
|
return hashlib.sha256(fh.read()).hexdigest()
|
|
|
|
|
|
def hash_paths(base_path, patterns):
|
|
"""
|
|
Give a list of path patterns, return a digest of the contents of all
|
|
the corresponding files, similarly to git tree objects or mercurial
|
|
manifests.
|
|
|
|
Each file is hashed. The list of all hashes and file paths is then
|
|
itself hashed to produce the result.
|
|
"""
|
|
finder = FileFinder(base_path)
|
|
h = hashlib.sha256()
|
|
files = {}
|
|
for pattern in patterns:
|
|
files.update(finder.find(pattern))
|
|
for path in sorted(files.keys()):
|
|
h.update('{} {}\n'.format(
|
|
_hash_path(mozpath.abspath(mozpath.join(base_path, path))),
|
|
mozpath.normsep(path)
|
|
))
|
|
return h.hexdigest()
|