Skip to content

Commit 8834eb3

Browse files
committed
feat(reference): Add clone_with_digest() function
This allows to create a copy of the reference but setting a new digest. This also copies the registry_mirror, so the digest also gets pulled from the same mirror. Signed-off-by: Benjamin Neff <[email protected]>
1 parent 54e63d8 commit 8834eb3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/client.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,11 +867,7 @@ impl Client {
867867
match digest {
868868
Some(digest) => {
869869
debug!("Selected manifest entry with digest: {}", digest);
870-
let manifest_entry_reference = Reference::with_digest(
871-
image.registry().to_string(),
872-
image.repository().to_string(),
873-
digest.clone(),
874-
);
870+
let manifest_entry_reference = image.clone_with_digest(digest.clone());
875871
self._pull_manifest(&manifest_entry_reference)
876872
.await
877873
.and_then(|(manifest, _digest)| match manifest {

src/reference.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ impl Reference {
104104
}
105105
}
106106

107+
/// Clone the Reference for the same image with a new digest.
108+
pub fn clone_with_digest(&self, digest: String) -> Self {
109+
Self {
110+
registry: self.registry.clone(),
111+
mirror_registry: self.mirror_registry.clone(),
112+
repository: self.repository.clone(),
113+
tag: None,
114+
digest: Some(digest),
115+
}
116+
}
117+
107118
/// Set a pull mirror registry for this reference.
108119
///
109120
/// The mirror registry will be used to resolve the image, the original registry

0 commit comments

Comments
 (0)