Date: Tue, 2 Jul 2013 06:17:32 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253829 - in soc2013/mattbw/backend: . actions Message-ID: <201307020617.r626HWqp061853@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Tue Jul 2 06:17:32 2013 New Revision: 253829 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253829 Log: (still segfaults) we don't need a separate job match if we allow the database to be retrieved from the emitter Modified: soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/actions/get-files.c soc2013/mattbw/backend/actions/install-packages.c soc2013/mattbw/backend/pk-backend-pkgng.c soc2013/mattbw/backend/query.c soc2013/mattbw/backend/query.h Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Tue Jul 2 04:45:51 2013 (r253828) +++ soc2013/mattbw/backend/actions/get-details.c Tue Jul 2 06:17:32 2013 (r253829) @@ -30,8 +30,8 @@ static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES; -static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend); -static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); +static gboolean body(struct query *q); +static void emit(struct pkg *pkg, const gchar *id, struct query *q); /* * The thread that performs a GetDetails operation. Should be invoked by the @@ -40,7 +40,7 @@ gboolean get_details_thread(PkBackend *backend) { - return iterate_ids(backend, get_for); + return query_for_all_ids(backend, LOAD_FLAGS, body); } /* @@ -48,16 +48,16 @@ * found. */ static gboolean -get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) +body(struct query *q) { - return query_emit_match(id, backend, db, LOAD_FLAGS, emit_pkg); + return query_emit_match(q, emit); } /* * Emits the given package's details. To be used as an iterating function. */ static void -emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend) +emit(struct pkg *pkg, const gchar *id, struct query *q) { const char *description; const char *origin; @@ -71,7 +71,7 @@ PKG_ORIGIN, &origin, PKG_WWW, &www); - pk_backend_details(backend, + pk_backend_details(query_backend(q), id, license_name_from_pkg(pkg), group_from_origin(origin), Modified: soc2013/mattbw/backend/actions/get-files.c ============================================================================== --- soc2013/mattbw/backend/actions/get-files.c Tue Jul 2 04:45:51 2013 (r253828) +++ soc2013/mattbw/backend/actions/get-files.c Tue Jul 2 06:17:32 2013 (r253829) @@ -32,24 +32,34 @@ static const int FILE_NAME_STEP = 10; static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES; -static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend); -static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); +static gboolean body(struct query *q); +static void emit(struct pkg *pkg, const gchar *id, struct query *q); /* * The thread that performs a GetDetails operation. Should be invoked by the - * pk_backend_get_files hook. + * pk_backend_get_details hook. */ gboolean get_files_thread(PkBackend *backend) { - return iterate_ids(backend, get_for); + return query_for_all_ids(backend, LOAD_FLAGS, body); +} + +/* + * Look up and emit package details for the given PackageID, if it can be + * found. + */ +static gboolean +body(struct query *q) +{ + return query_emit_match(q, emit); } /* * Emits the given package's files. To be used as an iterating function. */ static void -emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend) +emit(struct pkg *pkg, const gchar *id, struct query *q) { struct pkg_file *file; int err; @@ -81,16 +91,6 @@ joined_filenames = g_strjoinv(";", filenames); g_strfreev(filenames); - pk_backend_files(backend, id, joined_filenames); + pk_backend_files(query_backend(q), id, joined_filenames); g_free(joined_filenames); } - -/* - * Look up and emit package files for the given PackageID, if it can be - * found. - */ -gboolean -get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) -{ - return query_emit_match(id, backend, db, LOAD_FLAGS, emit_pkg); -} Modified: soc2013/mattbw/backend/actions/install-packages.c ============================================================================== --- soc2013/mattbw/backend/actions/install-packages.c Tue Jul 2 04:45:51 2013 (r253828) +++ soc2013/mattbw/backend/actions/install-packages.c Tue Jul 2 06:17:32 2013 (r253829) @@ -26,7 +26,8 @@ #include "actions.h" /* install_packages_thread prototype */ -static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); +static gboolean body(struct query *q); +/*static void emit(struct pkg *pkg, const gchar *id, PkBackend *backend);*/ /* * The thread that performs an InstallPackages operation. Should be invoked by @@ -35,29 +36,16 @@ gboolean install_packages_thread(PkBackend *backend) { - return iterate_ids(backend, get_for); + return query_for_all_ids(backend, PKG_LOAD_BASIC, body); } /* * Look up and attempt to install the given PackageID, if it can be found. */ static gboolean -get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) +body(struct query *q) { - struct pkg_jobs *jobs; - int err; - - jobs = NULL; - err = pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db); - - if (err != EPKG_OK) - pk_backend_error_code(backend, - PK_ERROR_ENUM_INTERNAL_ERROR, - "pkg_jobs_new failed"); - else - err = query_job_match(id, backend, db, jobs); - /* TODO: actually install */ - pk_backend_error_code(backend, PK_ERROR_ENUM_NOT_SUPPORTED, NULL); - return err; + pk_backend_error_code(query_backend(q), PK_ERROR_ENUM_NOT_SUPPORTED, NULL); + return FALSE; } Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Tue Jul 2 04:45:51 2013 (r253828) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Tue Jul 2 06:17:32 2013 (r253829) @@ -45,9 +45,7 @@ static gboolean _updated_powertop = FALSE; static gboolean _has_signature = FALSE; static gboolean _use_eula = FALSE; -static gboolean _use_media = FALSE; static gboolean _use_gpg = FALSE; -static gboolean _use_trusted = TRUE; static gboolean _use_distro_upgrade = FALSE; static PkBitfield _filters = 0; static GSocket *_socket = NULL; @@ -357,43 +355,6 @@ _signal_timeout = g_timeout_add(1000, pk_backend_get_updates_timeout, backend); } -static gboolean -pk_backend_install_timeout(gpointer data) -{ - PkBackend *backend = (PkBackend *)data; - guint sub_percent; - - if (_progress_percentage == 100) { - pk_backend_finished(backend); - return FALSE; - } - if (_progress_percentage == 30) { - pk_backend_set_allow_cancel(backend, FALSE); - pk_backend_package(backend, PK_INFO_ENUM_INSTALLING, - "gtkhtml2;2.19.1-4.fc8;i386;fedora", - "An HTML widget for GTK+ 2.0"); - pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL); - } - if (_progress_percentage == 50) { - pk_backend_package(backend, PK_INFO_ENUM_INSTALLING, - "gtkhtml2-devel;2.19.1-0.fc8;i386;fedora", - "Devel files for gtkhtml"); - /* this duplicate package should be ignored */ - pk_backend_package(backend, PK_INFO_ENUM_INSTALLING, - "gtkhtml2-devel;2.19.1-0.fc8;i386;fedora", NULL); - pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL); - } - if (_progress_percentage > 30 && _progress_percentage < 50) { - sub_percent = ((gfloat) (_progress_percentage - 30.0) / 20.0) * 100.0; - pk_backend_set_sub_percentage(backend, sub_percent); - } else { - pk_backend_set_sub_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); - } - _progress_percentage += 1; - pk_backend_set_percentage(backend, _progress_percentage); - return TRUE; -} - /** * pk_backend_install_packages: */ @@ -401,6 +362,7 @@ pk_backend_install_packages(PkBackend *backend, gboolean only_trusted, gchar **package_ids) { INTENTIONALLY_IGNORE(only_trusted); + INTENTIONALLY_IGNORE(package_ids); pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); Modified: soc2013/mattbw/backend/query.c ============================================================================== --- soc2013/mattbw/backend/query.c Tue Jul 2 04:45:51 2013 (r253828) +++ soc2013/mattbw/backend/query.c Tue Jul 2 06:17:32 2013 (r253829) @@ -43,15 +43,23 @@ gboolean local_repo; }; - static const char *get_repo_of(struct pkg *pkg); static const char *get_repo_of_remote(struct pkg *pkg); -static gboolean try_id_match(struct pkg *pkg, struct query *state, gchar **match_id); -static gboolean match(struct query *state, gchar **match_id_p, struct pkg **match_pkg_p); +static gboolean match(struct query *q, gchar **match_id_p, struct pkg **match_pkg_p); +static gboolean try_id_match(struct pkg *pkg, struct query *q, gchar **match_id); +static gboolean match_id_in_it(struct pkgdb_it *it, struct query *q, gchar **match_id_p, struct pkg **match_pkg_p); +static void query_free_contents(struct query *q); + +/* Returns the backend stored inside the struct query. */ +PkBackend * +query_backend(struct query *q) +{ + return (q == NULL ? NULL : q->backend); +} -gboolean +static gboolean match_id_in_it(struct pkgdb_it *it, - struct query *state, + struct query *q, gchar **match_id_p, struct pkg **match_pkg_p) { @@ -63,10 +71,10 @@ found = FALSE; *match_pkg_p = NULL; *match_id_p = NULL; - load_flags = state->load_flags; + load_flags = q->load_flags; for (HASH_FOR(err, pkgdb_it_next, it, match_pkg_p, load_flags)) { - if (try_id_match(*match_pkg_p, state, match_id_p) == TRUE) { + if (try_id_match(*match_pkg_p, q, match_id_p) == TRUE) { found = TRUE; break; } @@ -131,7 +139,7 @@ } static gboolean -try_id_match(struct pkg *pkg, struct query *state, char **match_id) +try_id_match(struct pkg *pkg, struct query *q, char **match_id) { const char *p_arch; const char *p_data; @@ -154,38 +162,46 @@ * PackageID. Of course, the original ID might have missing fields * (NULLs), so we treat a comparison involving one as a success. */ - return (string_match(state->name, p_name) && - string_match(state->version, p_version) && - string_match(state->arch, p_arch) && - string_match(state->data, p_data)) ? TRUE : FALSE; + return (string_match(q->name, p_name) && + string_match(q->version, p_version) && + string_match(q->arch, p_arch) && + string_match(q->data, p_data)) ? TRUE : FALSE; } /* - * Iterates over a set of PackageIDs provided for this job with a function. + * Iterates a query function over all PackageIDs provided for this job. * - * This provides each iterating function call with an open database connection - * and updates the percentage after each iteration. + * This provides each iterating function call with a query structure ready to + * run and updates the percentage after each iteration. * * It also *finishes* the backend job. */ gboolean -iterate_ids(PkBackend *backend, ids_func_ptr iterate_f) +query_for_all_ids(PkBackend *backend, int load_flags, query_body_ptr body) { gboolean no_error_yet; gchar **package_ids; guint len; guint i; struct pkgdb *db; + struct query *q; package_ids = pk_backend_get_strv(backend, "package_ids"); len = g_strv_length(package_ids); db = NULL; + q = NULL; no_error_yet = open_remote_db(&db, backend); pk_backend_set_percentage(backend, 0); for (i = 0; i < len && no_error_yet; i++) { - no_error_yet = iterate_f(package_ids[i], backend, db); + no_error_yet = query_init(package_ids[i], + backend, + db, + load_flags, + &q); + if (no_error_yet == TRUE) + no_error_yet = body(q); pk_backend_set_percentage(backend, ((i * 100) / len)); } pkgdb_close(db); @@ -200,15 +216,15 @@ * matching result to an emitter function. */ gboolean -query_emit_match(struct query *state, int load_flags, emit_ptr emitter) +query_emit_match(struct query *q, emit_ptr emitter) { gboolean success; gchar *match_id; struct pkg *match_pkg; - success = match(state, &match_id, &match_pkg); + success = match(q, &match_id, &match_pkg); if (success == TRUE && match_id != NULL && match_pkg != NULL) - emitter(match_pkg, match_id, state->backend); + emitter(match_pkg, match_id, q); pkg_free(match_pkg); g_free(match_id); @@ -226,28 +242,28 @@ * * TODO: do something about the redundancy in both this and the emitter variant. */ -gboolean -query_job_match(struct query *state, struct pkg_jobs *jobs) -{ - gboolean success; - gchar *match_id; - struct pkg *match_pkg; - - state->load_flags = PKG_LOAD_BASIC; - success = match(state, &match_id, &match_pkg); - if (success == TRUE && match_id != NULL && match_pkg != NULL) { - gchar *name[1]; - - name[0] = NULL; - pkg_get(match_pkg, PKG_NAME, &(name[0])); - - pkg_jobs_add(jobs, MATCH_EXACT, name, 1); - } - pkg_free(match_pkg); - g_free(match_id); - - return success; -} +/* + * // TODO: salvage something out of this gboolean emit_job(struct pkg *pkg, + * const gchar *id, struct query *q, pkg_jobs_t type, job_ptr user) { + * gboolean success; gchar *match_id; struct pkg *match_pkg; + * struct pkg_jobs *jobs; + * + * success = TRUE; jobs = NULL; + * + * q->load_flags = PKG_LOAD_BASIC; success = match(q, &match_id, &match_pkg); if + * (success == TRUE && match_id != NULL && match_pkg != NULL) { + * + * // Duplicated because pkg_jobs_add is not const correct. // gchar + * *name; int err; + * + * err = pkg_jobs_new(&jobs, type, q->db); if (err != EPKG_OK) { + * pk_backend_error_code(q->backend, PK_ERROR_ENUM_INTERNAL_ERROR, + * "pkg_jobs_new failed"); success = FALSE; } else { name = + * g_strdup(q->name); pkg_jobs_add(jobs, MATCH_EXACT, &name, 1); + * g_free(name); } pkg_free(match_pkg); g_free(match_id); + * + * return success; } + */ /* * Performs a package database query against a (potentially partial) @@ -256,7 +272,7 @@ * The exact type of query depends on the repository given. */ static gboolean -match(struct query *state, gchar **match_id_p, struct pkg **match_pkg_p) +match(struct query *q, gchar **match_id_p, struct pkg **match_pkg_p) { gboolean success; gboolean try_local; @@ -265,42 +281,42 @@ struct pkgdb_it *it; success = FALSE; - db = state->db; + db = q->db; /* * If we're not given a specific repository in the PackageID, we want * to try searching locally first and then remotely; otherwise which * database we query depends on the repository we have been given. */ - if (state->any_repo == TRUE) + if (q->any_repo == TRUE) try_local = try_remote = TRUE; else { - try_local = (state->local_repo == TRUE); - try_remote = (state->local_repo == FALSE); + try_local = (q->local_repo == TRUE); + try_remote = (q->local_repo == FALSE); } /* Try a local search first, if applicable. */ if (try_local == TRUE) - it = pkgdb_query(db, state->name, MATCH_EXACT); + it = pkgdb_query(db, q->name, MATCH_EXACT); else it = NULL; if (it != NULL) - success = match_id_in_it(it, state, match_id_p, match_pkg_p); + success = match_id_in_it(it, q, match_id_p, match_pkg_p); /* Next, try a remote search, again only if applicable. */ if (success == FALSE && (try_remote == TRUE)) - it = pkgdb_rquery(db, state->name, MATCH_EXACT, state->data); + it = pkgdb_rquery(db, q->name, MATCH_EXACT, q->data); else it = NULL; if (it != NULL) - success = match_id_in_it(it, state, match_id_p, match_pkg_p); + success = match_id_in_it(it, q, match_id_p, match_pkg_p); /* * Assume any error is due to not finding packages. At time of * writing this is true, but may change. */ if (success == FALSE) - pk_backend_error_code(state->backend, + pk_backend_error_code(q->backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found"); @@ -309,43 +325,47 @@ /* Creates a struct query for the given backend and target ID. */ gboolean -query_init(const gchar *id, PkBackend *backend, int load_flags, - struct query **state_p) +query_init(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + struct query **q_p) { gboolean success; gboolean loading_files; - struct query *state; + struct query *q; - state = *state_p; - if (state == NULL) - state = g_new0(struct query, 1); + q = *q_p; + if (q == NULL) + q = g_new0(struct query, 1); + else + query_free_contents(q); - state->backend = backend; - state->load_flags = load_flags; + q->backend = backend; + q->load_flags = load_flags; + q->db = db; + + success = split_id(id, + &(q->strv), + &(q->name), + &(q->version), + &(q->arch), + &(q->data)); + if (success == FALSE) + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_ID_INVALID, + "invalid package id"); - success = open_remote_db(&(state->db), backend); - if (success == TRUE) { - success = split_id(id, - &(state->strv), - &(state->name), - &(state->version), - &(state->arch), - &(state->data)); - if (success == FALSE) - pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_ID_INVALID, - "invalid package id"); - } /* * Check the repository to make sure it's sane, and populate the repo * type flags in the state for later consumption. */ if (success == TRUE) { - if (state->data != NULL) - state->any_repo = TRUE; - else if (strcmp(state->data, "installed") == 0) - state->local_repo = TRUE; - else if (pkg_repo_find_ident(state->data) != NULL) { + if (q->data != NULL) + q->any_repo = TRUE; + else if (strcmp(q->data, "installed") == 0) + q->local_repo = TRUE; + else if (pkg_repo_find_ident(q->data) != NULL) { pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "no such repository"); @@ -357,29 +377,34 @@ * non-installed packages. */ loading_files = (load_flags & PKG_LOAD_FILES) ? TRUE : FALSE; - if (success == TRUE && state->local_repo == FALSE && loading_files) { + if (success == TRUE && q->local_repo == FALSE && loading_files) { pk_backend_error_code(backend, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "cannot get files for remote package"); success = FALSE; } if (success == FALSE) { - query_free(state); - state = NULL; + query_free(q); + q = NULL; } - *state_p = state; + *q_p = q; return success; } void -query_free(struct query *state) +query_free(struct query *q) { - if (state != NULL) { - if (state->db != NULL) - pkgdb_close(state->db); - if (state->strv != NULL) - g_strfreev(state->strv); - /* This should free the other split ID pointer targets. */ - g_free(state); + if (q != NULL) { + query_free_contents(q); + g_free(q); } } + +static void +query_free_contents(struct query *q) +{ + /* The database is owned by the creator and is not freed. */ + /* This should free the other split ID pointer targets. */ + if (q->strv != NULL) + g_strfreev(q->strv); +} Modified: soc2013/mattbw/backend/query.h ============================================================================== --- soc2013/mattbw/backend/query.h Tue Jul 2 04:45:51 2013 (r253828) +++ soc2013/mattbw/backend/query.h Tue Jul 2 06:17:32 2013 (r253829) @@ -25,19 +25,16 @@ #include "pk-backend.h" #include "pkg.h" -typedef void (*emit_ptr) (struct pkg *pkg, - const gchar *id, - PkBackend *backend); -typedef gboolean (*ids_func_ptr) (const gchar *id, PkBackend *backend, struct pkgdb *db); - struct query; -gboolean query_emit_match(struct query *state, int load_flags, emit_ptr emitter); -gboolean query_job_match(struct query *state, struct pkg_jobs *jobs); -gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); +typedef void (*emit_ptr) (struct pkg *pkg, const gchar *id, struct query *q); +typedef gboolean (*query_body_ptr) (struct query *q); + -/* Creates a struct query for the given backend and target ID. */ -gboolean query_init(const gchar *id, PkBackend *backend, int load_flags, struct query **state_p); -void query_free(struct query *state); +PkBackend *query_backend(struct query *q); +gboolean query_emit_match(struct query *q, emit_ptr emitter); +gboolean query_for_all_ids(PkBackend *backend, int load_flags, query_body_ptr body); +gboolean query_init(const gchar *id, PkBackend *backend, struct pkgdb *db, int load_flags, struct query **q_p); +void query_free(struct query *q); #endif /* !_PKGNG_BACKEND_QUERY_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307020617.r626HWqp061853>
