From owner-svn-soc-all@FreeBSD.ORG Fri Jul 5 00:59:10 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id CCB5A93D for ; Fri, 5 Jul 2013 00:59:10 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id BD76317B9 for ; Fri, 5 Jul 2013 00:59:10 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r650xAnQ085258 for ; Fri, 5 Jul 2013 00:59:10 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r650xAUS085252 for svn-soc-all@FreeBSD.org; Fri, 5 Jul 2013 00:59:10 GMT (envelope-from mattbw@FreeBSD.org) Date: Fri, 5 Jul 2013 00:59:10 GMT Message-Id: <201307050059.r650xAUS085252@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254075 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jul 2013 00:59:10 -0000 Author: mattbw Date: Fri Jul 5 00:59:10 2013 New Revision: 254075 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254075 Log: (builds, regresses) more work on the query system ready for querying to jobs. Modified: soc2013/mattbw/backend/actions/install-packages.c soc2013/mattbw/backend/pk-backend-pkgng.c soc2013/mattbw/backend/query.c soc2013/mattbw/backend/query.h soc2013/mattbw/backend/utils.h Modified: soc2013/mattbw/backend/actions/install-packages.c ============================================================================== --- soc2013/mattbw/backend/actions/install-packages.c Thu Jul 4 23:08:27 2013 (r254074) +++ soc2013/mattbw/backend/actions/install-packages.c Fri Jul 5 00:59:10 2013 (r254075) @@ -22,12 +22,15 @@ #include "../pk-backend.h" #include "pkg.h" +#include "../hash_traverse.h" /* HASH_FOR */ #include "../query.h" /* Package querying */ +#include "../utils.h" /* INTENTIONALLY_IGNORE */ #include "actions.h" /* install_packages_thread prototype */ static gboolean body(struct query *q); -/*static void emit(struct pkg *pkg, const gchar *id, PkBackend *backend);*/ +static void emit(struct pkg *pkg, const gchar *id, struct query *q); +static void job(struct pkg_jobs *jobs, struct query *q); /* * The thread that performs an InstallPackages operation. Should be invoked by @@ -36,6 +39,7 @@ gboolean install_packages_thread(PkBackend *backend) { + return query_for_all_ids(backend, PKG_LOAD_BASIC, body); } @@ -45,7 +49,45 @@ static gboolean body(struct query *q) { - /* TODO: actually install */ - pk_backend_error_code(query_backend(q), PK_ERROR_ENUM_NOT_SUPPORTED, NULL); - return FALSE; + + return query_emit_match(q, emit); +} + +/* + * Tries to install the given package. + */ +static void +emit(struct pkg *pkg, const gchar *id, struct query *q) +{ + + INTENTIONALLY_IGNORE(id); + return query_emit_to_job(pkg, q, PKG_JOBS_INSTALL, job); +} + +/* + * Tries to install the given package. + */ +static void +job(struct pkg_jobs *jobs, struct query *q) +{ + int err; + PkBackend *backend; + + backend = query_backend(q); + + err = pkg_jobs_solve(jobs); + if (err == EPKG_OK) { + struct pkg *pkg; + + pkg = NULL; + for (HASH_FOR(err, pkg_jobs, jobs, &pkg)) { + //pk_backend_package(backend, + // PK_INFO_ENUM_INSTALLING, + ; + + } + } else + pk_backend_error_code(backend, + PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, + "could not solve the job"); } Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Thu Jul 4 23:08:27 2013 (r254074) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Fri Jul 5 00:59:10 2013 (r254075) @@ -29,11 +29,10 @@ #include "pk-backend.h" #include "pkg.h" +#include "utils.h" /* INTENTIONALLY_IGNORE */ #include "groups.h" /* available_groups */ #include "actions/actions.h" /* Actions threads */ -#define INTENTIONALLY_IGNORE(x) (void)(x) - /* static bodges */ static guint _progress_percentage = 0; static gulong _signal_timeout = 0; Modified: soc2013/mattbw/backend/query.c ============================================================================== --- soc2013/mattbw/backend/query.c Thu Jul 4 23:08:27 2013 (r254074) +++ soc2013/mattbw/backend/query.c Fri Jul 5 00:59:10 2013 (r254075) @@ -46,41 +46,35 @@ static const char *get_repo_of(struct pkg *pkg); static const char *get_repo_of_remote(struct pkg *pkg); 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 gboolean try_id_match(struct pkg *pkg, struct query *q, gchar **match_id); +static int jobs_add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg); static void query_free_contents(struct query *q); +static void query_pkg_to_id_through(struct pkg *pkg, gchar **name_p, const gchar **strv); /* Returns the backend stored inside the struct query. */ -PkBackend * +PkBackend * query_backend(struct query *q) { return (q == NULL ? NULL : q->backend); } -static gboolean -match_id_in_it(struct pkgdb_it *it, - struct query *q, - gchar **match_id_p, - struct pkg **match_pkg_p) +/* Converts a package to a PackageID. */ +void +query_pkg_to_id(struct pkg *pkg, gchar **id_p) { - /* TODO: Filters */ - gboolean found; - int err; - int load_flags; + const gchar **id_bits; - found = FALSE; - *match_pkg_p = NULL; - *match_id_p = NULL; - load_flags = q->load_flags; + /* Make sure the initial string vector's pointers are all NULL */ + id_bits = g_new0(const gchar *, 4); - for (HASH_FOR(err, pkgdb_it_next, it, match_pkg_p, load_flags)) { - if (try_id_match(*match_pkg_p, q, match_id_p) == TRUE) { - found = TRUE; - break; - } - } + /* This is split through an intermediate function so the same code + * can be used for the ID-checking logic. + */ + query_pkg_to_id_through(pkg, id_p, id_bits); - return found; + /* AFAIK we don't own any of the strings, so we don't use g_strfreev. */ + g_free(id_bits); } /* Gets the PackageKit repository name for the package. */ @@ -139,33 +133,82 @@ } static gboolean +match_id_in_it(struct pkgdb_it *it, + struct query *q, + gchar **match_id_p, + struct pkg **match_pkg_p) +{ + /* TODO: Filters */ + gboolean found; + int err; + int load_flags; + + found = FALSE; + *match_pkg_p = NULL; + *match_id_p = NULL; + 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, q, match_id_p) == TRUE) { + found = TRUE; + break; + } + } + + return found; +} + +static gboolean try_id_match(struct pkg *pkg, struct query *q, char **match_id) { - const char *p_arch; - const char *p_data; - const char *p_name; - const char *p_version; + gboolean cmp; + const gchar **pkg_id_bits; - pkg_get(pkg, - PKG_ARCH, &p_arch, - PKG_NAME, &p_name, - PKG_VERSION, &p_version); - - p_data = get_repo_of(pkg); - - if (*match_id != NULL) - g_free(*match_id); - *match_id = pk_package_id_build(p_name, p_version, p_arch, p_data); + pkg_id_bits = g_new0(const gchar *, 4); + query_pkg_to_id_through(pkg, match_id, pkg_id_bits); + /* * Succeed if this package's PackageID fields match the original * PackageID. Of course, the original ID might have missing fields * (NULLs), so we treat a comparison involving one as a success. */ - 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; + cmp = (string_match(q->name, pkg_id_bits[0]) && + string_match(q->version, pkg_id_bits[1]) && + string_match(q->arch, pkg_id_bits[2]) && + string_match(q->data, pkg_id_bits[3])) ? TRUE : FALSE; + g_free(pkg_id_bits); + + return cmp; +} + +/* Adds a single package to a jobs structure. */ +static int +jobs_add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg) +{ + char *name; + + pkg_get(pkg, PKG_NAME, &name); + return pkg_jobs_add(jobs, type, &name, 1); +} + +/* Converts a package to a PackageID, dumping the intermediate information into + * the pointed-to string vector (which must have at least 4 places, and they + * should be NULL). + */ +static void +query_pkg_to_id_through(struct pkg *pkg, gchar **id_p, const gchar **strv) +{ + pkg_get(pkg, + PKG_NAME, strv, + PKG_ARCH, strv + 1, + PKG_VERSION, strv + 2); + + *(strv + 3) = get_repo_of(pkg); + + if (*id_p != NULL) + g_free(*id_p); + *id_p = pk_package_id_build(strv[0], strv[1], strv[2], strv[3]); } /* @@ -235,37 +278,43 @@ } /* - * Performs a package database query against a PackageID, and then adds the - * matching results to a pkg job. - * - * The round trip through the database seems like a strange idea given that - * pkg_jobs takes a package name. At the moment this is done to ensure that - * the package matches the PackageID fully. - * - * TODO: do something about the redundancy in both this and the emitter variant. - */ -/* - * // 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; } + * For adapting an emitter function into one that solves and applies a job. */ +void +query_emit_to_job(struct pkg *pkg, + struct query *q, + pkg_jobs_t type, + job_emit_ptr job_emitter) +{ + int err; + struct pkg_jobs *jobs; + + jobs = NULL; + err = pkg_jobs_new(&jobs, type, q->db); + if (err == EPKG_OK) { + err = pkg_jobs_set_repository(jobs, q->data); + if (err == EPKG_OK) { + err = jobs_add_pkg(jobs, MATCH_EXACT, pkg); + if (err == EPKG_OK) + job_emitter(jobs, q); + else + pk_backend_error_code(q->backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "could not add to job"); + + } else + pk_backend_error_code(q->backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "could not set repo"); + + } else + pk_backend_error_code(q->backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "could not init pkg_jobs"); + + pkg_jobs_free(jobs); + +} /* * Performs a package database query against a (potentially partial) Modified: soc2013/mattbw/backend/query.h ============================================================================== --- soc2013/mattbw/backend/query.h Thu Jul 4 23:08:27 2013 (r254074) +++ soc2013/mattbw/backend/query.h Fri Jul 5 00:59:10 2013 (r254075) @@ -28,6 +28,7 @@ struct query; typedef void (*emit_ptr) (struct pkg *pkg, const gchar *id, struct query *q); +typedef void (*job_emit_ptr) (struct pkg_jobs *jobs, struct query *q); typedef gboolean (*query_body_ptr) (struct query *q); @@ -35,6 +36,8 @@ 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_emit_to_job(struct pkg *pkg, struct query *q, pkg_jobs_t type, job_emit_ptr job_emitter); void query_free(struct query *q); +void query_pkg_to_id(struct pkg *pkg, gchar **id_p); #endif /* !_PKGNG_BACKEND_QUERY_H_ */ Modified: soc2013/mattbw/backend/utils.h ============================================================================== --- soc2013/mattbw/backend/utils.h Thu Jul 4 23:08:27 2013 (r254074) +++ soc2013/mattbw/backend/utils.h Fri Jul 5 00:59:10 2013 (r254075) @@ -24,6 +24,8 @@ #include /* gboolean */ +#define INTENTIONALLY_IGNORE(x) (void)(x) + const char *null_if_empty(const char *in); gboolean split_id(const char *id,