From 5cba4b83f60966045b86ac615df2692c953ebba7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 26 Feb 2024 17:47:28 -0300 Subject: fix(fs): make current_dir always return 1 arg only --- src/luarocks/fs/tools.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua index a7724dc7..23f2561e 100644 --- a/src/luarocks/fs/tools.lua +++ b/src/luarocks/fs/tools.lua @@ -48,12 +48,11 @@ do end end +local current_dir_with_cache do local cache_pwd - --- Obtain current directory. - -- Uses the module's internal directory stack. - -- @return string: the absolute pathname of the current directory. - function tools.current_dir() + + current_dir_with_cache = function() local current = cache_pwd if not current then local pipe = io.popen(fs.quiet_stderr(vars.PWD)) @@ -66,6 +65,13 @@ do end return current, cache_pwd end + + --- Obtain current directory. + -- Uses the module's internal directory stack. + -- @return string: the absolute pathname of the current directory. + function tools.current_dir() + return (current_dir_with_cache()) -- drop second return + end end --- Change the current directory. @@ -107,7 +113,7 @@ end -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function tools.execute_string(cmd) - local current, cache_pwd = fs.current_dir() + local current, cache_pwd = current_dir_with_cache() if not current then return false end if current ~= cache_pwd then cmd = fs.command_at(current, cmd) -- cgit v1.2.3-55-g6feb