Add function in data interface for mounting blobs into other repositories
This commit is contained in:
parent
03789b2210
commit
818ed32f87
3 changed files with 49 additions and 0 deletions
|
@ -690,5 +690,22 @@ class PreOCIModel(RegistryDataInterface):
|
|||
return Blob.for_image_storage(blob_record,
|
||||
storage_path=model.storage.get_layer_path(blob_record))
|
||||
|
||||
def mount_blob_into_repository(self, blob, target_repository_ref, expiration_sec):
|
||||
"""
|
||||
Mounts the blob from another repository into the specified target repository, and adds an
|
||||
expiration before that blob is automatically GCed. This function is useful during push
|
||||
operations if an existing blob from another repositroy is being pushed. Returns False if
|
||||
the mounting fails.
|
||||
"""
|
||||
repo = model.repository.lookup_repository(target_repository_ref._db_id)
|
||||
if repo is None:
|
||||
return False
|
||||
|
||||
namespace_name = repo.namespace_user.username
|
||||
repo_name = repo.name
|
||||
|
||||
storage = model.blob.temp_link_blob(namespace_name, repo_name, blob.digest,
|
||||
expiration_sec)
|
||||
return bool(storage)
|
||||
|
||||
pre_oci_model = PreOCIModel()
|
||||
|
|
Reference in a new issue