int datalist_writedb(DSTATE *s) { if (!s->dodbsave) { return 1; } if (!checkdb(s->datalist->data.interface, s->dirname)) { return 0; } if (spacecheck(s->dirname)) { if (writedb(s->datalist->data.interface, s->dirname, 0)) { if (!s->dbsaved) { snprintf(errorstring, 512, "Database write possible again."); printe(PT_Info); s->dbsaved = 1; } } else { if (s->dbsaved) { snprintf(errorstring, 512, "Unable to write database, continuing with cached data."); printe(PT_Error); s->dbsaved = 0; } } } else { /* show freespace error only once */ if (s->dbsaved) { snprintf(errorstring, 512, "Free diskspace check failed, unable to write database, continuing with cached data."); printe(PT_Error); s->dbsaved = 0; } } return 1; }
static int db_query(lua_State *L) { int rv; libretrodb_cursor_t *cursor = NULL; libretrodb_t *db = checkdb(L); const char *query = luaL_checkstring(L, -1); const char *error = NULL; libretrodb_query_t *q = libretrodb_query_compile( db, query, strlen(query), &error); if (error) { lua_pushnil(L); lua_pushstring(L, error); } else { cursor = lua_newuserdata(L, sizeof(libretrodb_t)); if ((rv = libretrodb_cursor_open(db, cursor, q)) == 0) { luaL_getmetatable(L, "RarchDB.Cursor"); lua_setmetatable(L, -2); lua_pushnil(L); } else { lua_pop(L, 1); lua_pushnil(L); lua_pushstring(L, strerror(-rv)); } libretrodb_query_free(q); } return 2; }
static int Papk_who_owns(lua_State *L) { struct apk_database *db = checkdb(L, 1); const char *path = luaL_checkstring(L, 2); struct apk_package *pkg = apk_db_get_file_owner(db, APK_BLOB_STR(path)); return push_package(L, pkg); }
END_TEST START_TEST(checkdb_does_not_find_nonexisting_file) { ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(checkdb("nonexistingdb", TESTDBDIR), 0); }
END_TEST START_TEST(checkdb_finds_existing_file) { ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("existingdb"), 1); ck_assert_int_eq(checkdb("existingdb", TESTDBDIR), 1); }
static int Pinstalled(lua_State *L) { struct apk_database *db = checkdb(L, 1); struct apk_installed_package_iterator *i; i = (struct apk_installed_package_iterator *) lua_newuserdata(L, sizeof(*i)); i->end = &db->installed.packages; i->node = list_entry((&db->installed.packages)->next, struct apk_installed_package, installed_pkgs_list); lua_pushcclosure(L, iterate_installed, 1); return 1; }
static int db_cursor_open(lua_State *L) { int rv; libretrodb_cursor_t *cursor = NULL; libretrodb_t *db = checkdb(L); cursor = lua_newuserdata(L, sizeof(libretrodb_t)); if ((rv = libretrodb_cursor_open(db, cursor, NULL)) == 0) { luaL_getmetatable(L, "RarchDB.Cursor"); lua_setmetatable(L, -2); lua_pushnil(L); } else { lua_pop(L, 1); lua_pushnil(L); lua_pushstring(L, strerror(-rv)); } return 2; }
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_package *pkg; apk_blob_t blob = APK_BLOB_STR(depstr); apk_blob_pull_dep(&blob, db, &dep); if (APK_BLOB_IS_NULL(blob) || blob.len > 0) goto ret_nil; pkg = apk_pkg_get_installed(dep.name); if (pkg == NULL) goto ret_nil; if (apk_dep_analyze(&dep, pkg) & APK_DEP_SATISFIES) return push_package(L, pkg); ret_nil: lua_pushnil(L); return 1; }
static sqlite3 * checkdb_sqlite3(lua_State * L, int narg) { return checkdb(L, narg)->sqlite3; }
static int db_close(lua_State *L) { libretrodb_t *db = checkdb(L); libretrodb_close(db); return 0; }
static int l_db_gc(lua_State* L) { DB * db = checkdb(L, 1); close_sqlite(db); return 0; }
static int Papk_db_close(lua_State *L) { struct apk_database *db = checkdb(L, 1); apk_db_close(db); return 0; }