Commit 0d5c1c7a authored by Lucas Carvalho's avatar Lucas Carvalho

following last modification on libnetworkcache.

the behavior still the same.
parent 08aa5cab
...@@ -21,7 +21,7 @@ import urllib ...@@ -21,7 +21,7 @@ import urllib
import urlparse import urlparse
from download import check_md5sum from download import check_md5sum
from slapos.libnetworkcache import NetworkcacheClient, UploadError, \ from slapos.libnetworkcache import NetworkcacheClient, UploadError, \
MultipleFileFoundError, DirectoryNotFound DirectoryNotFound
_md5_re = re.compile(r'md5=([a-f0-9]+)') _md5_re = re.compile(r'md5=([a-f0-9]+)')
...@@ -81,21 +81,27 @@ def download_network_cached(sha_dir, sha_cache, path, url, logger, md5sum=None): ...@@ -81,21 +81,27 @@ def download_network_cached(sha_dir, sha_cache, path, url, logger, md5sum=None):
md5sum = _get_md5_from_url(url) md5sum = _get_md5_from_url(url)
sha512sum = select_sha512sum_from_shadir(sha_dir, url, logger) directory_key = get_directory_key(url)
if sha512sum is None: file_name = os.path.basename(url)
return False
sha_cache_url = os.path.join(sha_cache, sha512sum) logger.info('Downloading %s from network cache.' % file_name)
logger.info('Downloading from network cache %s' % sha_cache_url)
try: try:
nc = NetworkcacheClient(shacache=sha_cache) nc = NetworkcacheClient(shacache=sha_cache, shadir=sha_dir)
nc.download(path, sha512sum) file_content = nc.select(directory_key)
f = open(path, 'w+b')
try:
f.write(file_content)
finally:
f.close()
if not check_md5sum(path, md5sum): if not check_md5sum(path, md5sum):
logger.info('MD5 checksum mismatch downloading %r' % sha_cache_url) logger.info('MD5 checksum mismatch downloading %s' % file_name)
return False return False
except IOError, e:
except (IOError, DirectoryNotFound), e:
logger.info('Fail to download from network cache %s: %s' % \ logger.info('Fail to download from network cache %s: %s' % \
(sha_cache_url, str(e))) (file_name, str(e)))
return False return False
return True return True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment