UGLY workaround is UGLY
[project/luci.git] / libs / uci / luasrc / model / uci.lua
index de885808ac507d051c5088087404ee7710a667e4..e26f9030adb0dac848a494e3dbfc508a79dc5a8a 100644 (file)
@@ -1,5 +1,5 @@
 --[[
-LuCI - UCI mpdel
+LuCI - UCI model
 
 Description:
 Generalized UCI model
@@ -23,34 +23,43 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 ]]--
-local uci   = require "uci2"
+local os    = require "os"
+local uci   = require "uci"
 local util  = require "luci.util"
 local table = require "table"
 
+
 local setmetatable, rawget, rawset = setmetatable, rawget, rawset
 local error, pairs, ipairs, tostring = error, pairs, ipairs, tostring
 local require, getmetatable = require, getmetatable
 
 --- LuCI UCI model library.
-module("luci.model.uci")
+-- @cstyle     instance
+module "luci.model.uci"
 
+--- Create a new UCI-Cursor.
+-- @class function
+-- @name cursor
+-- @return     UCI-Cursor
 cursor = uci.cursor
+
 APIVERSION = uci.APIVERSION
 
---- Creates a new statevalue cursor
+--- Create a new Cursor initialized to the state directory.
 -- @return UCI cursor
 function cursor_state()
        return cursor(nil, "/var/state")
 end
 
---- UCI-Cursor
+
 local Cursor = getmetatable(cursor())
 
 --- Applies the new config
 -- @param config               UCI config
 function Cursor.apply(self, config)
        local conf = require "luci.config"
-       return conf.uci_oncommit[config] and os.execute(conf.uci_oncommit[config])
+       return conf.uci_oncommit[config] and
+        os.execute(conf.uci_oncommit[config] .. " >/dev/null 2>&1")
 end
 
 --- Delete all sections of a given type that match certain criteria.
@@ -139,6 +148,22 @@ function Cursor.set_list(self, config, section, option, value)
 end
 
 
+Cursor._changes = Cursor.changes
+function Cursor.changes(self, config)
+       if config then
+               return Cursor._changes(self, config)
+       else
+               local changes = {}
+               for k,v in pairs(require "luci.fs".dir(self:get_savedir())) do
+                       if v ~= "." and v ~= ".." then
+                               util.update(changes, Cursor._changes(self, v))
+                       end
+               end
+               return changes
+       end
+end
+
+
 --- Add an anonymous section.
 -- @class function
 -- @name Cursor.add
@@ -157,7 +182,7 @@ end
 -- @name Cursor.commit
 -- @param config       UCI config
 -- @return                     Boolean whether operation succeeded
--- @see revert
+-- @see Cursor.revert
 
 --- Deletes a section or an option.
 -- @class function
@@ -191,30 +216,27 @@ end
 -- @return                     Table of UCI sections or table of UCI values
 
 --- Manually load a config.
--- Warning: This function is unsave! You should use load_config or load_state if possible.
 -- @class function
 -- @name Cursor.load
 -- @param config       UCI config
 -- @return                     Boolean whether operation succeeded
--- @see load_config
--- @see load_state
--- @see save
--- @see unload
+-- @see Cursor.save
+-- @see Cursor.unload
 
 --- Revert unsaved changes.
 -- @class function
 -- @name Cursor.revert
 -- @param config       UCI config
 -- @return                     Boolean whether operation succeeded
--- @see commit
+-- @see Cursor.commit
 
 --- Saves changes made to a config to make them committable.
 -- @class function
 -- @name Cursor.save
 -- @param config       UCI config
 -- @return                     Boolean whether operation succeeded
--- @see load
--- @see unload
+-- @see Cursor.load
+-- @see Cursor.unload
 
 --- Set a value or create a named section.
 -- @class function
@@ -252,5 +274,5 @@ end
 -- @name Cursor.unload
 -- @param config       UCI config
 -- @return                     Boolean whether operation succeeded
--- @see load
--- @see save
+-- @see Cursor.load
+-- @see Cursor.save