Skip to content

Commit

Permalink
[cli] do not crash when listing unaccessible directories
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
mikz committed Sep 3, 2018
1 parent 50b063b commit fd1f8a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gateway/src/apicast/cli/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ 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)

if ok then
return iter, state
else
return nil, iter
ngx.log(ngx.DEBUG, 'error listing directory: ', dir, ' err: ', iter)
return noop
end
end

Expand Down

0 comments on commit fd1f8a8

Please sign in to comment.