X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=modules%2Fluci-base%2Fluasrc%2Futil.lua;h=a30e8b72f31466d28bec20792c6648c9b6989cb2;hb=09b2d8a8ac6ca14cfa91168e3f3d1a102e6b62fb;hp=10428b0b35f707d26b42ca492fa94bf94713991b;hpb=1fd3a1663528cc5029ee9d864128964f020a520d;p=oweals%2Fluci.git diff --git a/modules/luci-base/luasrc/util.lua b/modules/luci-base/luasrc/util.lua index 10428b0b3..a30e8b72f 100644 --- a/modules/luci-base/luasrc/util.lua +++ b/modules/luci-base/luasrc/util.lua @@ -16,7 +16,7 @@ local _ubus = require "ubus" local _ubus_connection = nil local getmetatable, setmetatable = getmetatable, setmetatable -local rawget, rawset, unpack = rawget, rawset, unpack +local rawget, rawset, unpack, select = rawget, rawset, unpack, select local tostring, type, assert, error = tostring, type, assert, error local ipairs, pairs, next, loadstring = ipairs, pairs, next, loadstring local require, pcall, xpcall = require, pcall, xpcall @@ -207,9 +207,8 @@ end -- handling. It may actually be a property of the getopt function -- rather than the shell proper. function shellstartsqescape(value) - res, _ = string.gsub(value, "^\-", "\\-") - res, _ = string.gsub(res, "^-", "\-") - return shellsqescape(value) + res, _ = string.gsub(value, "^%-", "\\-") + return shellsqescape(res) end -- containing the resulting substrings. The optional max parameter specifies @@ -262,7 +261,7 @@ end -- one token per invocation, the tokens are separated by whitespace. If the -- input value is a table, it is transformed into a string first. A nil value --- will result in a valid interator which aborts with the first invocation. +-- will result in a valid iterator which aborts with the first invocation. function imatch(v) if type(v) == "table" then local k = nil @@ -647,6 +646,17 @@ local ubus_codes = { "CONNECTION_FAILED" } +local function ubus_return(...) + if select('#', ...) == 2 then + local rv, err = select(1, ...), select(2, ...) + if rv == nil and type(err) == "number" then + return nil, err, ubus_codes[err] + end + end + + return ... +end + function ubus(object, method, data) if not _ubus_connection then _ubus_connection = _ubus.connect() @@ -657,8 +667,7 @@ function ubus(object, method, data) if type(data) ~= "table" then data = { } end - local rv, err = _ubus_connection:call(object, method, data) - return rv, err, ubus_codes[err] + return ubus_return(_ubus_connection:call(object, method, data)) elseif object then return _ubus_connection:signatures(object) else