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
import urlparse
from download import check_md5sum
from slapos.libnetworkcache import NetworkcacheClient, UploadError, \
MultipleFileFoundError, DirectoryNotFound
DirectoryNotFound
_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):
md5sum = _get_md5_from_url(url)
sha512sum = select_sha512sum_from_shadir(sha_dir, url, logger)
if sha512sum is None:
return False
directory_key = get_directory_key(url)
file_name = os.path.basename(url)
sha_cache_url = os.path.join(sha_cache, sha512sum)
logger.info('Downloading from network cache %s' % sha_cache_url)
logger.info('Downloading %s from network cache.' % file_name)
try:
nc = NetworkcacheClient(shacache=sha_cache)
nc.download(path, sha512sum)
nc = NetworkcacheClient(shacache=sha_cache, shadir=sha_dir)
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):
logger.info('MD5 checksum mismatch downloading %r' % sha_cache_url)
logger.info('MD5 checksum mismatch downloading %s' % file_name)
return False
except IOError, e:
except (IOError, DirectoryNotFound), e:
logger.info('Fail to download from network cache %s: %s' % \
(sha_cache_url, str(e)))
(file_name, str(e)))
return False
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