mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Do not use the md5 from cache for a missing image
This commit is contained in:
parent
4aadfa3b67
commit
a8e69d9a0b
@ -27,7 +27,7 @@ def md5sum(path):
|
|||||||
:returns: Digest of the image
|
:returns: Digest of the image
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if path is None or len(path) == 0:
|
if path is None or len(path) == 0 or not os.path.exists(path):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -36,14 +36,18 @@ def md5sum(path):
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
m = hashlib.md5()
|
try:
|
||||||
with open(path, 'rb') as f:
|
m = hashlib.md5()
|
||||||
while True:
|
with open(path, 'rb') as f:
|
||||||
buf = f.read(128)
|
while True:
|
||||||
if not buf:
|
buf = f.read(128)
|
||||||
break
|
if not buf:
|
||||||
m.update(buf)
|
break
|
||||||
digest = m.hexdigest()
|
m.update(buf)
|
||||||
|
digest = m.hexdigest()
|
||||||
|
except OSError as e:
|
||||||
|
log.error("Can't create digest of %s: %s", path, str(e))
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open('{}.md5sum'.format(path), 'w+') as f:
|
with open('{}.md5sum'.format(path), 'w+') as f:
|
||||||
|
@ -34,12 +34,24 @@ def test_md5sum(tmpdir):
|
|||||||
def test_md5sum_existing_digest(tmpdir):
|
def test_md5sum_existing_digest(tmpdir):
|
||||||
fake_img = str(tmpdir / 'hello')
|
fake_img = str(tmpdir / 'hello')
|
||||||
|
|
||||||
|
with open(fake_img, 'w+') as f:
|
||||||
|
f.write('hello')
|
||||||
|
|
||||||
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
|
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
|
||||||
f.write('aaaaa02abc4b2a76b9719d911017c592')
|
f.write('aaaaa02abc4b2a76b9719d911017c592')
|
||||||
|
|
||||||
assert md5sum(fake_img) == 'aaaaa02abc4b2a76b9719d911017c592'
|
assert md5sum(fake_img) == 'aaaaa02abc4b2a76b9719d911017c592'
|
||||||
|
|
||||||
|
|
||||||
|
def test_md5sum_existing_digest_but_missing_image(tmpdir):
|
||||||
|
fake_img = str(tmpdir / 'hello')
|
||||||
|
|
||||||
|
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
|
||||||
|
f.write('aaaaa02abc4b2a76b9719d911017c592')
|
||||||
|
|
||||||
|
assert md5sum(fake_img) is None
|
||||||
|
|
||||||
|
|
||||||
def test_md5sum_none(tmpdir):
|
def test_md5sum_none(tmpdir):
|
||||||
assert md5sum(None) is None
|
assert md5sum(None) is None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user