luci-app-ddns: get rid of luci-lib-ipkg depdency
authorJo-Philipp Wich <jo@mein.io>
Thu, 20 Oct 2022 08:07:21 +0000 (10:07 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 20 Oct 2022 08:08:36 +0000 (10:08 +0200)
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>
applications/luci-app-ddns/Makefile
applications/luci-app-ddns/root/usr/libexec/rpcd/luci.ddns

index 1b70170308cc4963efc643f9035a8154a8a700e5..a529e22e227bc9c977f2517e4d7042ca7036abf6 100644 (file)
@@ -12,7 +12,7 @@ PKG_LICENSE:=Apache-2.0
 PKG_MAINTAINER:=Ansuel Smith <ansuelsmth@gmail.com>
 
 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
 
 include ../../luci.mk
index 132c186642eabffc8290f954cb7f987cd92bc22e..6db329c18690e4ad1dca4ec7944d0473f4415256 100755 (executable)
@@ -153,21 +153,26 @@ local methods = {
        },
        get_ddns_state = {
                call = function()
-                       local ipkg = require "luci.model.ipkg"
                        local uci = UCI.cursor()
                        local dateformat = uci:get("ddns", "global", "ddns_dateformat") or "%F %R"
                        local services_mtime = fs.stat(ddns_package_path .. "/list", 'mtime')
                        uci:unload("ddns")
-                       local ver, srv_ver_cmd
                        local res = {}
+                       local ver
 
-                       if ipkg then
-                               ver = ipkg.info(srv_name)[srv_name].Version
-                       else
-                               srv_ver_cmd = luci_helper .. " -V | awk {'print $2'} "
-                               ver = util.exec(srv_ver_cmd)
+                       local _, ctrl = pcall(io.lines, "/usr/lib/opkg/info/%s.control" % srv_name)
+                       if ctrl then
+                               for line in ctrl do
+                                       ver = line:match("^Version: (.+)$")
+
+                                       if ver then
+                                               break
+                                       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['_enabled'] = sys.init.enabled("ddns")
                        res['_curr_dateformat'] = os.date(dateformat)