Skip to content

Commit

Permalink
Fixup some registry things (#2576)
Browse files Browse the repository at this point in the history
* warn instead of error if a registry TOML file has an unexpected format

* also remove compressed file when removing registry
  • Loading branch information
KristofferC authored May 29, 2021
1 parent e75c7d0 commit 6263bcd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Registry/Registry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ rm(regs::Vector{String}; kwargs...) = rm([RegistrySpec(name = name) for name in
function rm(regs::Vector{RegistrySpec}; io::IO=stderr_f())
for registry in find_installed_registries(io, regs)
printpkgstyle(io, :Removing, "registry `$(registry.name)` from $(Base.contractuser(registry.path))")
if isfile(registry.path)
d = TOML.parsefile(registry.path)
if haskey(d, "path")
Base.rm(joinpath(dirname(registry.path), d["path"]); force=true)
end
end
Base.rm(registry.path; force=true, recursive=true)
end
return nothing
Expand Down
26 changes: 25 additions & 1 deletion src/Registry/registry_instance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,26 @@ function create_name_uuid_mapping!(r::RegistryInstance)
return
end

function verify_compressed_registry_toml(path::String)
d = TOML.tryparsefile(path)
if d isa TOML.ParserError
@warn "Failed to parse registry TOML file at $(repr(path))" exception=d
return false
end
for key in ("git-tree-sha1", "uuid", "path")
if !haskey(d, key)
@warn "Expected key $(repr(key)) to exist in registry TOML file at $(repr(path))"
return false
end
end
compressed_file = joinpath(dirname(path), d["path"])
if !isfile(compressed_file)
@warn "Expected the compressed registry for $(repr(path)) to exist at $(repr(compressed_file))"
return false
end
return true
end

function reachable_registries(; depots::Union{String, Vector{String}}=Base.DEPOT_PATH)
# collect registries
if depots isa String
Expand All @@ -340,7 +360,11 @@ function reachable_registries(; depots::Union{String, Vector{String}}=Base.DEPOT
# with the same name
compressed_registry_names = Set([splitext(basename(file))[1] for file in compressed_registries])
filter!(x -> !(basename(x) in compressed_registry_names), candidate_registries)
append!(candidate_registries, compressed_registries)
for compressed_registry in compressed_registries
if verify_compressed_registry_toml(compressed_registry)
push!(candidate_registries, compressed_registry)
end
end
end

for candidate in candidate_registries
Expand Down
2 changes: 2 additions & 0 deletions test/registry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ if Pkg.Registry.registry_use_pkg_server()
""")
end
Pkg.update()
Pkg.Registry.rm(RegistrySpec(name = "General"))
@test isempty(readdir(joinpath(DEPOT_PATH[1], "registries")))
end
end
end
Expand Down

0 comments on commit 6263bcd

Please sign in to comment.