Skip to content

Commit

Permalink
stale_cachefile: handle if the expected cache file is missing (#55419)
Browse files Browse the repository at this point in the history
Part of fixing JuliaLang/Pkg.jl#3984

(cherry picked from commit 18340a3)
  • Loading branch information
IanButterworth authored and KristofferC committed Aug 13, 2024
1 parent d499694 commit 99583cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,13 @@ end
ignore_loaded::Bool=false, requested_flags::CacheFlags=CacheFlags(),
reasons::Union{Dict{String,Int},Nothing}=nothing, stalecheck::Bool=true)
# n.b.: this function does nearly all of the file validation, not just those checks related to stale, so the name is potentially unclear
io = open(cachefile, "r")
io = try
open(cachefile, "r")
catch ex
ex isa IOError || ex isa SystemError || rethrow()
@debug "Rejecting cache file $cachefile for $modkey because it could not be opened" isfile(cachefile)
return true
end
try
checksum = isvalid_cache_header(io)
if iszero(checksum)
Expand Down
4 changes: 4 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ precompile_test_harness(false) do dir
@test Base.invokelatest(Baz.baz) === 1
@test Baz === UseBaz.Baz

# should not throw if the cachefile does not exist
@test !isfile("DoesNotExist.ji")
@test Base.stale_cachefile("", "DoesNotExist.ji") === true

# Issue #12720
FooBar1_file = joinpath(dir, "FooBar1.jl")
write(FooBar1_file,
Expand Down

0 comments on commit 99583cf

Please sign in to comment.