Skip to content
Snippets Groups Projects
Commit 54ec2fca authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Improve get_contents_error implementation

- Only read the storage key once.
- Improve the logging error.
parent b3c109e4
No related branches found
No related tags found
No related merge requests found
...@@ -164,33 +164,35 @@ class BaseArchiveWorker(config.SWHConfig, metaclass=abc.ABCMeta): ...@@ -164,33 +164,35 @@ class BaseArchiveWorker(config.SWHConfig, metaclass=abc.ABCMeta):
self.content_archive_update( self.content_archive_update(
content_id, archive_id=destination, new_status='present') content_id, archive_id=destination, new_status='present')
def get_contents_error(self, content_ids, storage): def get_contents_error(self, content_ids, source_storage):
""" Indicates what is the error associated to a content when needed """Indicates what is the error associated to a content when needed
Check the given content on the given storage. If an error is detected, Check the given content on the given storage. If an error is detected,
it will be reported through the returned dict. it will be reported through the returned dict.
Args: Args:
content_ids ([sha1]): list of content ids to check content_ids ([sha1]): list of content ids to check
storage (str): the storage where are the content to check. source_storage (str): the source storage holding the
contents to check.
Returns: Returns:
a dict that map {content_id -> error_status} for each content_id a dict that map {content_id -> error_status} for each content_id
with an error. The `error_status` result may be 'missing' or with an error. The `error_status` result may be 'missing' or
'corrupted'. 'corrupted'.
""" """
content_status = {} content_status = {}
storage = self.objstorages[source_storage]
for content_id in content_ids: for content_id in content_ids:
try: try:
self.objstorages[storage].check(content_id) storage.check(content_id)
except Error as e: except Error:
content_status[content_id] = 'corrupted' content_status[content_id] = 'corrupted'
content_id = hashutil.hash_to_hex(content_id) logger.error('%s corrupted!' % hashutil.hash_to_hex(
logger.error(e) content_id))
except ObjNotFoundError as e: except ObjNotFoundError:
content_status[content_id] = 'missing' content_status[content_id] = 'missing'
content_id = hashutil.hash_to_hex(content_id) logger.error('%s missing!' % hashutil.hash_to_hex(content_id))
logger.error(e)
return content_status return content_status
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment