From 99583cf95ccd2995b7751b886ee7fa49977d1c5c Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 9 Aug 2024 19:47:20 +0200 Subject: [PATCH] `stale_cachefile`: handle if the expected cache file is missing (#55419) Part of fixing https://github.com/JuliaLang/Pkg.jl/issues/3984 (cherry picked from commit 18340a3eb40758f5c21428c9c03b3f2b696f475d) --- base/loading.jl | 8 +++++++- test/precompile.jl | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index 0e4ad3461a2f2..5614c3603e540 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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) diff --git a/test/precompile.jl b/test/precompile.jl index be894e5d26133..65b94e81c31ab 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -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,