platform dependent implementation of check_if_bin_exists and check_if_file_exists
This commit is contained in:
@@ -51,16 +51,17 @@ dtutils_file.libdoc.functions["check_if_bin_exists"] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dtutils_file.check_if_bin_exists(bin)
|
function dtutils_file.check_if_bin_exists(bin)
|
||||||
local cmd
|
local result
|
||||||
if package.config:sub(1,1) == '/' then
|
if (dt.configuration.running_os == 'linux') then
|
||||||
cmd = 'which '
|
result = os.execute("which "..bin)
|
||||||
else
|
else
|
||||||
cmd = 'where '
|
result = dtutils_file.check_if_file_exists(bin)
|
||||||
end
|
end
|
||||||
local result = os.execute(cmd .. bin)
|
|
||||||
if not result then
|
if not result then
|
||||||
result = false
|
result = false
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -200,11 +201,26 @@ dtutils_file.libdoc.functions["check_if_file_exists"] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dtutils_file.check_if_file_exists(filepath)
|
function dtutils_file.check_if_file_exists(filepath)
|
||||||
local file = io.open(filepath, "r")
|
local result
|
||||||
local result = false
|
if (dt.configuration.running_os == 'windows') then
|
||||||
if file then
|
filepath = string.gsub(filepath, '[\\/]+', '\\')
|
||||||
result = true
|
result = os.execute('if exist "'..filepath..'" (cmd /c exit 0) else (cmd /c exit 1)')
|
||||||
file:close()
|
if not result then
|
||||||
|
result = false
|
||||||
|
end
|
||||||
|
elseif (dt.configuration.running_os == "linux") then
|
||||||
|
result = os.execute('test -e ' .. filepath)
|
||||||
|
if not result then
|
||||||
|
result = false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local file = io.open(filepath, "r")
|
||||||
|
if file then
|
||||||
|
result = true
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
result = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user