summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2018-08-13 19:02:25 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-08-29 15:23:51 +0100
commitee176ddba8739301bea6ca990783773b2e3fbdcb (patch)
tree82b20bb707f90e6bd2e6fc5804f5898b05e0c0bc /bitbake
parent8f7fb9baf82e6c6eea81d8410de91ce08992e314 (diff)
downloadpoky-ee176ddba8739301bea6ca990783773b2e3fbdcb.tar.gz
bitbake: utils/md5_file: don't iterate line-by-line
Opening a file in binary mode and iterating it seems like the simple solution but will still break on newlines, which for binary files isn't really useful as the size of the chunks could be huge or tiny. Instead, let's be a bit more clever: we'll be MD5ing lots of files, but we don't want to fill up memory: use mmap() to open the file and read the file in 8k blocks. (Bitbake rev: 41e6161c8ce8cc90ebc93d72852673ae60fac923) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/utils.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 378e699e0c..2ff7e82222 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -524,12 +524,17 @@ def md5_file(filename):
524 """ 524 """
525 Return the hex string representation of the MD5 checksum of filename. 525 Return the hex string representation of the MD5 checksum of filename.
526 """ 526 """
527 import hashlib 527 import hashlib, mmap
528 m = hashlib.md5()
529 528
530 with open(filename, "rb") as f: 529 with open(filename, "rb") as f:
531 for line in f: 530 m = hashlib.md5()
532 m.update(line) 531 try:
532 with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
533 for chunk in iter(lambda: mm.read(8192), b''):
534 m.update(chunk)
535 except ValueError:
536 # You can't mmap() an empty file so silence this exception
537 pass
533 return m.hexdigest() 538 return m.hexdigest()
534 539
535def sha256_file(filename): 540def sha256_file(filename):