Skip to content

Commit 532992f

Browse files
authored
Merge pull request #39 from JuliaLang/kc/init
remove using `__init__` by either using `OncePerProcess` or recomputing
1 parent 3169a7c commit 532992f

File tree

7 files changed

+21
-83
lines changed

7 files changed

+21
-83
lines changed

.ci/test_and_change_uuid.jl

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
version:
26-
- '1.3'
27-
- '1' # automatically expands to the latest stable 1.x release of Julia.
2826
- 'nightly'
2927
os:
3028
- ubuntu-latest
@@ -44,7 +42,6 @@ jobs:
4442
version: ${{ matrix.version }}
4543
arch: ${{ matrix.arch }}
4644
- uses: julia-actions/cache@v2
47-
- run: julia --color=yes .ci/test_and_change_uuid.jl
4845
- uses: julia-actions/julia-buildpkg@v1
4946
- uses: julia-actions/julia-runtest@v1
5047
- uses: julia-actions/julia-processcoverage@v1

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["Stefan Karpinski <[email protected]> and contributors"]
44
version = "1.3.0"
55

66
[compat]
7-
julia = "1"
7+
julia = "1.12"
88

99
[extras]
1010
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

src/NetworkOptions.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,4 @@ include("ca_roots.jl")
44
include("ssh_options.jl")
55
include("verify_host.jl")
66

7-
function __init__()
8-
SYSTEM_CA_ROOTS[] = nothing
9-
BUNDLED_KNOWN_HOSTS_FILE[] = nothing
10-
empty!(ENV_HOST_PATTERN_CACHE)
11-
end
12-
137
end # module

src/ca_roots.jl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,22 @@ const BSD_CA_ROOTS = [
7373
"/usr/local/etc/ssl/cert.pem" # FreeBSD
7474
]
7575

76-
const SYSTEM_CA_ROOTS_LOCK = ReentrantLock()
77-
const SYSTEM_CA_ROOTS = Ref{Union{Nothing, String}}(nothing)
78-
7976
const BEGIN_CERT_REGULAR = "-----BEGIN CERTIFICATE-----"
8077
const BEGIN_CERT_OPENSSL = "-----BEGIN TRUSTED CERTIFICATE-----"
8178

82-
function system_ca_roots()
83-
lock(SYSTEM_CA_ROOTS_LOCK) do
84-
SYSTEM_CA_ROOTS[] !== nothing && return # from lock()
85-
search_path = Sys.islinux() ? LINUX_CA_ROOTS :
86-
Sys.isbsd() && !Sys.isapple() ? BSD_CA_ROOTS : String[]
87-
for path in search_path
88-
ispath(path) || continue
89-
for line in eachline(path)
90-
if line in [BEGIN_CERT_REGULAR, BEGIN_CERT_OPENSSL]
91-
SYSTEM_CA_ROOTS[] = path
92-
return # from lock()
93-
end
79+
const system_ca_roots = OncePerProcess{String}() do
80+
search_path = Sys.islinux() ? LINUX_CA_ROOTS :
81+
Sys.isbsd() && !Sys.isapple() ? BSD_CA_ROOTS : String[]
82+
for path in search_path
83+
ispath(path) || continue
84+
for line in eachline(path)
85+
if line in [BEGIN_CERT_REGULAR, BEGIN_CERT_OPENSSL]
86+
return path
9487
end
9588
end
96-
# TODO: extract system certs on Windows & macOS
97-
SYSTEM_CA_ROOTS[] = bundled_ca_roots()
9889
end
99-
return SYSTEM_CA_ROOTS[]
90+
# TODO: extract system certs on Windows & macOS
91+
return bundled_ca_roots()
10092
end
10193

10294
const CA_ROOTS_VARS = [

src/ssh_options.jl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,11 @@ end
144144

145145
## helper functions
146146

147-
const BUNDLED_KNOWN_HOSTS_LOCK = ReentrantLock()
148-
const BUNDLED_KNOWN_HOSTS_FILE = Ref{Union{Nothing, String}}(nothing)
149-
150-
function bundled_known_hosts()
151-
lock(BUNDLED_KNOWN_HOSTS_LOCK) do
152-
file = BUNDLED_KNOWN_HOSTS_FILE[]
153-
if file === nothing
154-
file, io = mktemp()
155-
BUNDLED_KNOWN_HOSTS_FILE[] = file
156-
write(io, BUNDLED_KNOWN_HOSTS)
157-
close(io)
158-
end
159-
return file::String
160-
end
147+
const bundled_known_hosts = OncePerProcess{String}() do
148+
file, io = mktemp()
149+
write(io, BUNDLED_KNOWN_HOSTS)
150+
close(io)
151+
return file
161152
end
162153

163154
const BUNDLED_KNOWN_HOSTS = """

src/verify_host.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,14 @@ env_host_pattern_match(var::AbstractString, host::AbstractString) =
8686
env_host_pattern_match(var::AbstractString, host::Nothing) =
8787
env_host_pattern_regex(var) === MATCH_ANY_RE
8888

89-
const ENV_HOST_PATTERN_LOCK = ReentrantLock()
90-
const ENV_HOST_PATTERN_CACHE = Dict{String,Tuple{String,Regex}}()
9189

9290
function env_host_pattern_regex(var::AbstractString)
93-
lock(ENV_HOST_PATTERN_LOCK) do
94-
value = get(ENV, var, nothing)
95-
if value === nothing
96-
delete!(ENV_HOST_PATTERN_CACHE, var)
97-
return MATCH_NONE_RE
98-
end
99-
old_value, regex = get(ENV_HOST_PATTERN_CACHE, var, (nothing, nothing))
100-
old_value == value && return regex
101-
regex = host_pattern_regex(value, var)
102-
ENV_HOST_PATTERN_CACHE[var] = (value, regex)
103-
return regex
91+
value = get(ENV, var, nothing)
92+
if value === nothing
93+
return MATCH_NONE_RE
10494
end
95+
regex = host_pattern_regex(value, var)
96+
return regex
10597
end
10698

10799
if !@isdefined(contains)

0 commit comments

Comments
 (0)