summaryrefslogtreecommitdiffstats
path: root/apk-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-06-05 19:45:03 +0000
committerTed Trask <ttrask01@yahoo.com>2008-06-05 19:45:03 +0000
commitdebc2e6ee82d7e10e7e414b8f855bee32e864dae (patch)
treeb53cc6e4853163836da4057a9505b3e682530440 /apk-model.lua
parentb4e8c5956ac0b6c7a8f95d14516caeb1a5b5968c (diff)
downloadacf-apk-tools-debc2e6ee82d7e10e7e414b8f855bee32e864dae.tar.bz2
acf-apk-tools-debc2e6ee82d7e10e7e414b8f855bee32e864dae.tar.xz
Validate package name before delete/install
git-svn-id: svn://svn.alpinelinux.org/acf/apk-tools/trunk@1204 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'apk-model.lua')
-rw-r--r--apk-model.lua42
1 files changed, 27 insertions, 15 deletions
diff --git a/apk-model.lua b/apk-model.lua
index eaf1f40..186ef77 100644
--- a/apk-model.lua
+++ b/apk-model.lua
@@ -50,25 +50,36 @@ get_packages = function()
end
delete_package = function(package, sessiondata)
- local cmd = "/sbin/apk_delete " .. package .. " 2>&1"
- local f = io.popen( cmd )
- local cmdresult = f:read("*a") or ""
- f:close()
- -- Destroy menu and permissions info in session so recalculated
- if sessiondata then sessiondata.menu = nil end
- if sessiondata then sessiondata.permissions = nil end
+ local cmdresult = "Delete failed - Invalid package"
+ local loaded = get_loaded_packages()
+ for i,pack in pairs(loaded.value) do
+ if pack.name == package then
+ local cmd = "/sbin/apk_delete " .. package .. " 2>&1"
+ local f = io.popen( cmd )
+ cmdresult = f:read("*a") or ""
+ f:close()
+ -- Destroy menu and permissions info in session so recalculated
+ if sessiondata then sessiondata.menu = nil end
+ if sessiondata then sessiondata.permissions = nil end
+ end
+ end
return cfe({ value=cmdresult, label="Result of Delete" })
end
install_package = function(package,sessiondata)
- -- need to set path
- local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin apk_get install " .. package .. " 2>&1"
- local f = io.popen( cmd )
- local cmdresult = f:read("*a")
- f:close()
- -- Destroy menu and permissions info in session so recalculated
- if sessiondata then sessiondata.menu = nil end
- if sessiondata then sessiondata.permissions = nil end
+ local cmdresult = "Install failed - Invalid package"
+ local available = get_available_packages()
+ for i,pack in pairs(available.value) do
+ if pack == package then
+ local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin apk_get install " .. package .. " 2>&1"
+ local f = io.popen( cmd )
+ cmdresult = f:read("*a")
+ f:close()
+ -- Destroy menu and permissions info in session so recalculated
+ if sessiondata then sessiondata.menu = nil end
+ if sessiondata then sessiondata.permissions = nil end
+ end
+ end
return cfe({ value=cmdresult, label="Result of Install" })
end
@@ -79,6 +90,7 @@ get_config = function()
end
set_config = function(newconfig)
+ -- FIXME - don't know how to validate
if not getopts.setoptsinfile(configfile, "", "APK_PATH", newconfig.value.source.value) then
newconfig.errtxt = "Failed to update config"
end