diff mbox series

Lua: Add sublevel to SWUpdate version result table

Message ID B551F07A-64D0-48E4-9129-F3D03AB4FD28@siemens.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series Lua: Add sublevel to SWUpdate version result table | expand

Commit Message

Storm, Christian May 12, 2025, 2:07 p.m. UTC
Add the missing sublevel field (VERSION_SUBLEVEL) to
the table returned by lua_get_swupdate_version().

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/lua_interface.c  | 5 +++++
 suricatta/server_wfx.lua | 9 ++++++++-
 suricatta/suricatta.lua  | 2 ++
 3 files changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index ec1eadab..d6d3fe9b 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -1044,6 +1044,7 @@  int lua_get_swupdate_version(lua_State *L)
 {
 	const unsigned int version = VERSION;
 	const unsigned int patchlevel = VERSION_PATCHLEVEL;
+	const unsigned int sublevel = VERSION_SUBLEVEL;
 
 	lua_newtable (L);
 	lua_pushnumber(L, 1);
@@ -1052,8 +1053,12 @@  int lua_get_swupdate_version(lua_State *L)
 	lua_pushnumber(L, 2);
 	lua_pushnumber(L, patchlevel);
 	lua_settable(L, -3);
+	lua_pushnumber(L, 3);
+	lua_pushnumber(L, sublevel);
+	lua_settable(L, -3);
 	lua_push_enum(L, "version", version);
 	lua_push_enum(L, "patchlevel", patchlevel);
+	lua_push_enum(L, "sublevel", sublevel);
 	return 1;
 }
 
diff --git a/suricatta/server_wfx.lua b/suricatta/server_wfx.lua
index ea9c4036..0978ed50 100644
--- a/suricatta/server_wfx.lua
+++ b/suricatta/server_wfx.lua
@@ -1804,7 +1804,14 @@  M.job.workflow.dispatch:set(
 --- @field version string            Device client version information, sent to server in HTTP Header
 --- @field reset   function(device)  Reset `device` Table
 M.device = {
-    version = ("SWUpdate %04u.%02u"):format(table.unpack(suricatta.getversion() or { 2025, 5 })),
+    version = (function()
+        local version = suricatta.getversion()
+        local format = "SWUpdate %04u.%02u"
+        if version.sublevel > 0 then
+            format = format .. ".%02u"
+        end
+        return format:format(table.unpack(version))
+    end)(),
     reset = function(self)
         self.id = nil
         self.pstate = nil
diff --git a/suricatta/suricatta.lua b/suricatta/suricatta.lua
index 303e8639..24d6eb8f 100644
--- a/suricatta/suricatta.lua
+++ b/suricatta/suricatta.lua
@@ -320,8 +320,10 @@  suricatta.get_tmpdir = function() end
 --- @class suricatta.version
 --- @field [1]         number  SWUpdate's version
 --- @field [2]         number  SWUpdate's patch level
+--- @field [3]         number  SWUpdate's sub level
 --- @field version     number  SWUpdate's version
 --- @field patchlevel  number  SWUpdate's patch level
+--- @field sublevel    number  SWUpdate's sub level
 
 --- Get SWUpdate version.
 --