From 26ea986b8322dc3bd1e82cf6d819082c57a69024 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sat, 7 May 2016 13:52:08 +0300 Subject: Add fs.quiet_stderr function --- src/luarocks/fs/unix.lua | 7 +++++++ src/luarocks/fs/unix/tools.lua | 6 +++--- src/luarocks/fs/win32.lua | 7 +++++++ src/luarocks/fs/win32/tools.lua | 6 +++--- 4 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index e2cc825b..520b3e99 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -16,6 +16,13 @@ function unix.quiet(cmd) return cmd.." 1> /dev/null 2> /dev/null" end +--- Annotate command string for execution with quiet stderr. +-- @param cmd string: A command-line string. +-- @return string: The command-line, with stderr silencing annotation. +function unix.quiet_stderr(cmd) + return cmd.." 2> /dev/null" +end + --- Return an absolute pathname from a potentially relative one. -- @param pathname string: pathname to convert. -- @param relative_to string or nil: path to prepend when making diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index ab55897e..d75d9795 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -21,7 +21,7 @@ end function tools.current_dir() local current = cfg.cache_pwd if not current then - local pipe = io.popen(fs.Q(vars.PWD).." 2> /dev/null") + local pipe = io.popen(fs.quiet_stderr(fs.Q(vars.PWD))) current = pipe:read("*l") pipe:close() cfg.cache_pwd = current @@ -183,7 +183,7 @@ function tools.find(at) return {} end local result = {} - local pipe = io.popen(command_at(at, vars.FIND.." * 2>/dev/null")) + local pipe = io.popen(command_at(at, fs.quiet_stderr(vars.FIND.." *"))) for file in pipe:lines() do table.insert(result, file) end @@ -268,7 +268,7 @@ function tools.use_downloader(url, filename, cache) if cfg.connection_timeout and cfg.connection_timeout > 0 then curl_cmd = curl_cmd .. "--connect-timeout "..tonumber(cfg.connection_timeout).." " end - ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) + ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." > "..fs.Q(filename))) end if ok then return true, filename diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index c14c421b..74f3ed69 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -27,6 +27,13 @@ function win32.quiet(cmd) return cmd.." 2> NUL 1> NUL" end +--- Annotate command string for execution with quiet stderr. +-- @param cmd string: A command-line string. +-- @return string: The command-line, with stderr silencing annotation. +function win32.quiet_stderr(cmd) + return cmd.." 2> NUL" +end + local drive_letter = "[%.a-zA-Z]?:?[\\/]" local win_escape_chars = { diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index b9dce85c..39aa4ba1 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -39,7 +39,7 @@ end function tools.current_dir() local current = cfg.cache_pwd if not current then - local pipe = io.popen(fs.Q(vars.PWD).. " 2> NUL") + local pipe = io.popen(fs.quiet_stderr(fs.Q(vars.PWD))) current = pipe:read("*l") pipe:close() cfg.cache_pwd = current @@ -196,7 +196,7 @@ function tools.find(at) return {} end local result = {} - local pipe = io.popen(command_at(at, fs.Q(vars.FIND).." 2> NUL")) + local pipe = io.popen(command_at(at, fs.quiet_stderr(fs.Q(vars.FIND)))) for file in pipe:lines() do -- Windows find is a bit different local first_two = file:sub(1,2) @@ -278,7 +278,7 @@ function tools.use_downloader(url, filename, cache) if cfg.connection_timeout and cfg.connection_timeout > 0 then curl_cmd = curl_cmd .. "--connect-timeout "..tonumber(cfg.connection_timeout).." " end - ok = fs.execute_string(curl_cmd..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) + ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." > "..fs.Q(filename))) end if ok then return true, filename -- cgit v1.2.3-55-g6feb