diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-08-13 15:57:58 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-08-13 15:57:58 +0000 |
commit | 671e924f2402e18a6b32af8eedf9af5a24b7a01b (patch) | |
tree | 8a4b3e3096ce3c8c4206ccc9bf5ca65b6d176228 /apk-model.lua | |
parent | d962635e52cc8f11764c7cde6a4ab073842ac72c (diff) | |
download | acf-apk-tools-671e924f2402e18a6b32af8eedf9af5a24b7a01b.tar.bz2 acf-apk-tools-671e924f2402e18a6b32af8eedf9af5a24b7a01b.tar.xz |
Added ability to enable cache, changed upgrade to use 'fix -u', added '-U' to upgrade all, bumped to 0.4.0.
Diffstat (limited to 'apk-model.lua')
-rw-r--r-- | apk-model.lua | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/apk-model.lua b/apk-model.lua index 31ef54c..7922e68 100644 --- a/apk-model.lua +++ b/apk-model.lua @@ -2,9 +2,14 @@ module (..., package.seeall) require("apk") require("modelfunctions") +require("posix") +require("fs") +require("format") local configfile = "/etc/apk/repositories" local worldfile = "/var/lib/apk/world" +local cachelink = "/etc/apk/cache" +local lbuconffile = "/etc/lbu/lbu.conf" local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " @@ -189,12 +194,7 @@ install_package = function(package,sessiondata) end upgrade_package = function(package) - -- Jump through hoops to upgrade package without making top level - local retval = run_apk_cmd("add -t temp -u "..package) - run_apk_cmd("del temp") - retval = string.gsub(retval, "Installing temp [^\n]+\n", "") - return cfe({ value=retval, label="Result of Package Upgrade" }) --- return cfe({ value=run_apk_cmd("add -u "..package), label="Result of Package Upgrade" }) + return cfe({ value=run_apk_cmd("fix -u "..package), label="Result of Package Upgrade" }) end update_all = function() @@ -202,7 +202,58 @@ update_all = function() end upgrade_all = function() - return cfe({ value=run_apk_cmd("upgrade"), label="Result of Upgrade" }) + return cfe({ value=run_apk_cmd("upgrade -U"), label="Result of Upgrade" }) +end + +get_cache = function() + local cache = {} + cache.enable = cfe({ type="boolean", value=false, label="Enable Cache" }) + cache.directory = cfe({ label="Cache Directory" }) + local link = posix.stat(cachelink, "type") + if link == "link" then + cache.enable.value = true + cache.directory.value = posix.readlink(cachelink) + else + if link then + cache.enable.errtxt = cachelink.." exists but is not a link" + end + local lbu_media = format.parse_ini_file(fs.read_file(lbuconffile), "", "LBU_MEDIA") + if lbu_media then + cache.directory.value = "/media/"..lbu_media.."/cache" + end + end + return cfe({ type="group", value=cache, label="Cache Settings" }) +end + +update_cache = function(cache) + cache.value.enable.errtxt = nil + if not cache.value.enable.value then + os.remove(cachelink) + else + local success = false + cache.errtxt = "Failed to set cache" + if cache.value.directory.value == "" then + cache.value.directory.errtxt = "Directory must be defined" + else + local dir = posix.stat(cache.value.directory.value, "type") + if dir and dir ~= "directory" then + cache.value.directory.errtxt = "Path exists but is not a directory" + elseif not dir then + success = fs.create_directory(cache.value.directory.value) + if not success then + cache.value.directory.errtxt = "Failed to create directory" + end + else + success = true + end + end + if success then + os.remove(cachelink) + posix.link(cache.value.directory.value, cachelink, true) + cache.errtxt = nil + end + end + return cache end get_configfile = function() |