From dc0af58cfccdf21192c91ed358cd732bad8181da Mon Sep 17 00:00:00 2001 From: git-hulk Date: Thu, 9 May 2024 14:42:36 +0800 Subject: Fix the open fd might be nil if failing to open in fetch_caching --- src/luarocks/fetch.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 435108ae..193e5e39 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -62,15 +62,20 @@ function fetch.fetch_caching(url, mirroring) end local file, err, errcode, from_cache = fetch.fetch_url(url, cachefile, true, mirroring) + if not file then + fs.unlock_access(lock) + return nil, err or "Failed downloading "..url, errcode + end - local fd = io.open(checkfile, "wb") + local fd, err = io.open(checkfile, "wb") + if err then + fs.unlock_access(lock) + return nil, err + end fd:write("!") fd:close() fs.unlock_access(lock) - if not file then - return nil, err or "Failed downloading "..url, errcode - end return file, nil, nil, from_cache end -- cgit v1.2.3-55-g6feb