Skip to content

Commit

Permalink
Support for packages with same UUID name in multiple registries (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdayanand authored and StefanKarpinski committed Dec 27, 2017
1 parent 3b86007 commit 317e312
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ find_registered!(env::EnvCache)::Void =
"Get registered uuids associated with a package name"
function registered_uuids(env::EnvCache, name::String)::Vector{UUID}
find_registered!(env, [name], UUID[])
return env.uuids[name]
return unique(env.uuids[name])
end

"Get registered paths associated with a package uuid"
Expand All @@ -1028,21 +1028,36 @@ end
function registered_uuid(env::EnvCache, name::String)::UUID
uuids = registered_uuids(env, name)
length(uuids) == 0 && return UUID(zero(UInt128))
length(uuids) == 1 && return uuids[1]
choices::Vector{String} = []
choices_cache::Vector{Tuple{UUID, String}} = []
for uuid in uuids
values = registered_info(env, uuid, "repo")
for value in values
push!(choices, "Registry: $(split(value[1],"/")[end-2]) - Path: $(value[2])")
push!(choices_cache, (uuid, value[1]))
end
end
length(choices_cache) == 1 && return choices_cache[1][1]
# prompt for which UUID was intended:
choices = ["$uuid$(registered_info(env, uuid, "repo"))" for uuid in uuids]
menu = RadioMenu(choices)
choice = request("There are multiple registered `$name` packages, choose one:", menu)
choice == -1 && return UUID(zero(UInt128))
return uuids[choice]
env.paths[choices_cache[choice][1]] = [choices_cache[choice][2]]
return choices_cache[choice][1]
end

"Determine current name for a given package UUID"
function registered_name(env::EnvCache, uuid::UUID)::String
names = registered_names(env, uuid)
length(names) == 0 && return ""
length(names) == 1 && return names[1]
return registered_info(env, uuid, "name")
values = registered_info(env, uuid, "name")
name = nothing
for value in values
name == nothing && (name = value[2])
name != value[2] && cmderror("package `$uuid` has multiple registered name values: $name, $(value[2])")
end
return name
end

"Return most current package info for a registered UUID"
Expand All @@ -1051,13 +1066,11 @@ function registered_info(env::EnvCache, uuid::UUID, key::String)
isempty(paths) && cmderror("`$uuid` is not registered")
values = []
for path in paths
info = parse_toml(paths[1], "package.toml")
info = parse_toml(path, "package.toml")
value = get(info, key, nothing)
value in values || push!(values, value)
push!(values, (path, value))
end
length(values) > 1 &&
cmderror("package `$uuid` has multiple registered `$key` values: ", join(values, ", "))
return values[1]
return values
end

"Find package by UUID in the manifest file"
Expand Down

0 comments on commit 317e312

Please sign in to comment.