@@ -27,6 +27,65 @@ mutable struct SymbolServerInstance
2727 end
2828end
2929
30+ function get_general_pkgs ()
31+ dp_before = copy (Base. DEPOT_PATH )
32+ try
33+ # because the env var JULIA_DEPOT_PATH is overritten this is probably the best
34+ # guess depot location
35+ push! (empty! (Base. DEPOT_PATH ), joinpath (homedir (), " .julia" ))
36+ @static if VERSION >= v " 1.7-"
37+ regs = Pkg. Types. Context (). registries
38+ i = findfirst (r -> r. name == " General" && r. uuid == UUID (" 23338594-aafe-5451-b93e-139f81909106" ), regs)
39+ i === nothing && return Dict {UUID, PkgEntry} ()
40+ return regs[i]. pkgs
41+ else
42+ for r in Pkg. Types. collect_registries ()
43+ (r. name == " General" && r. uuid == UUID (" 23338594-aafe-5451-b93e-139f81909106" )) || continue
44+ reg = Pkg. Types. read_registry (joinpath (r. path, " Registry.toml" ))
45+ return reg[" packages" ]
46+ end
47+ return Dict {UUID, PkgEntry} ()
48+ end
49+ finally
50+ append! (empty! (Base. DEPOT_PATH ), dp_before)
51+ end
52+ end
53+
54+ """
55+ remove_non_general_pkgs!(pkgs)
56+
57+ Removes packages that aren't going to be on the symbol cache server because they aren't in the General registry.
58+ This avoids leaking private package name & uuid pairs via the url requests to the symbol server.
59+
60+ If the General registry cannot be found packages cannot be checked, so all packages will be removed.
61+ """
62+ function remove_non_general_pkgs! (pkgs)
63+ general_pkgs = get_general_pkgs ()
64+ if isempty (general_pkgs)
65+ @warn """
66+ Could not find the General registry when checking for whether packages are public.
67+ All package symbol caches will be generated locally"""
68+ return empty! (pkgs)
69+ end
70+ filter! (pkgs) do pkg
71+ packageuuid (pkg) === nothing && return false
72+ packagename (pkg) === nothing && return false
73+ tree_hash (pkg) === nothing && return false # stdlibs and dev-ed packages don't have tree_hash and aren't cached
74+ @static if VERSION >= v " 1.7-"
75+ uuid_match = get (general_pkgs, packageuuid (pkg), nothing )
76+ uuid_match === nothing && return false
77+ uuid_match. name != packagename (pkg) && return false
78+ return true
79+ else
80+ uuid_match = get (general_pkgs, string (packageuuid (pkg)), nothing )
81+ uuid_match === nothing && return false
82+ uuid_match[" name" ] != packagename (pkg) && return false
83+ return true
84+ end
85+ end
86+ return pkgs
87+ end
88+
3089function getstore (ssi:: SymbolServerInstance , environment_path:: AbstractString , progress_callback= nothing , error_handler= nothing ; download = false )
3190 ! ispath (environment_path) && return :success , recursive_copy (stdlibs)
3291
@@ -42,20 +101,33 @@ function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, p
42101 if manifest != = nothing
43102 @debug " Downloading cache files for manifest at $(manifest_filename) ."
44103 to_download = collect (validate_disc_store (ssi. store_path, manifest))
45- batches = Iterators. partition (to_download, max (1 , floor (Int, length (to_download)÷ 50 )))
46- for (i, batch) in enumerate (batches)
47- percentage = round (Int, 100 * (i - 1 )/ length (batches))
48- progress_callback != = nothing && progress_callback (" Downloading caches..." , percentage)
49- @sync for pkg in batch
50- @async begin
51- yield ()
52- uuid = packageuuid (pkg)
53- get_file_from_cloud (manifest, uuid, environment_path, ssi. depot_path, ssi. store_path, download_dir, ssi. symbolcache_upstream)
54- yield ()
104+ try
105+ remove_non_general_pkgs! (to_download)
106+ catch err
107+ # if any errors, err on the side of caution and mark all as private, and continue
108+ @error """
109+ Symbol cache downloading: Failed to identify which packages to omit based on the General registry.
110+ All packages will be processsed locally""" err
111+ empty! (to_download)
112+ end
113+ if ! isempty (to_download)
114+ n_done = 0
115+ n_total = length (to_download)
116+ for batch in Iterators. partition (to_download, 100 ) # 100 connections at a time
117+ @sync for pkg in batch
118+ @async begin
119+ yield ()
120+ uuid = packageuuid (pkg)
121+ get_file_from_cloud (manifest, uuid, environment_path, ssi. depot_path, ssi. store_path, download_dir, ssi. symbolcache_upstream)
122+ yield ()
123+ n_done += 1
124+ percentage = round (Int, 100 * (n_done/ n_total))
125+ progress_callback != = nothing && progress_callback (" Downloading caches..." , percentage)
126+ end
55127 end
56128 end
129+ progress_callback != = nothing && progress_callback (" All cache files downloaded." , 100 )
57130 end
58- progress_callback != = nothing && progress_callback (" All cache files downloaded." , 100 )
59131 end
60132 end
61133 end
0 commit comments