refactor: improve code
This commit is contained in:
@@ -751,8 +751,10 @@ static int _add_to_zip(struct zip_t *zip, const char *path, const char *root)
|
|||||||
// add it to zip
|
// add it to zip
|
||||||
if (zip_entry_open(zip, root) == -1)
|
if (zip_entry_open(zip, root) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
if (zip_entry_fwrite(zip, path) == -1)
|
if (zip_entry_fwrite(zip, path) == -1) {
|
||||||
|
zip_entry_close(zip);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
zip_entry_close(zip);
|
zip_entry_close(zip);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ require("silk.core.std")
|
|||||||
|
|
||||||
-- global helper functions for lua page script
|
-- global helper functions for lua page script
|
||||||
function has_module(m)
|
function has_module(m)
|
||||||
if utils.file_exists(__ROOT__ .. '/' .. m) then
|
if ulib.exists(__ROOT__ .. '/' .. m) then
|
||||||
if m:find("%.ls$") then
|
if m:find("%.ls$") then
|
||||||
return true, true, __ROOT__ .. '/' .. m
|
return true, true, __ROOT__ .. '/' .. m
|
||||||
else
|
else
|
||||||
return true, false, m:gsub(".lua$", "")
|
return true, false, m:gsub(".lua$", "")
|
||||||
end
|
end
|
||||||
elseif utils.file_exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.lua') then
|
elseif ulib.exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.lua') then
|
||||||
return true, false, m
|
return true, false, m
|
||||||
elseif utils.file_exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls') then
|
elseif ulib.exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls') then
|
||||||
return true, true, __ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls'
|
return true, true, __ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls'
|
||||||
end
|
end
|
||||||
return false, false, nil
|
return false, false, nil
|
||||||
|
|||||||
@@ -86,10 +86,11 @@ function utils.unescape(s)
|
|||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
function utils.file_exists(name)
|
function ulib.exists(name)
|
||||||
local f = io.open(name, "r")
|
local f = io.open(name, "r")
|
||||||
if f ~= nil then
|
if f then
|
||||||
io.close(f)
|
f:close()
|
||||||
|
--io.close(f)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user