Merge lp:~nickie-7/cubic/fix-md5sum into lp:cubic/classic-development

Proposed by Nikolaos S. Papaspyrou
Status: Merged
Approved by: Cubic PPA
Approved revision: 92
Merged at revision: 92
Proposed branch: lp:~nickie-7/cubic/fix-md5sum
Merge into: lp:cubic/classic-development
Diff against target: 38 lines (+12/-2)
1 file modified
usr/share/cubic/utilities.py (+12/-2)
To merge this branch: bzr merge lp:~nickie-7/cubic/fix-md5sum
Reviewer Review Type Date Requested Status
Cubic PPA Approve
Review via email: mp+321975@code.launchpad.net

Description of the change

This patch uses a buffer for reading the contents of large files, instead of using a single read, when generating MD5 sums.

To post a comment you must log in.
Revision history for this message
Cubic PPA (cubic-wizard) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'usr/share/cubic/utilities.py'
2--- usr/share/cubic/utilities.py 2016-12-30 05:28:22 +0000
3+++ usr/share/cubic/utilities.py 2017-04-05 11:20:20 +0000
4@@ -1187,6 +1187,16 @@
5 with open(filepath, 'w') as file: file.write('%s' % model.custom_iso_image_disk_name)
6
7
8+def buffered_hash_md5(filepath, blocksize=2**20):
9+ m = hashlib.md5()
10+ with open(filepath, 'rb' ) as f:
11+ while True:
12+ buf = f.read(blocksize)
13+ if not buf: break
14+ m.update(buf)
15+ return m.hexdigest()
16+
17+
18 def update_md5_sums():
19 logger.log_note('Updating the md5 sums')
20
21@@ -1197,7 +1207,7 @@
22 for filename in files:
23 if root != './isolinux' and filename != 'md5sum.txt':
24 filepath = os.path.join(root, filename)
25- md5_sum = hashlib.md5(open(filepath, 'rb').read()).hexdigest()
26+ md5_sum = buffered_hash_md5(filepath)
27 md5_sum_file.write('%s %s\n' % (md5_sum, filepath))
28 # logger.log_note('%s %s' % (md5_sum, filepath))
29
30@@ -1299,7 +1309,7 @@
31 def calculate_iso_md5_sum():
32 logger.log_note('Calculating the md5 sum')
33
34- md5_sum = hashlib.md5(open(model.custom_iso_image_filepath, 'rb').read()).hexdigest()
35+ md5_sum = buffered_hash_md5(model.custom_iso_image_filepath)
36 model.set_custom_iso_image_md5_sum(md5_sum)
37
38 with open(model.custom_iso_image_md5_filepath, 'w') as md5_sum_file:

Subscribers

People subscribed via source and target branches