From fd1f8a8284ea620687053f58043e80c3ee54ecfb Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Mon, 3 Sep 2018 16:29:23 +0200 Subject: [PATCH] [cli] do not crash when listing unaccessible directories When the directory is not accessible, instead of crash like: ``` lua coroutine: runtime error: /opt/app-root/src/src/apicast/cli/filesystem.lua:50: attempt to call a nil value ``` Get a debug log like: ``` /usr/local/share/lua/5.1/lfs.lua:513: cannot open /usr/local/openresty/nginx/fastcgi_temp : Permission denied ``` --- gateway/src/apicast/cli/filesystem.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gateway/src/apicast/cli/filesystem.lua b/gateway/src/apicast/cli/filesystem.lua index e079fab7f..1dc81f244 100644 --- a/gateway/src/apicast/cli/filesystem.lua +++ b/gateway/src/apicast/cli/filesystem.lua @@ -13,6 +13,8 @@ local co_yield = coroutine.yield local co_create = coroutine.create local co_resume = coroutine.resume +local noop = function () end + --- Safely try to get directory iterator local function ldir(dir) local ok, iter, state = pcall(pl_path_dir, dir) @@ -20,7 +22,8 @@ local function ldir(dir) if ok then return iter, state else - return nil, iter + ngx.log(ngx.DEBUG, 'error listing directory: ', dir, ' err: ', iter) + return noop end end