From ac558099e6cf3222d7eda50a318a0e37a6b89373 Mon Sep 17 00:00:00 2001 From: Aleksandar Jovanov Date: Mon, 14 Aug 2017 12:58:35 +0200 Subject: [PATCH] Always try to download the resource since it's hosted externally --- ckanext/archiver/tasks.py | 48 --------------------------------------- 1 file changed, 48 deletions(-) diff --git a/ckanext/archiver/tasks.py b/ckanext/archiver/tasks.py index 0d4adb09..266bc67b 100644 --- a/ckanext/archiver/tasks.py +++ b/ckanext/archiver/tasks.py @@ -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')