Merge pull request #2259 from blocktrron/bugfix-util-file-contains-line-exists

gluon-core: util: check if file exists prior to reading
This commit is contained in:
Martin Weinelt 2021-07-01 03:42:36 +02:00 committed by GitHub
commit 97f6710d45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ local posix_syslog = require 'posix.syslog'
local hash = require 'hash' local hash = require 'hash'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local site = require 'gluon.site' local site = require 'gluon.site'
local unistd = require 'posix.unistd'
local M = {} local M = {}
@ -37,6 +38,10 @@ function M.contains(table, value)
end end
function M.file_contains_line(path, value) function M.file_contains_line(path, value)
if not unistd.access(path) then
return false
end
for line in io.lines(path) do for line in io.lines(path) do
if line == value then if line == value then
return true return true