Skip to content

Commit f8b13a7

Browse files
IanButterworthlazarusA
authored andcommitted
stale_cachefile: handle if the expected cache file is missing (JuliaLang#55419)
Part of fixing JuliaLang/Pkg.jl#3984
1 parent 7c4b40c commit f8b13a7

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

base/loading.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3666,7 +3666,13 @@ end
36663666
ignore_loaded::Bool=false, requested_flags::CacheFlags=CacheFlags(),
36673667
reasons::Union{Dict{String,Int},Nothing}=nothing, stalecheck::Bool=true)
36683668
# n.b.: this function does nearly all of the file validation, not just those checks related to stale, so the name is potentially unclear
3669-
io = open(cachefile, "r")
3669+
io = try
3670+
open(cachefile, "r")
3671+
catch ex
3672+
ex isa IOError || ex isa SystemError || rethrow()
3673+
@debug "Rejecting cache file $cachefile for $modkey because it could not be opened" isfile(cachefile)
3674+
return true
3675+
end
36703676
try
36713677
checksum = isvalid_cache_header(io)
36723678
if iszero(checksum)

test/precompile.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ precompile_test_harness(false) do dir
597597
@test Base.invokelatest(Baz.baz) === 1
598598
@test Baz === UseBaz.Baz
599599

600+
# should not throw if the cachefile does not exist
601+
@test !isfile("DoesNotExist.ji")
602+
@test Base.stale_cachefile("", "DoesNotExist.ji") === true
603+
600604
# Issue #12720
601605
FooBar1_file = joinpath(dir, "FooBar1.jl")
602606
write(FooBar1_file,

0 commit comments

Comments
 (0)