always close open file handles

Fixes #1619
This commit is contained in:
Benjamin Staneck 2018-01-16 21:58:28 +01:00
parent 5e703796c9
commit a71c6a50ad

60
vendor/clink.lua vendored
View File

@ -14,9 +14,9 @@ dofile(clink_lua_file)
-- now add our own things... -- now add our own things...
--- ---
-- Setting the prompt in clink means that commands which rewrite the prompt do -- Setting the prompt in clink means that commands which rewrite the prompt do
-- not destroy our own prompt. It also means that started cmds (or batch files -- not destroy our own prompt. It also means that started cmds (or batch files
-- which echo) don't get the ugly '{lamb}' shown. -- which echo) don't get the ugly '{lamb}' shown.
--- ---
local function set_prompt_filter() local function set_prompt_filter()
-- get_cwd() is differently encoded than the clink.prompt.value, so everything other than -- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
@ -51,12 +51,12 @@ local function set_prompt_filter()
end end
--- ---
-- Resolves closest directory location for specified directory. -- Resolves closest directory location for specified directory.
-- Navigates subsequently up one level and tries to find specified directory -- Navigates subsequently up one level and tries to find specified directory
-- @param {string} path Path to directory will be checked. If not provided -- @param {string} path Path to directory will be checked. If not provided
-- current directory will be used -- current directory will be used
-- @param {string} dirname Directory name to search for -- @param {string} dirname Directory name to search for
-- @return {string} Path to specified directory or nil if such dir not found -- @return {string} Path to specified directory or nil if such dir not found
local function get_dir_contains(path, dirname) local function get_dir_contains(path, dirname)
-- return parent path for specified entry (either file or directory) -- return parent path for specified entry (either file or directory)
@ -152,8 +152,8 @@ local function get_svn_dir(path)
end end
--- ---
-- Find out current branch -- Find out current branch
-- @return {nil|git branch name} -- @return {nil|git branch name}
--- ---
local function get_git_branch(git_dir) local function get_git_branch(git_dir)
git_dir = git_dir or get_git_dir() git_dir = git_dir or get_git_dir()
@ -174,8 +174,8 @@ local function get_git_branch(git_dir)
end end
--- ---
-- Find out current branch -- Find out current branch
-- @return {false|mercurial branch name} -- @return {false|mercurial branch name}
--- ---
local function get_hg_branch() local function get_hg_branch()
for line in io.popen("hg branch 2>nul"):lines() do for line in io.popen("hg branch 2>nul"):lines() do
@ -189,8 +189,8 @@ local function get_hg_branch()
end end
--- ---
-- Find out current branch -- Find out current branch
-- @return {false|svn branch name} -- @return {false|svn branch name}
--- ---
local function get_svn_branch(svn_dir) local function get_svn_branch(svn_dir)
for line in io.popen("svn info 2>nul"):lines() do for line in io.popen("svn info 2>nul"):lines() do
@ -204,38 +204,46 @@ local function get_svn_branch(svn_dir)
end end
--- ---
-- Get the status of working dir -- Get the status of working dir
-- @return {bool} -- @return {bool}
--- ---
local function get_git_status() local function get_git_status()
local file = io.popen("git --no-optional-locks status --porcelain 2>nul") local file = io.popen("git --no-optional-locks status --porcelain 2>nul")
for line in file:lines() do for line in file:lines() do
file:close()
return false return false
end end
file:close()
return true return true
end end
--- ---
-- Get the status of working dir -- Get the status of working dir
-- @return {bool} -- @return {bool}
--- ---
local function get_hg_status() local function get_hg_status()
for line in io.popen("hg status -0"):lines() do local file = io.popen("hg status -0")
return false for line in file:lines() do
file:close()
return false
end end
file:close()
return true return true
end end
--- ---
-- Get the status of working dir -- Get the status of working dir
-- @return {bool} -- @return {bool}
--- ---
local function get_svn_status() function get_svn_status()
for line in io.popen("svn status -q"):lines() do local file = io.popen("svn status -q")
return false for line in file:lines() do
file:close()
return false
end end
file:close()
return true return true
end end