#!/opt/Lua51/bin/lua -- Created by jiaqiang.ye@lnxall.com -- determine existing pkgdir name -- 2025/08/06 package.cpath = "/opt/Lua51/lib/lua/?.so;/opt/Lua51/lib/lua/loadall.so" package.path = "/opt/Lua51/share/lua/?.lua;/opt/Lua51/share/lua/?/init.lua;/opt/Lua51/lib/lua/?.lua;/opt/Lua51/lib/lua/?/init.lua" local invoker = require 'invoker' local g_absdir = nil local g_appname = nil local function goodstr(s) if type(s) ~= "string" then return false end if string.len(s) == 0 then return false end return true end local function pdn_init(arg1, arg2) if not goodstr(arg1) then io.stderr:write("Error, invalid absolute directory argument.\n") io.stderr:flush() return false end if not goodstr(arg2) then io.stderr:write("Error, invalid package name argument.\n") io.stderr:flush() return false end g_absdir, g_appname = arg1, arg2 if not invoker.chdir(arg1) then io.stderr:write(gfmt("Error, chdir(%s) has failed: %s\n", arg1)) io.stderr:flush() return false end return true end local function pdn_find() local pdirs = invoker.glob("*") if type(pdirs) ~= "table" then return false end local anl = string.len(g_appname) local flen = anl + 4 local res, nres = {}, 0 for _, pdir in ipairs(pdirs) do local typ = invoker.statfile(pdir) if typ == "directory" and flen == #pdir then local ftidx = tonumber(pdir:sub(1, 3), 10) if ftidx and ftidx >= 0 then local ndir = string.format("%03d-%s", math.floor(ftidx), g_appname) if pdir == ndir then nres = nres + 1 res[nres] = pdir end end end end if nres == 0 then return false end if nres == 1 then io.stdout:write(res[1] .. "\n") io.stdout:flush() return true end io.stdout:write(table.concat(res, " ")) io.stdout:write("\n") io.stdout:flush() return true end if not pdn_init(arg[1], arg[2]) then os.exit(1) end pdn_find() os.exit(0)