From a5f240eef9bf813dd8f87013e981139a739d8fd2 Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Fri, 3 May 2024 15:13:37 +0100 Subject: [PATCH] Check that a registry has the correct versions of stripped packages This handles cases where a package has migrated between registries, such as moving from a closed source registry to the General registry. Only accept the registry metadata if there is a matching version. --- src/code_stripping.jl | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/code_stripping.jl b/src/code_stripping.jl index f743854..179b3ad 100644 --- a/src/code_stripping.jl +++ b/src/code_stripping.jl @@ -153,28 +153,39 @@ function _generate_stripped_registry(; found = false for reg in registries if haskey(reg, package_uuid) - found = true - info = get!(() -> _process_reg_info(reg), registry_info, reg.uuid) pkg_entry = reg[package_uuid] pkg_path = pkg_entry.path - stripped_info = get!(Dict, registry_contents, pkg_path) - for (k, v) in info[pkg_path] - k == "Versions.toml" && continue - stripped_info[k] = v - end + # Package versions may be split across multiple registries + # if they have been migrated from closed source to open, for + # example. We verify that the registry we're currently + # looking through has the package version that we want. + if haskey( + get(Dict{String,Any}, info[pkg_path], "Versions.toml"), + version, + ) + found = true - versions_toml = get!(Dict{String,Any}, stripped_info, "Versions.toml") - versions_toml[version] = Dict{String,Any}("git-tree-sha1" => tree_hash) + stripped_info = get!(Dict, registry_contents, pkg_path) + for (k, v) in info[pkg_path] + k == "Versions.toml" && continue + stripped_info[k] = v + end - project_toml = get!(Dict{String,Any}, stripped_info, "Package.toml") - project_toml["repo"] = "{{PACKAGES}}/$package_name" + versions_toml = + get!(Dict{String,Any}, stripped_info, "Versions.toml") + versions_toml[version] = + Dict{String,Any}("git-tree-sha1" => tree_hash) - packages[string(package_uuid)] = - Dict("name" => pkg_entry.name, "path" => pkg_path) + project_toml = get!(Dict{String,Any}, stripped_info, "Package.toml") + project_toml["repo"] = "{{PACKAGES}}/$package_name" - break + packages[string(package_uuid)] = + Dict("name" => pkg_entry.name, "path" => pkg_path) + + break + end end end if !found