Skip to content

Commit

Permalink
Fixed 500 during image pull when content is missing on the FS.
Browse files Browse the repository at this point in the history
closes pulp#555
  • Loading branch information
ipanova committed Feb 2, 2022
1 parent bc638e0 commit de49c48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES/555.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed 500 during image pull when content is missing on the FS.
14 changes: 7 additions & 7 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from gettext import gettext as _

from asgiref.sync import sync_to_async

Expand Down Expand Up @@ -62,17 +63,16 @@ async def _dispatch(file, headers):
The :class:`aiohttp.web.FileResponse` for the file.
"""
path = os.path.join(settings.MEDIA_ROOT, file.name)
if not os.path.exists(path):
log.warning(_("Expected path '{}' is not found").format(path))
raise PathNotResolved(path)

full_headers = MultiDict()

full_headers["Content-Type"] = headers["Content-Type"]
full_headers["Docker-Content-Digest"] = headers["Docker-Content-Digest"]
full_headers["Docker-Distribution-API-Version"] = "registry/2.0"
full_headers["Content-Length"] = str(file.size)
full_headers["Content-Disposition"] = "attachment; filename={n}".format(
n=os.path.basename(file.name)
)

path = os.path.join(settings.MEDIA_ROOT, file.name)
file_response = web.FileResponse(path, headers=full_headers)
return file_response

Expand Down Expand Up @@ -117,7 +117,7 @@ async def get_tag(self, request):
and tag.tagged_manifest.media_type not in accepted_media_types
):
log.warn(
"OCI format found, but the client only accepts {accepted_media_types}.".format(
_("OCI format found, but the client only accepts {accepted_media_types}.").format(
accepted_media_types=accepted_media_types
)
)
Expand Down
5 changes: 4 additions & 1 deletion pulp_container/app/schema_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,7 @@ def _get_manifest_dict(manifest):


def _get_dict(artifact):
return json.load(artifact.file)
try:
return json.load(artifact.file)
except FileNotFoundError:
raise RuntimeError()

0 comments on commit de49c48

Please sign in to comment.