Cleanup database code

This commit is contained in:
topjohnwu
2024-12-29 03:52:21 -08:00
committed by John Wu
parent 10e47248de
commit 3ca6d06f69
7 changed files with 231 additions and 214 deletions

View File

@@ -201,7 +201,7 @@ void scan_deny_apps() {
LOGI("denylist rm: [%s]\n", it->first.data());
ssprintf(sql, sizeof(sql), "DELETE FROM denylist WHERE package_name='%s'",
it->first.data());
db_exec(sql).check_err();
db_exec(sql);
it = pkg_to_procs.erase(it);
} else {
update_app_id(app_id, it->first, false);
@@ -222,11 +222,11 @@ static bool ensure_data() {
LOGI("denylist: initializing internal data structures\n");
default_new(pkg_to_procs_);
auto res = db_exec("SELECT * FROM denylist", [](db_row &row) -> bool {
bool res = db_exec("SELECT * FROM denylist", [](db_row &row) -> bool {
add_hide_set(row["package_name"].data(), row["process"].data());
return true;
});
if (res.check_err())
if (!res)
goto error;
default_new(app_id_to_pkgs_);
@@ -263,7 +263,7 @@ static int add_list(const char *pkg, const char *proc) {
char sql[4096];
ssprintf(sql, sizeof(sql),
"INSERT INTO denylist (package_name, process) VALUES('%s', '%s')", pkg, proc);
return db_exec(sql).check_err() ? DenyResponse::ERROR : DenyResponse::OK;
return db_exec(sql) ? DenyResponse::OK : DenyResponse::ERROR;
}
int add_list(int client) {
@@ -307,7 +307,7 @@ static int rm_list(const char *pkg, const char *proc) {
else
ssprintf(sql, sizeof(sql),
"DELETE FROM denylist WHERE package_name='%s' AND process='%s'", pkg, proc);
return db_exec(sql).check_err() ? DenyResponse::ERROR : DenyResponse::OK;
return db_exec(sql) ? DenyResponse::OK : DenyResponse::ERROR;
}
int rm_list(int client) {