From 5f2b365faa456990dfa65c7d4ba3393168069f67 Mon Sep 17 00:00:00 2001 From: khassen Date: Thu, 13 Nov 2014 20:58:00 -0500 Subject: [PATCH] Use the common/shared MD5 function. --- cloud/amazon/s3.py | 13 ++----------- cloud/google/gc_storage.py | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/cloud/amazon/s3.py b/cloud/amazon/s3.py index 072c8bc40d4..e6b511b36b8 100644 --- a/cloud/amazon/s3.py +++ b/cloud/amazon/s3.py @@ -175,7 +175,6 @@ EXAMPLES = ''' import os import urlparse -import hashlib from ssl import SSLError try: @@ -356,13 +355,6 @@ def is_walrus(s3_url): else: return False -def get_md5_digest(local_file): - md5 = hashlib.md5() - with open(local_file, 'rb') as f: - for data in f.read(1024 ** 2): - md5.update(data) - return md5.hexdigest() - def main(): argument_spec = ec2_argument_spec() @@ -488,8 +480,7 @@ def main(): # Compare the remote MD5 sum of the object with the local dest md5sum, if it already exists. if pathrtn is True: md5_remote = keysum(module, s3, bucket, obj, version=version) - md5_local = get_md5_digest(dest) - + md5_local = module.md5(dest) if md5_local == md5_remote: sum_matches = True if overwrite == 'always': @@ -532,7 +523,7 @@ def main(): # Lets check key state. Does it exist and if it does, compute the etag md5sum. if bucketrtn is True and keyrtn is True: md5_remote = keysum(module, s3, bucket, obj) - md5_local = get_md5_digest(src) + md5_local = module.md5(src) if md5_local == md5_remote: sum_matches = True diff --git a/cloud/google/gc_storage.py b/cloud/google/gc_storage.py index 280bc42a219..c1e6f5707a6 100644 --- a/cloud/google/gc_storage.py +++ b/cloud/google/gc_storage.py @@ -284,7 +284,7 @@ def get_download_url(module, gs, bucket, obj, expiry): def handle_get(module, gs, bucket, obj, overwrite, dest): md5_remote = keysum(module, gs, bucket, obj) - md5_local = hashlib.md5(open(dest, 'rb').read()).hexdigest() + md5_local = module.md5(dest) if md5_local == md5_remote: module.exit_json(changed=False) if md5_local != md5_remote and not overwrite: @@ -300,7 +300,7 @@ def handle_put(module, gs, bucket, obj, overwrite, src, expiration): # Lets check key state. Does it exist and if it does, compute the etag md5sum. if bucket_rc and key_rc: md5_remote = keysum(module, gs, bucket, obj) - md5_local = hashlib.md5(open(src, 'rb').read()).hexdigest() + md5_local = module.md5(src) if md5_local == md5_remote: module.exit_json(msg="Local and remote object are identical", changed=False) if md5_local != md5_remote and not overwrite: