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:
commit
97f6710d45
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user