diff --git a/CHANGELOG.md b/CHANGELOG.md index 268f23a07..758088b30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Dev environment: Camel proxy [PR #1441](https://github.com/3scale/APIcast/pull/1441) +- Bump penlight to 1.31.1 [PR #1447](https://github.com/3scale/APIcast/pull/1447) + ## [3.14.0] 2023-07-25 ### Fixed diff --git a/Dockerfile b/Dockerfile index 6477ee198..f54d8dbcc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,7 @@ RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/man RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/lua-resty-env-0.4.0-1.src.rock RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/liquid-0.2.0-2.src.rock RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/tieske/date-2.2-2.src.rock -RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/tieske/penlight-1.7.0-1.src.rock +RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/tieske/penlight-1.13.1-1.src.rock RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/mpeterv/argparse-0.6.0-1.src.rock RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/lua-resty-execvp-0.1.1-1.src.rock RUN luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/luafilesystem-ffi-0.2.0-1.src.rock diff --git a/gateway/src/apicast/cli/command/generate.lua b/gateway/src/apicast/cli/command/generate.lua index 56ee2db5f..631b7ea8a 100644 --- a/gateway/src/apicast/cli/command/generate.lua +++ b/gateway/src/apicast/cli/command/generate.lua @@ -1,6 +1,5 @@ local setmetatable = setmetatable -local filesystem = require('apicast.cli.filesystem') local pl = require'pl.import_into'() local Template = require('apicast.cli.template') @@ -30,7 +29,7 @@ function _M.copy(source, destination, env, force) local template = Template:new(env, source, true) - for filename in filesystem(source) do + for filename in pl.dir.dirtree(source) do local path = template:interpret(pl.path.relpath(filename, source)) local fullpath = pl.path.join(destination, path) diff --git a/gateway/src/apicast/cli/filesystem.lua b/gateway/src/apicast/cli/filesystem.lua deleted file mode 100644 index 4b6c7eceb..000000000 --- a/gateway/src/apicast/cli/filesystem.lua +++ /dev/null @@ -1,75 +0,0 @@ ---- Filesystem for CLI --- This module exposes functions that work with filesystem. --- So far exposes only function - to recursively traverse a filesystem path. --- Workaround for https://github.com/stevedonovan/Penlight/issues/265 --- - ---- These lines to avoid _G write guard issues, external depencies --- See https://github.com/openresty/lua-nginx-module/issues/1558 for more info -rawset(_G, 'lfs', false) -rawset(_G, 'warn', false) - -local pl_path = require('pl.path') -local exists, isdir = pl_path.exists, pl_path.isdir -local pl_path_dir = pl_path.dir -local pl_path_join = pl_path.join -local abspath = pl_path.abspath -local pcall = pcall -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 - ngx.log(ngx.DEBUG, 'error listing directory: ', dir, ' err: ', iter) - return noop - end -end - ---- Create coroutine iterator --- Like coroutine.wrap but safe to be used as iterator, --- because it will return nil as first return value on error. -local function co_wrap_iter(f) - local co = co_create(f) - - return function(...) - local ok, ret = co_resume(co, ...) - - if ok then - return ret - else - return nil, ret - end - end -end - ---- Recursively list directory --- This is a copy of penlight's dir.dirtree -return function ( d ) - if not d then return nil end - - local function yieldtree( dir ) - for entry in ldir( dir ) do - if entry ~= '.' and entry ~= '..' then - entry = pl_path_join(dir, entry) - - if exists(entry) then -- Just in case a symlink is broken. - local is_dir = isdir(entry) - co_yield( entry, is_dir ) - if is_dir then - yieldtree( entry ) - end - end - end - end - end - - return co_wrap_iter(function() yieldtree( abspath(d) ) end) -end diff --git a/gateway/src/apicast/cli/template.lua b/gateway/src/apicast/cli/template.lua index 122359602..944ff7a63 100644 --- a/gateway/src/apicast/cli/template.lua +++ b/gateway/src/apicast/cli/template.lua @@ -8,7 +8,6 @@ local ipairs = ipairs local sub = string.sub local len = string.len local pack = table.pack -local fs = require('apicast.cli.filesystem') local pl = { dir = require('pl.dir'), path = require('pl.path'), file = require('pl.file') } local Liquid = require 'liquid' local resty_env = require('resty.env') @@ -84,7 +83,7 @@ local function dirtree(dir, cache) return pairs(cached) else cache[dir] = {} - return fs(dir) + return pl.dir.dirtree(dir) end end