From 9d359709945ec9026564636bb8c313024f3bad75 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 23 Nov 2010 22:16:24 +0000 Subject: [PATCH] - server scripts (e.g. update_versions): compute MD5 checksums be reading files in pieces instead of reading whole file into memory. From Tolu Aina svn path=/trunk/boinc/; revision=22743 --- checkin_notes | 8 ++++++++ py/Boinc/tools.py | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/checkin_notes b/checkin_notes index be879be05a..b60f3c7bcf 100644 --- a/checkin_notes +++ b/checkin_notes @@ -8359,3 +8359,11 @@ David 23 Nov 2010 cpu_sched.cpp lib/ gui_rpc_client_ops.cpp + +David 23 Nov 2010 + - server scripts (e.g. update_versions): + compute MD5 checksums be reading files in pieces instead + of reading whole file into memory. From Tolu Aina + + py/Boinc/ + tools.py diff --git a/py/Boinc/tools.py b/py/Boinc/tools.py index a484c2f3d6..d432114bd8 100644 --- a/py/Boinc/tools.py +++ b/py/Boinc/tools.py @@ -44,8 +44,28 @@ def make_uuid(): return binascii.hexlify(urandom(16)) def md5_file(path): - """Return a 16-digit MD5 hex digest of a file's contents""" - return md5.new(open(path).read()).hexdigest() + """ + Return a 16-digit MD5 hex digest of a file's contents + Read the file in chunks + """ + + chunk = 8096 + + try: + checksum = md5() + except NameError: + checksum = md5.new() + + fp = open(path, 'r') + while True: + buffer = fp.read(chunk) + if not buffer: + break + checksum.update(buffer) + + fp.close() + + return checksum def file_size(path): """Return the size of a file"""