From 3b8d7744b5fe13eb1eed1558f83462f8e61cd092 Mon Sep 17 00:00:00 2001 From: Dany LE Date: Mon, 6 Apr 2026 19:00:51 +0200 Subject: [PATCH] refactor: improve code --- modules/ulib.c | 4 +++- silkmvc/core/hook.lua | 6 +++--- silkmvc/core/utils.lua | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/ulib.c b/modules/ulib.c index 48931da..4226c00 100644 --- a/modules/ulib.c +++ b/modules/ulib.c @@ -751,8 +751,10 @@ static int _add_to_zip(struct zip_t *zip, const char *path, const char *root) // add it to zip if (zip_entry_open(zip, root) == -1) return -1; - if (zip_entry_fwrite(zip, path) == -1) + if (zip_entry_fwrite(zip, path) == -1) { + zip_entry_close(zip); return -1; + } zip_entry_close(zip); } return 0; diff --git a/silkmvc/core/hook.lua b/silkmvc/core/hook.lua index 69bc859..13c9152 100644 --- a/silkmvc/core/hook.lua +++ b/silkmvc/core/hook.lua @@ -20,15 +20,15 @@ require("silk.core.std") -- global helper functions for lua page script function has_module(m) - if utils.file_exists(__ROOT__ .. '/' .. m) then + if ulib.exists(__ROOT__ .. '/' .. m) then if m:find("%.ls$") then return true, true, __ROOT__ .. '/' .. m else return true, false, m:gsub(".lua$", "") end - elseif utils.file_exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.lua') then + elseif ulib.exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.lua') then 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' end return false, false, nil diff --git a/silkmvc/core/utils.lua b/silkmvc/core/utils.lua index b59d10b..ededfb9 100644 --- a/silkmvc/core/utils.lua +++ b/silkmvc/core/utils.lua @@ -86,10 +86,11 @@ function utils.unescape(s) return str end -function utils.file_exists(name) +function ulib.exists(name) local f = io.open(name, "r") - if f ~= nil then - io.close(f) + if f then + f:close() + --io.close(f) return true else return false