Use the common/shared MD5 function.
This commit is contained in:
parent
03a809a21c
commit
5f2b365faa
2 changed files with 4 additions and 13 deletions
|
@ -175,7 +175,6 @@ EXAMPLES = '''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import urlparse
|
import urlparse
|
||||||
import hashlib
|
|
||||||
from ssl import SSLError
|
from ssl import SSLError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -356,13 +355,6 @@ def is_walrus(s3_url):
|
||||||
else:
|
else:
|
||||||
return False
|
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():
|
def main():
|
||||||
argument_spec = ec2_argument_spec()
|
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.
|
# Compare the remote MD5 sum of the object with the local dest md5sum, if it already exists.
|
||||||
if pathrtn is True:
|
if pathrtn is True:
|
||||||
md5_remote = keysum(module, s3, bucket, obj, version=version)
|
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:
|
if md5_local == md5_remote:
|
||||||
sum_matches = True
|
sum_matches = True
|
||||||
if overwrite == 'always':
|
if overwrite == 'always':
|
||||||
|
@ -532,7 +523,7 @@ def main():
|
||||||
# Lets check key state. Does it exist and if it does, compute the etag md5sum.
|
# Lets check key state. Does it exist and if it does, compute the etag md5sum.
|
||||||
if bucketrtn is True and keyrtn is True:
|
if bucketrtn is True and keyrtn is True:
|
||||||
md5_remote = keysum(module, s3, bucket, obj)
|
md5_remote = keysum(module, s3, bucket, obj)
|
||||||
md5_local = get_md5_digest(src)
|
md5_local = module.md5(src)
|
||||||
|
|
||||||
if md5_local == md5_remote:
|
if md5_local == md5_remote:
|
||||||
sum_matches = True
|
sum_matches = True
|
||||||
|
|
|
@ -284,7 +284,7 @@ def get_download_url(module, gs, bucket, obj, expiry):
|
||||||
|
|
||||||
def handle_get(module, gs, bucket, obj, overwrite, dest):
|
def handle_get(module, gs, bucket, obj, overwrite, dest):
|
||||||
md5_remote = keysum(module, gs, bucket, obj)
|
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:
|
if md5_local == md5_remote:
|
||||||
module.exit_json(changed=False)
|
module.exit_json(changed=False)
|
||||||
if md5_local != md5_remote and not overwrite:
|
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.
|
# Lets check key state. Does it exist and if it does, compute the etag md5sum.
|
||||||
if bucket_rc and key_rc:
|
if bucket_rc and key_rc:
|
||||||
md5_remote = keysum(module, gs, bucket, obj)
|
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:
|
if md5_local == md5_remote:
|
||||||
module.exit_json(msg="Local and remote object are identical", changed=False)
|
module.exit_json(msg="Local and remote object are identical", changed=False)
|
||||||
if md5_local != md5_remote and not overwrite:
|
if md5_local != md5_remote and not overwrite:
|
||||||
|
|
Loading…
Reference in a new issue