From 7ed4465b8177dcaa8742f079bc6b4d2745fd68c8 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 22 Aug 2024 23:08:19 -0300 Subject: fs.download: get consistent return values --- src/luarocks/fs/lua.lua | 12 +++++++----- src/luarocks/fs/tools.lua | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 4016ddcd..fdf3af78 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -936,14 +936,16 @@ local downloader_warning = false -- resulting local filename of the remote file as the basename of the URL; -- if that is not correct (due to a redirection, for example), the local -- filename can be given explicitly as this second argument. --- @return (boolean, string, boolean): +-- @return (string, string, string, boolean): -- In case of success: --- * true --- * a string with the filename +-- * name +-- nil +-- nil -- * true if the file was retrieved from local cache -- In case of failure: --- * false +-- nil -- * error message +-- * error code function fs_lua.download(url, filename, cache) assert(type(url) == "string") assert(type(filename) == "string" or not filename) @@ -984,7 +986,7 @@ function fs_lua.download(url, filename, cache) elseif not ok then return nil, err, "network" end - return true, filename, from_cache + return filename, nil, nil, from_cache end else --...if socket_ok == false then diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua index 23f2561e..b7d03759 100644 --- a/src/luarocks/fs/tools.lua +++ b/src/luarocks/fs/tools.lua @@ -148,7 +148,7 @@ end -- filename can be given explicitly as this second argument. -- @param cache boolean: compare remote timestamps via HTTP HEAD prior to -- re-downloading the file. --- @return (boolean, string, string): true and the filename on success, +-- @return (string, string, string): filename on success, -- false and the error message and code on failure. function tools.use_downloader(url, filename, cache) assert(type(url) == "string") @@ -190,10 +190,10 @@ function tools.use_downloader(url, filename, cache) ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." --output "..fs.Q(filename))) end if ok then - return true, filename + return filename else os.remove(filename) - return false, "failed downloading " .. url, "network" + return nil, "failed downloading " .. url, "network" end end -- cgit v1.2.3-55-g6feb