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 c52896d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## Fixed

- Capture permission errors when searching for files on filesystem [PR #865](https://github.com/3scale/apicast/pull/865)

## [3.3.0-beta1] - 2018-08-31

### Added
Expand Down
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 c52896d

Please sign in to comment.