gluon-core: util: check if file exists prior to reading

The file_contains_line helper function was not testing whether a file
exists or not prior attempting to read from it.

Add this check to circumvent errors on the private WiFi config in
case the hwflags file is missing.

Reported-by: Tom Herbers <freifunk@tomherbers.de>
Tested-by: Tom Herbers <freifunk@tomherbers.de>
Signed-off-by: David Bauer <mail@david-bauer.net>
This commit is contained in:
David Bauer 2021-07-01 02:56:14 +02:00
parent 1b620c831b
commit ff9f295f7d
1 changed files with 5 additions and 0 deletions

View File

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