Skip to content

Commit 64015f7

Browse files
KenoKristofferC
authored andcommitted
Registry: Properly pass down depot (#4268)
(cherry picked from commit e02bcab)
1 parent 12bc31e commit 64015f7

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/Pkg.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ public activate, add, build, compat, develop, free, gc, generate, instantiate,
2121
pin, precompile, redo, rm, resolve, status, test, undo, update, why
2222

2323
depots() = Base.DEPOT_PATH
24-
function depots1()
25-
d = depots()
26-
isempty(d) && Pkg.Types.pkgerror("no depots found in DEPOT_PATH")
27-
return d[1]
24+
function depots1(depot_list::Union{String, Vector{String}}=depots())
25+
# Get the first depot from a list, with proper error handling
26+
if depot_list isa String
27+
return depot_list
28+
else
29+
isempty(depot_list) && Pkg.Types.pkgerror("no depots provided")
30+
return depot_list[1]
31+
end
2832
end
2933

3034
function pkg_server()

src/Registry/Registry.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Registry
22

33
import ..Pkg
4-
using ..Pkg: depots1, printpkgstyle, stderr_f, isdir_nothrow, pathrepr, pkg_server,
4+
using ..Pkg: depots, depots1, printpkgstyle, stderr_f, isdir_nothrow, pathrepr, pkg_server,
55
GitTools
66
using ..Pkg.PlatformEngines: download_verify_unpack, download, download_verify, exe7z, verify_archive_tree_hash
77
using UUIDs, LibGit2, TOML, Dates
@@ -48,11 +48,11 @@ function add(; name=nothing, uuid=nothing, url=nothing, path=nothing, linked=not
4848
add([RegistrySpec(; name, uuid, url, path, linked)]; kwargs...)
4949
end
5050
end
51-
function add(regs::Vector{RegistrySpec}; io::IO=stderr_f(), depot=depots1())
51+
function add(regs::Vector{RegistrySpec}; io::IO=stderr_f(), depots::Union{String, Vector{String}}=depots())
5252
if isempty(regs)
53-
download_default_registries(io, only_if_empty = false; depot)
53+
download_default_registries(io, only_if_empty = false; depots=depots)
5454
else
55-
download_registries(io, regs, depot)
55+
download_registries(io, regs, depots)
5656
end
5757
end
5858

@@ -103,20 +103,23 @@ end
103103

104104
pkg_server_url_hash(url::String) = Base.SHA1(split(url, '/')[end])
105105

106-
function download_default_registries(io::IO; only_if_empty::Bool = true, depot=depots1())
107-
installed_registries = reachable_registries()
106+
function download_default_registries(io::IO; only_if_empty::Bool = true, depots::Union{String, Vector{String}}=depots())
107+
# Check the specified depots for installed registries
108+
installed_registries = reachable_registries(; depots)
108109
# Only clone if there are no installed registries, unless called
109110
# with false keyword argument.
110111
if isempty(installed_registries) || !only_if_empty
111-
printpkgstyle(io, :Installing, "known registries into $(pathrepr(depot))")
112+
# Install to the first depot in the list
113+
target_depot = depots1(depots)
114+
printpkgstyle(io, :Installing, "known registries into $(pathrepr(target_depot))")
112115
registries = copy(DEFAULT_REGISTRIES)
113116
for uuid in keys(pkg_server_registry_urls())
114117
if !(uuid in (reg.uuid for reg in registries))
115118
push!(registries, RegistrySpec(uuid = uuid))
116119
end
117120
end
118121
filter!(reg -> !(reg.uuid in installed_registries), registries)
119-
download_registries(io, registries, depot)
122+
download_registries(io, registries, depots)
120123
return true
121124
end
122125
return false
@@ -168,9 +171,11 @@ function check_registry_state(reg)
168171
return nothing
169172
end
170173

171-
function download_registries(io::IO, regs::Vector{RegistrySpec}, depot::String=depots1())
174+
function download_registries(io::IO, regs::Vector{RegistrySpec}, depots::Union{String, Vector{String}}=depots())
175+
# Use the first depot as the target
176+
target_depot = depots1(depots)
172177
populate_known_registries_with_urls!(regs)
173-
regdir = joinpath(depot, "registries")
178+
regdir = joinpath(target_depot, "registries")
174179
isdir(regdir) || mkpath(regdir)
175180
# only allow one julia process to download and install registries at a time
176181
FileWatching.mkpidlock(joinpath(regdir, ".pid"), stale_age = 10) do

test/registry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ end
257257
@test isempty(Registry.reachable_registries(; depots=[depot_off_path]))
258258

259259
# After this, we have depots only in the depot that's off the path
260-
Registry.add("General"; depot=depot_off_path)
260+
Registry.add("General"; depots=depot_off_path)
261261
@test isempty(Registry.reachable_registries())
262262
@test length(Registry.reachable_registries(; depots=[depot_off_path])) == 1
263263

0 commit comments

Comments
 (0)