mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #559 from jkleint/iterative-md5
Use iterative MD5 hashing.
This commit is contained in:
commit
238e4adba2
4 changed files with 60 additions and 49 deletions
|
@ -33,11 +33,9 @@ except ImportError:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import hashlib
|
from hashlib import md5 as _md5
|
||||||
HAVE_HASHLIB=True
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import md5
|
from md5 import md5 as _md5
|
||||||
HAVE_HASHLIB=False
|
|
||||||
|
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
import ansible.constants as C
|
import ansible.constants as C
|
||||||
|
@ -321,13 +319,19 @@ def parse_kv(args):
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def md5(filename):
|
def md5(filename):
|
||||||
''' compute md5sum, return None if file is not present '''
|
''' Return MD5 hex digest of local file, or None if file is not present. '''
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return None
|
return None
|
||||||
if HAVE_HASHLIB:
|
digest = _md5()
|
||||||
return hashlib.md5(file(filename).read()).hexdigest()
|
blocksize = 64 * 1024
|
||||||
else:
|
infile = open(filename, 'rb')
|
||||||
return md5.new(file(filename).read()).hexdigest()
|
block = infile.read(blocksize)
|
||||||
|
while block:
|
||||||
|
digest.update(block)
|
||||||
|
block = infile.read(blocksize)
|
||||||
|
infile.close()
|
||||||
|
return digest.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
|
@ -30,14 +30,10 @@ import syslog
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import hashlib
|
from hashlib import md5 as _md5
|
||||||
HAVE_HASHLIB=True
|
except ImportError:
|
||||||
except ImportError:
|
from md5 import md5 as _md5
|
||||||
import md5
|
|
||||||
HAVE_HASHLIB=False
|
|
||||||
|
|
||||||
# Since hashlib is only available in 2.5 and onwards, this module
|
|
||||||
# uses md5 which is available in 2.4.
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Support methods
|
# Support methods
|
||||||
|
@ -66,13 +62,18 @@ def write_temp_file(data):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def md5(filename):
|
def md5(filename):
|
||||||
''' compute md5sum, return None if file is not present '''
|
''' Return MD5 hex digest of local file, or None if file is not present. '''
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return None
|
return None
|
||||||
if HAVE_HASHLIB:
|
digest = _md5()
|
||||||
return hashlib.md5(file(filename).read()).hexdigest()
|
blocksize = 64 * 1024
|
||||||
else:
|
infile = open(filename, 'rb')
|
||||||
return md5.new(file(filename).read()).hexdigest()
|
block = infile.read(blocksize)
|
||||||
|
while block:
|
||||||
|
digest.update(block)
|
||||||
|
block = infile.read(blocksize)
|
||||||
|
infile.close()
|
||||||
|
return digest.hexdigest()
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
|
|
27
library/copy
27
library/copy
|
@ -25,11 +25,9 @@ import shutil
|
||||||
import syslog
|
import syslog
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import hashlib
|
from hashlib import md5 as _md5
|
||||||
HAVE_HASHLIB=True
|
except ImportError:
|
||||||
except ImportError:
|
from md5 import md5 as _md5
|
||||||
import md5
|
|
||||||
HAVE_HASHLIB=False
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# convert arguments of form a=b c=d
|
# convert arguments of form a=b c=d
|
||||||
|
@ -46,13 +44,18 @@ def exit_kv(rc=0, **kwargs):
|
||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
|
|
||||||
def md5(filename):
|
def md5(filename):
|
||||||
''' compute md5sum, return None if file is not present '''
|
''' Return MD5 hex digest of local file, or None if file is not present. '''
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return None
|
return None
|
||||||
if HAVE_HASHLIB:
|
digest = _md5()
|
||||||
return hashlib.md5(file(filename).read()).hexdigest()
|
blocksize = 64 * 1024
|
||||||
else:
|
infile = open(filename, 'rb')
|
||||||
return md5.new(file(filename).read()).hexdigest()
|
block = infile.read(blocksize)
|
||||||
|
while block:
|
||||||
|
digest.update(block)
|
||||||
|
block = infile.read(blocksize)
|
||||||
|
infile.close()
|
||||||
|
return digest.hexdigest()
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,9 @@ import traceback
|
||||||
import syslog
|
import syslog
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import hashlib
|
from hashlib import md5 as _md5
|
||||||
HAVE_HASHLIB=True
|
except ImportError:
|
||||||
except ImportError:
|
from md5 import md5 as _md5
|
||||||
import md5
|
|
||||||
HAVE_HASHLIB=False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import selinux
|
import selinux
|
||||||
|
@ -319,13 +317,18 @@ def ansible_facts():
|
||||||
return facts
|
return facts
|
||||||
|
|
||||||
def md5(filename):
|
def md5(filename):
|
||||||
''' compute md5sum, return None if file is not present '''
|
''' Return MD5 hex digest of local file, or None if file is not present. '''
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return None
|
return None
|
||||||
if HAVE_HASHLIB:
|
digest = _md5()
|
||||||
return hashlib.md5(file(filename).read()).hexdigest()
|
blocksize = 64 * 1024
|
||||||
else:
|
infile = open(filename, 'rb')
|
||||||
return md5.new(file(filename).read()).hexdigest()
|
block = infile.read(blocksize)
|
||||||
|
while block:
|
||||||
|
digest.update(block)
|
||||||
|
block = infile.read(blocksize)
|
||||||
|
infile.close()
|
||||||
|
return digest.hexdigest()
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue