Skip to content

Commit

Permalink
Always try to download the resource since it's hosted externally
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Jovanov committed Aug 14, 2017
1 parent e3391cd commit ac55809
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions ckanext/archiver/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,54 +269,6 @@ def _save(status_id, exception, resource, url_redirected_to=None,
try_as_api = False
requires_archive = True

url = resource['url']
if not url.startswith('http'):
url = config['ckan.site_url'].rstrip('/') + url

hosted_externally = not url.startswith(config['ckan.site_url'])
# if resource.get('resource_type') == 'file.upload' and not hosted_externally:
if resource.get('url_type') == 'upload' and not hosted_externally:
log.info("Won't attemp to archive resource uploaded locally: %s" % resource['url'])

upload = uploader.ResourceUpload(resource)
filepath = upload.get_path(resource['id'])

try:
hash, length = _file_hashnlength(filepath)
except IOError, e:
log.error('Error while accessing local resource %s: %s', filepath, e)

download_status_id = Status.by_text('URL request failed')
_save(download_status_id, e, resource)
return

mimetype = None
headers = None
content_type, content_encoding = mimetypes.guess_type(url)
if content_type:
mimetype = _clean_content_type(content_type)
headers = {'Content-Type': content_type}

download_result_mock = {'mimetype': mimetype,
'size': length,
'hash': hash,
'headers': headers,
'saved_file': filepath,
'url_redirected_to': url,
'request_type': 'GET'}

archive_result_mock = {'cache_filepath': filepath,
'cache_url': url}

# Success
_save(Status.by_text('Archived successfully'), '', resource,
download_result_mock['url_redirected_to'], download_result_mock, archive_result_mock)

# The return value is only used by tests. Serialized for Celery.
return json.dumps(dict(download_result_mock, **archive_result_mock))
# endif: processing locally uploaded resource


log.info("Attempting to download resource: %s" % resource['url'])
download_result = None
download_status_id = Status.by_text('Archived successfully')
Expand Down

0 comments on commit ac55809

Please sign in to comment.