From e5a564ef17990ba4b7c6db6381ef8fb98cd5bab9 Mon Sep 17 00:00:00 2001 From: guerler Date: Wed, 28 Mar 2018 22:29:16 -0400 Subject: [PATCH] Add additional checks for installed repository handler, open files using with-block --- lib/galaxy/webapps/galaxy/api/workflows.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index 1e269e762557..6fed3e48fc98 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -283,10 +283,15 @@ def create(self, trans, payload, **kwd): if 'installed_repository_file' in payload: installed_repository_file = payload.get('installed_repository_file', '') - workflow_file = open(installed_repository_file, 'rb') - workflow_data = workflow_file.read() - workflow_file.close() - return self.__api_import_from_archive(trans, workflow_data) + if not os.path.exists(installed_repository_file): + raise exceptions.MessageException("Repository file '%s' not found.") + elif os.path.getsize(os.path.abspath(installed_repository_file)) > 0: + workflow_data = None + with open(installed_repository_file, 'rb') as f: + workflow_data = f.read() + return self.__api_import_from_archive(trans, workflow_data) + else: + raise exceptions.MessageException("You attempted to open an empty file.") if 'archive_source' in payload: archive_source = payload['archive_source'] @@ -305,7 +310,7 @@ def create(self, trans, payload, **kwd): else: raise exceptions.MessageException("You attempted to upload an empty file.") else: - raise exceptions.MessageException("Please provide a url or file.") + raise exceptions.MessageException("Please provide a URL or file.") return self.__api_import_from_archive(trans, archive_data) if 'from_history_id' in payload: