diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2011-02-19 09:41:15 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2011-09-15 17:13:08 +0000 |
commit | 9e60a72b92c34d0bd6ce3791da68a37cccfe999b (patch) | |
tree | 60a1d89f405fa951a62ad72a550e149cea5090bc /src/lua-apk.c | |
parent | c79302d9732087dd13e8b1a9a4edb9ed13e78ce7 (diff) | |
download | apk-tools-9e60a72b92c34d0bd6ce3791da68a37cccfe999b.tar.gz apk-tools-9e60a72b92c34d0bd6ce3791da68a37cccfe999b.tar.bz2 apk-tools-9e60a72b92c34d0bd6ce3791da68a37cccfe999b.tar.xz apk-tools-9e60a72b92c34d0bd6ce3791da68a37cccfe999b.zip |
lua: implement exists/is_installed
Tests whether given package string is installed
Diffstat (limited to 'src/lua-apk.c')
-rw-r--r-- | src/lua-apk.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lua-apk.c b/src/lua-apk.c index 31987a6..8bd9a7b 100644 --- a/src/lua-apk.c +++ b/src/lua-apk.c @@ -196,12 +196,45 @@ static int Papk_who_owns(lua_State *L) return push_package(L, pkg); } +static int Papk_exists(lua_State *L) +{ + struct apk_database *db = checkdb(L, 1); + const char *depstr = luaL_checkstring(L, 2); + struct apk_dependency dep; + struct apk_name *name; + struct apk_package *pkg; + int i, r; + + r = apk_dep_from_blob(&dep, db, APK_BLOB_STR(depstr)); + if (r != 0) + goto ret_nil; + + name = dep.name; + for (i = 0; i < name->pkgs->num; i++) { + pkg = name->pkgs->item[i]; + if (pkg->ipkg != NULL) + break; + } + if (i >= name->pkgs->num) + goto ret_nil; + + if (!apk_dep_is_satisfied(&dep, pkg)) + goto ret_nil; + + return push_package(L, pkg); +ret_nil: + lua_pushnil(L); + return 1; +} + static const luaL_reg reg_apk_methods[] = { {"version_validate", Pversion_validate}, {"version_compare", Pversion_compare}, {"version_is_less", Pversion_is_less}, {"db_open", Papk_db_open}, {"who_owns", Papk_who_owns}, + {"exists", Papk_exists}, + {"is_installed", Papk_exists}, {NULL, NULL} }; |