fix: return nil when `fs_stat` fails and return nil in module loader

This commit is contained in:
Folke Lemaitre 2022-12-02 19:16:21 +01:00
parent 756b4849d9
commit afcba52b1a
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 6 additions and 2 deletions

View File

@ -65,7 +65,10 @@ function M.loader(modname)
if entry then
M.check_load(modname, entry.modpath)
entry.used = os.time()
local hash = assert(M.hash(entry.modpath))
local hash = M.hash(entry.modpath)
if not hash then
return
end
if M.eq(entry.hash, hash) then
-- found in cache and up to date
chunk, err = load(entry.chunk --[[@as string]], "@" .. entry.modpath)
@ -155,7 +158,8 @@ end
---@return CacheHash?
function M.hash(file)
return uv.fs_stat(file)
local ok, ret = pcall(uv.fs_stat, file)
return ok and ret or nil
end
---@param h1 CacheHash