luci-app-ddns: get rid of luci-lib-ipkg depdency

Invoking opkg to obtain the installed package version is very slow and
resource intensive, parse the related control file directly to avoid
the extraneous dependency and resource consumption.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2022-10-20 10:07:21 +02:00
parent 1a47b37f1d
commit 3395656b9f
2 changed files with 13 additions and 8 deletions

View file

@ -12,7 +12,7 @@ PKG_LICENSE:=Apache-2.0
PKG_MAINTAINER:=Ansuel Smith <ansuelsmth@gmail.com> PKG_MAINTAINER:=Ansuel Smith <ansuelsmth@gmail.com>
LUCI_TITLE:=LuCI Support for Dynamic DNS Client (ddns-scripts) LUCI_TITLE:=LuCI Support for Dynamic DNS Client (ddns-scripts)
LUCI_DEPENDS:=+luci-lib-ipkg +luci-mod-admin-full +ddns-scripts LUCI_DEPENDS:=+luci-mod-admin-full +ddns-scripts
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
include ../../luci.mk include ../../luci.mk

View file

@ -153,20 +153,25 @@ local methods = {
}, },
get_ddns_state = { get_ddns_state = {
call = function() call = function()
local ipkg = require "luci.model.ipkg"
local uci = UCI.cursor() local uci = UCI.cursor()
local dateformat = uci:get("ddns", "global", "ddns_dateformat") or "%F %R" local dateformat = uci:get("ddns", "global", "ddns_dateformat") or "%F %R"
local services_mtime = fs.stat(ddns_package_path .. "/list", 'mtime') local services_mtime = fs.stat(ddns_package_path .. "/list", 'mtime')
uci:unload("ddns") uci:unload("ddns")
local ver, srv_ver_cmd
local res = {} local res = {}
local ver
if ipkg then local _, ctrl = pcall(io.lines, "/usr/lib/opkg/info/%s.control" % srv_name)
ver = ipkg.info(srv_name)[srv_name].Version if ctrl then
else for line in ctrl do
srv_ver_cmd = luci_helper .. " -V | awk {'print $2'} " ver = line:match("^Version: (.+)$")
ver = util.exec(srv_ver_cmd)
if ver then
break
end end
end
end
ver = ver or util.trim(util.exec("%s -V | awk {'print $2'}" % luci_helper))
res['_version'] = ver and #ver > 0 and ver or nil res['_version'] = ver and #ver > 0 and ver or nil
res['_enabled'] = sys.init.enabled("ddns") res['_enabled'] = sys.init.enabled("ddns")