-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PBENCH-1014 Using Tarball.extract in Inventory API for extracting files from tarball #3105
Changes from all commits
bdfe829
72cb4aa
6d344fe
4db0706
6f0852a
08fa10e
3dbfe84
fe3e748
1c9ee2d
b05aca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
ParamType, | ||
Schema, | ||
) | ||
from pbench.server.cache_manager import CacheManager, TarballNotFound | ||
from pbench.server.cache_manager import CacheManager, CacheType, TarballNotFound | ||
|
||
|
||
class DatasetsInventory(ApiBase): | ||
|
@@ -54,27 +54,18 @@ def _get( | |
APIAbort, reporting either "NOT_FOUND" or "UNSUPPORTED_MEDIA_TYPE" | ||
|
||
|
||
GET /api/v1/datasets/inventory/{dataset}/{target} | ||
GET /api/v1/datasets/{dataset}/inventory/{target} | ||
""" | ||
|
||
dataset = params.uri["dataset"] | ||
target = params.uri.get("target") | ||
|
||
cache_m = CacheManager(self.config, current_app.logger) | ||
try: | ||
tarball = cache_m.find_dataset(dataset.resource_id) | ||
file_info = cache_m.filestream(dataset, target) | ||
except TarballNotFound as e: | ||
raise APIAbort(HTTPStatus.NOT_FOUND, str(e)) | ||
|
||
if target is None: | ||
file_path = tarball.tarball_path | ||
else: | ||
dataset_location = tarball.unpacked | ||
if dataset_location is None: | ||
raise APIAbort(HTTPStatus.NOT_FOUND, "The dataset is not unpacked") | ||
file_path = dataset_location / target | ||
|
||
if file_path.is_file(): | ||
if file_info["type"] == CacheType.FILE: | ||
dbutenhof marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Tell send_file to set `Content-Disposition` to "attachment" if | ||
# targeting the large binary tarball. Otherwise we'll recommend the | ||
# default "inline": only `is_file()` paths are allowed here, and | ||
|
@@ -84,17 +75,15 @@ def _get( | |
# | ||
# NOTE: we could choose to be "smarter" based on file size, file | ||
# type codes (e.g., .csv, .json), and so forth. | ||
return send_file( | ||
file_path, | ||
resp = send_file( | ||
file_info["stream"], | ||
as_attachment=target is None, | ||
download_name=file_path.name, | ||
) | ||
elif file_path.exists(): | ||
raise APIAbort( | ||
HTTPStatus.UNSUPPORTED_MEDIA_TYPE, | ||
"The specified path does not refer to a regular file", | ||
Comment on lines
-93
to
-95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit behind on this one but why are we removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tarball.extract method was handling all error's around this. So, I didn't find the need to include these lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cache manager raises an internal error, but we don't want that to fall through to the generic (internal error) |
||
download_name=file_info["name"], | ||
) | ||
file_info["stream"].close() | ||
return resp | ||
else: | ||
raise APIAbort( | ||
HTTPStatus.NOT_FOUND, "The specified path does not refer to a file" | ||
HTTPStatus.BAD_REQUEST, | ||
"The specified path does not refer to a regular file", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a function named "filestream" return a "file information" dictionary doesn't seem like the best interface. Maybe something somewhat more generic, like "get_file()", would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, reality hasn't kept up with the implementation, and at some point we should consider whipping it into shape.