Skip to content

Commit

Permalink
avoid name collisions in support files
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelmuller committed Sep 20, 2017
1 parent 0747ab1 commit 84da6bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions fame/core/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ def add_support_file(self, module_name, name, filepath):
self.log('debug', "Adding support file '{}' at '{}'".format(name, filepath))

if fame_config.remote:
response = send_file_to_remote(filepath, '/analyses/{}/support_file'.format(self['_id']))
response = send_file_to_remote(filepath, '/analyses/{}/support_file/{}'.format(self['_id'], module_name))
dstfilepath = response.json()['path']
else:
dirpath = os.path.join(fame_config.storage_path, 'support_files', str(self['_id']))
dirpath = os.path.join(fame_config.storage_path, 'support_files', module_name, str(self['_id']))
dstfilepath = os.path.join(dirpath, os.path.basename(filepath))

# Create parent dirs if they don't exist
Expand Down
2 changes: 1 addition & 1 deletion web/templates/analyses/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% macro support_files(module) -%}
{% if 'support_files' in analysis %}
{% for support_file in analysis.support_files[module] %}
<li><a href="{{url_for('AnalysesView:download_support_file', id=analysis._id, filename=support_file[1])}}" target="_blank"><i class="pe-7s-link"></i> Download {{support_file[0]}}</a></li>
<li><a href="{{url_for('AnalysesView:download_support_file', id=analysis._id, module=module, filename=support_file[1])}}" target="_blank"><i class="pe-7s-link"></i> Download {{support_file[0]}}</a></li>
{{name}}
{% endfor %}
{% endif %}
Expand Down
24 changes: 17 additions & 7 deletions web/views/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,22 +346,32 @@ def add_generated_file(self, id):
return jsonify({'path': filepath})

@requires_permission('worker')
@route('/<id>/support_file', methods=['POST'])
def add_support_file(self, id):
filepath = self._save_analysis_file(id, os.path.join(fame_config.storage_path, 'support_files'))
@route('/<id>/support_file/<module>', methods=['POST'])
def add_support_file(self, id, module):
filepath = self._save_analysis_file(id, os.path.join(fame_config.storage_path, 'support_files', module))

return jsonify({'path': filepath})

@route('/<id>/download/<filename>')
def download_support_file(self, id, filename):
@route('/<id>/download/<module>/<filename>')
def download_support_file(self, id, module, filename):
"""Download a support file.
.. :quickref: Analysis; Download a support file.
:param id: id of the analysis.
:param module: name of the module.
:param filename: name of the file to download.
"""
analysis = get_or_404(current_user.analyses, _id=id)
filepath = os.path.join(fame_config.storage_path, 'support_files', str(analysis['_id']), secure_filename(filename))

return file_download(filepath)
filepath = os.path.join(fame_config.storage_path, 'support_files', module, str(analysis['_id']), secure_filename(filename))
if os.path.isfile(filepath):
return file_download(filepath)
else:
# This code is here for compatibility
# with older analyses
filepath = os.path.join(fame_config.storage_path, 'support_files', str(analysis['_id']), secure_filename(filename))
if os.path.isfile(filepath):
return file_download(filepath)
else:
abort(404)

0 comments on commit 84da6bd

Please sign in to comment.