Commit a1a9b9be authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed missing files in entry raw download. Added strip param to all entry downloads.

parent 43e53ada
Pipeline #62817 passed with stages
in 23 minutes and 34 seconds
......@@ -118,7 +118,7 @@ class RawFiles extends React.Component {
</FormLabel>
<Download component={IconButton} disabled={selectedFiles.length === 0}
tooltip="download selected files"
url={(selectedFiles.length === 1) ? `raw/${uploadId}/${selectedFiles[0]}` : `raw/${uploadId}?files=${encodeURIComponent(selectedFiles.map(file => `$${file}`).join(','))}`}
url={(selectedFiles.length === 1) ? `raw/${uploadId}/${selectedFiles[0]}` : `raw/${uploadId}?files=${encodeURIComponent(selectedFiles.join(','))}&strip=true`}
fileName={selectedFiles.length === 1 ? this.label(selectedFiles[0]) : `${calcId}.zip`}
>
<DownloadIcon />
......
......@@ -179,7 +179,7 @@ class RepoEntryView extends React.Component {
disabled={!mainfile} tooltip="download all raw files for calculation"
classes={{root: classes.downloadFab}}
component={Fab} className={classes.downloadFab} color="primary" size="medium"
url={`raw/${uploadId}/${calcPath}/*`} fileName={`${calcId}.zip`}
url={`raw/${uploadId}/${calcPath}/*?strip=true`} fileName={`${calcId}.zip`}
>
<DownloadIcon />
</Download>
......
......@@ -56,8 +56,13 @@ raw_file_list_model = api.model('RawFileList', {
raw_file_compress_argument = dict(
name='compress', type=bool, help='Use compression on .zip files, default is not.',
location='args')
raw_file_strip_argument = dict(
name='strip', type=bool, help='Removes a potential common path prefix from all file paths.',
location='args')
raw_file_from_path_parser = api.parser()
raw_file_from_path_parser.add_argument(**raw_file_compress_argument)
raw_file_from_path_parser.add_argument(**raw_file_strip_argument)
raw_file_from_path_parser.add_argument(**signature_token_argument)
raw_file_from_path_parser.add_argument(
name='length', type=int, help='Download only x bytes from the given file.',
......@@ -120,7 +125,9 @@ def get_raw_file_from_upload_path(
abort(404, message='There are no files for %s.' % upload_filepath)
else:
compress = request.args.get('compress', None) is not None
return respond_to_get_raw_files(upload_files.upload_id, wildcarded_files, compress)
strip = request.args.get('strip', None) is not None
return respond_to_get_raw_files(
upload_files.upload_id, wildcarded_files, compress=compress, strip=strip)
try:
with upload_files.raw_file(upload_filepath, 'br') as raw_file:
......@@ -296,6 +303,7 @@ raw_files_request_model = api.model('RawFilesRequest', {
raw_files_request_parser = api.parser()
raw_files_request_parser.add_argument(
'files', required=True, type=str, help='Comma separated list of files to download.', location='args')
raw_files_request_parser.add_argument(**raw_file_strip_argument)
raw_files_request_parser.add_argument(**raw_file_compress_argument)
raw_file_from_path_parser.add_argument(**signature_token_argument)
......@@ -335,23 +343,23 @@ class RawFilesResource(Resource):
Zip files are streamed; instead of 401 errors, the zip file will just not contain
any files that the user is not authorized to access.
"""
files_str = request.args.get('files', None)
compress = request.args.get('compress', 'false') == 'true'
args = raw_files_request_parser.parse_args()
files_str = args.get('files')
compress = args.get('compress', False)
strip = args.get('strip', False)
if files_str is None:
abort(400, message="No files argument given.")
files = [file.strip() for file in files_str.split(',')]
return respond_to_get_raw_files(upload_id, files, compress)
return respond_to_get_raw_files(upload_id, files, compress=compress, strip=strip)
raw_file_from_query_parser = search_request_parser.copy()
raw_file_from_query_parser.add_argument(
name='compress', type=bool, help='Use compression on .zip files, default is not.',
location='args')
raw_file_from_query_parser.add_argument(
name='strip', type=bool, help='Removes a potential common path prefix from all file paths.',
location='args')
raw_file_from_query_parser.add_argument(**raw_file_strip_argument)
raw_file_from_query_parser.add_argument(
name='file_pattern', type=str,
help=(
......@@ -459,7 +467,7 @@ class RawFileQueryResource(Resource):
manifest=manifest_contents)
def respond_to_get_raw_files(upload_id, files, compress=False):
def respond_to_get_raw_files(upload_id, files, compress=False, strip=False):
upload_files = UploadFiles.get(
upload_id, create_authorization_predicate(upload_id))
if upload_files is None:
......@@ -472,9 +480,14 @@ def respond_to_get_raw_files(upload_id, files, compress=False):
else:
zipfile_cache = contextlib.suppress()
if strip:
common_prefix_len = len(utils.common_prefix(files))
else:
common_prefix_len = 0
with zipfile_cache:
return _streamed_zipfile(
[(filename, filename, upload_files) for filename in files],
[(filename[common_prefix_len:], filename, upload_files) for filename in files],
zipfile_name='%s.zip' % upload_id, compress=compress)
......
......@@ -1098,17 +1098,19 @@ class TestRaw(UploadFilesBasedTests):
rv = api.get(url, headers=auth_headers)
assert rv.status_code == 404
@pytest.mark.parametrize('compress', [True, False])
@pytest.mark.parametrize('compress, strip', [(True, False), (False, False), (False, True)])
@UploadFilesBasedTests.check_authorization
def test_raw_files(self, api, upload, auth_headers, compress):
def test_raw_files(self, api, upload, auth_headers, compress, strip):
url = '/raw/%s?files=%s' % (
upload, ','.join(example_file_contents))
if compress:
url = '%s&compress=1' % url
if strip:
url = '%s&strip=1' % url
rv = api.get(url, headers=auth_headers)
assert rv.status_code == 200
self.assert_zip_file(rv, files=len(example_file_contents))
self.assert_zip_file(rv, files=len(example_file_contents), basename=strip)
@pytest.mark.parametrize('compress', [False, True])
def test_raw_files_from_query_upload_id(self, api, non_empty_processed, test_user_auth, compress):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment