summaryrefslogtreecommitdiffhomepage
path: root/libs/ipkg/luasrc/model
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-03-07 21:51:45 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-03-07 21:51:45 +0000
commit59b3711e704bac69101b1192782f4fa76db3dcdb (patch)
treec55cd1d4dcc65b4365ee8776da64cd1aa6411a6c /libs/ipkg/luasrc/model
parentfe8e9abc0f441e243eedb7160343011b07951235 (diff)
libs/ipkg: add overlay_root(), determines the overlay used by opkg
Diffstat (limited to 'libs/ipkg/luasrc/model')
-rw-r--r--libs/ipkg/luasrc/model/ipkg.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/ipkg/luasrc/model/ipkg.lua b/libs/ipkg/luasrc/model/ipkg.lua
index 12e5a94d0f..cda23af56d 100644
--- a/libs/ipkg/luasrc/model/ipkg.lua
+++ b/libs/ipkg/luasrc/model/ipkg.lua
@@ -15,6 +15,7 @@ $Id$
local os = require "os"
local io = require "io"
+local fs = require "nixio.fs"
local util = require "luci.util"
local type = type
@@ -23,6 +24,7 @@ local error = error
local table = table
local ipkg = "opkg --force-removal-of-dependent-packages --force-overwrite"
+local icfg = "/etc/opkg.conf"
--- LuCI IPKG/OPKG call abstraction library
module "luci.model.ipkg"
@@ -192,3 +194,33 @@ end
function list_installed(pat, cb)
_list("list_installed", pat, cb)
end
+
+--- Determines the overlay root used by opkg.
+-- @return String containing the directory path of the overlay root.
+function overlay_root()
+ local od = "/"
+ local fd = io.open(icfg, "r")
+
+ if fd then
+ local ln
+
+ repeat
+ ln = fd:read("*l")
+ if ln and ln:match("^%s*option%s+overlay_root%s+") then
+ od = ln:match("^%s*option%s+overlay_root%s+(%S+)")
+
+ local s = fs.stat(od)
+ if not s or s.type ~= "dir" then
+ od = "/"
+ end
+
+ break
+ end
+ until not ln
+
+ fd:close()
+ end
+
+ return od
+end
+