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"""