From ae42e979c1ed5ee1c32ffc81a9ed6c404b2e6eeb Mon Sep 17 00:00:00 2001 From: Christof Schulze Date: Sat, 23 Apr 2016 22:40:39 +0200 Subject: [PATCH] make code more compact --- .../upgrade/330-gluon-mesh-babel-interfaces | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/package/gluon-mesh-babel/files/lib/gluon/upgrade/330-gluon-mesh-babel-interfaces b/package/gluon-mesh-babel/files/lib/gluon/upgrade/330-gluon-mesh-babel-interfaces index 549b9dca..2dfc188f 100755 --- a/package/gluon-mesh-babel/files/lib/gluon/upgrade/330-gluon-mesh-babel-interfaces +++ b/package/gluon-mesh-babel/files/lib/gluon/upgrade/330-gluon-mesh-babel-interfaces @@ -2,6 +2,7 @@ local uci = require('luci.model.uci').cursor() local site = require 'gluon.site_config' +local interfaces='/lib/gluon/core/dynamic/interfaces' if site.mesh_on_wan then uci:section('babeld', 'interface', 'mesh_wan', @@ -13,27 +14,11 @@ if site.mesh_on_wan then uci:add_to_set('firewall', 'mesh_babel', 'network', 'wan') end - -local interfaces='/lib/gluon/core/dynamic/interfaces' -function interfaces_exists(file) - local f = io.open(file, "rb") - if f then f:close() end - return f ~= nil -end - -function lines_from(file) - if not interfaces_exists(file) then return {} end - lines = {} - for line in io.lines(file) do - lines[#lines + 1] = line - end - return lines -end - -local lines = lines_from(interfaces) -for line,interface in pairs(lines) do - uci:section('babeld', 'interface', line, { ifname = interface }) -end +pcall( function() +for interface in io.lines(interfaces) do + uci:section('babeld', 'interface', interface, { ifname = interface }) +end +end) uci:add_to_set('firewall', 'mesh_babel', 'network', 'client') uci:add_to_set('firewall', 'mesh_babel', 'network', 'local_node4')