From e137ca9efd51c53939df9b426bb99858540e5ec5 Mon Sep 17 00:00:00 2001 From: Fabrizio Sestito Date: Sat, 9 Sep 2023 12:15:51 +0200 Subject: [PATCH] fix: add latest tag when no tag is present Signed-off-by: Fabrizio Sestito --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 891f88e..b85a6aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,7 +93,7 @@ pub async fn fetch_policy( "registry" | "http" | "https" => Ok(()), _ => Err(anyhow!("unknown scheme: {}", url.scheme())), }?; - let (store, destination) = pull_destination(&url, &destination)?; + let (store, mut destination) = pull_destination(&url, &destination)?; if let Some(store) = store { store.ensure(&store.policy_full_path(url.as_str(), store::PolicyPath::PrefixOnly)?)?; } @@ -107,6 +107,11 @@ pub async fn fetch_policy( local_path: destination, }); } + // If the reference tag is `latest` and the URL does not contain `:latest` + // we need to add it to the destination + if Some("latest") == reference.tag() && !str::ends_with(url.as_str(), ":latest") { + destination = PathBuf::from(destination.to_string_lossy().to_string() + ":latest"); + } } "http" | "https" => { if Path::exists(&destination) {