From owner-svn-soc-all@FreeBSD.ORG Mon Jul 1 22:13:01 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 E5717D66 for ; Mon, 1 Jul 2013 22:13:01 +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 D65C4166E for ; Mon, 1 Jul 2013 22:13:01 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r61MD1IP098159 for ; Mon, 1 Jul 2013 22:13:01 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r61MD1Nj098150 for svn-soc-all@FreeBSD.org; Mon, 1 Jul 2013 22:13:01 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 1 Jul 2013 22:13:01 GMT Message-Id: <201307012213.r61MD1Nj098150@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: r253817 - 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: Mon, 01 Jul 2013 22:13:02 -0000 Author: mattbw Date: Mon Jul 1 22:13:01 2013 New Revision: 253817 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253817 Log: replace iterate.[ch] with query.[ch] and move related functions back in from db. Added: soc2013/mattbw/backend/query.c - copied, changed from r253789, soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/query.h - copied, changed from r253789, soc2013/mattbw/backend/iterate.h Deleted: soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/iterate.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/actions/get-files.c soc2013/mattbw/backend/actions/install-packages.c soc2013/mattbw/backend/db.c soc2013/mattbw/backend/db.h Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Mon Jul 1 21:59:17 2013 (r253816) +++ soc2013/mattbw/backend/Makefile Mon Jul 1 22:13:01 2013 (r253817) @@ -2,7 +2,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c groups.c db.c licenses.c iterate.c utils.c +SRCS= pk-backend-pkgng.c groups.c db.c licenses.c query.c utils.c SRCS+= actions/get-details.c \ actions/get-files.c \ actions/get-repo-list.c \ Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Mon Jul 1 21:59:17 2013 (r253816) +++ soc2013/mattbw/backend/actions/get-details.c Mon Jul 1 22:13:01 2013 (r253817) @@ -22,9 +22,8 @@ #include "../pk-backend.h" #include "pkg.h" -#include "../db.h" /* db_query_from_id */ #include "../groups.h" /* group_from_origin */ -#include "../iterate.h" /* Package iteration */ +#include "../query.h" /* Package querying */ #include "../licenses.h" /* license_from_pkg */ #include "actions.h" /* get_details_thread prototype */ @@ -51,7 +50,7 @@ static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) { - return db_query_with_id(id, backend, db, LOAD_FLAGS, emit_pkg); + return query_emit_match(id, backend, db, LOAD_FLAGS, emit_pkg); } /* Modified: soc2013/mattbw/backend/actions/get-files.c ============================================================================== --- soc2013/mattbw/backend/actions/get-files.c Mon Jul 1 21:59:17 2013 (r253816) +++ soc2013/mattbw/backend/actions/get-files.c Mon Jul 1 22:13:01 2013 (r253817) @@ -22,10 +22,9 @@ #include "../pk-backend.h" #include "pkg.h" -#include "../db.h" /* db_query_from_id */ #include "../groups.h" /* group_from_origin */ #include "../hash_traverse.h" /* HASH_FOR */ -#include "../iterate.h" /* Package iteration */ +#include "../query.h" /* Package querying */ #include "../licenses.h" /* license_from_pkg */ #include "actions.h" /* get_files_thread prototype */ @@ -93,5 +92,5 @@ gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) { - return db_query_with_id(id, backend, db, LOAD_FLAGS, emit_pkg); + 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 Mon Jul 1 21:59:17 2013 (r253816) +++ soc2013/mattbw/backend/actions/install-packages.c Mon Jul 1 22:13:01 2013 (r253817) @@ -22,8 +22,7 @@ #include "../pk-backend.h" #include "pkg.h" -#include "../db.h" /* db_query_from_id */ -#include "../iterate.h" /* Package iteration */ +#include "../query.h" /* Package querying */ #include "actions.h" /* install_packages_thread prototype */ @@ -56,7 +55,7 @@ PK_ERROR_ENUM_INTERNAL_ERROR, "pkg_jobs_new failed"); else - err = db_query_to_job(id, backend, db, jobs); + err = query_job_match(id, backend, db, jobs); /* TODO: actually install */ pk_backend_error_code(backend, PK_ERROR_ENUM_NOT_SUPPORTED, NULL); Modified: soc2013/mattbw/backend/db.c ============================================================================== --- soc2013/mattbw/backend/db.c Mon Jul 1 21:59:17 2013 (r253816) +++ soc2013/mattbw/backend/db.c Mon Jul 1 22:13:01 2013 (r253817) @@ -25,26 +25,8 @@ #include "pkg.h" #include "db.h" /* prototypes */ -#include "iterate.h" /* pkg_func_ptr */ #include "utils.h" /* null_if_empty, split_id */ -static gboolean -db_query_split(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db, - int load_flags, - gchar **match_id_p, - struct pkg **match_pkg_p); -static gboolean -db_query_match(const gchar *id, - PkBackend *backend, - struct pkgdb *db, - int load_flags, - gchar **match_id_p, - struct pkg **match_pkg_p); /* * Opens a pkgdb ready for remote operations. This will always return TRUE if @@ -87,197 +69,3 @@ return success; } - -/* - * Performs a package database query against a PackageID, and then hands the - * matching results to an emitter function. - */ -gboolean -db_query_with_id(const gchar *id, - PkBackend *backend, - struct pkgdb *db, - int load_flags, - pkg_func_ptr emitter) -{ - gboolean success; - gchar *match_id; - struct pkg *match_pkg; - - success = db_query_match(id, - backend, - db, - load_flags, - &match_id, - &match_pkg); - if (success == TRUE && match_id != NULL && match_pkg != NULL) - emitter(match_pkg, match_id, backend); - - pkg_free(match_pkg); - g_free(match_id); - - return success; -} - -/* - * 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. - */ -gboolean -db_query_to_job(const gchar *id, - PkBackend *backend, - struct pkgdb *db, - struct pkg_jobs *jobs) -{ - gboolean success; - gchar *match_id; - struct pkg *match_pkg; - - success = db_query_match(id, - backend, - db, - PKG_LOAD_BASIC, - &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; -} - -/* - * Performs a package database query against a (potentially partial) - * PackageID, retrieving the matched package and its full PackageID. - * - * The exact type of query depends on the repository given. - */ -static gboolean -db_query_match(const gchar *id, - PkBackend *backend, - struct pkgdb *db, - int load_flags, - gchar **match_id_p, - struct pkg **match_pkg_p) -{ - gboolean query_success; - gboolean split_success; - const gchar *arch; - const gchar *data; - const gchar *name; - const gchar *version; - gchar **strv; - - query_success = FALSE; - split_success = FALSE; - strv = NULL; - - split_success = split_id(id, &strv, &name, &version, &arch, &data); - if (split_success == FALSE) - pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_ID_INVALID, - "invalid package id"); - else { - /* - * If the PackageID has a repository specified (even if it's - * "installed" i.e. currently installed package), running - * "get_details_query" directly should handle remote/local - * queries properly. - * - * If there is no repository specified, however (data is NULL), - * we may need to check both the local and (all) remote - * repositories, in that order. (TODO: local packages?) - */ - if (data == NULL) - /* Try local database first. */ - query_success = db_query_split(name, - version, - arch, - "installed", - backend, - db, - load_flags, - match_id_p, - match_pkg_p); - if (query_success == FALSE) - query_success = db_query_split(name, version, arch, data, - backend, db, load_flags, 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 (query_success == FALSE) - pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_NOT_FOUND, - "package not found"); - g_strfreev(strv); - } - - return query_success; -} - -/* - * Looks the split PackageID up in the package databases. - * - * Usually, a remote query will be done on the repository named by "reponame". - * If reponame is NULL, a remote check will be done against all repostories. - * If it is "installed", a local check will be done. (This is in keeping - * with the special meaning of the "installed" repository in PackageIDs). - */ -static gboolean -db_query_split(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db, - int load_flags, - gchar **match_id_p, - struct pkg **match_pkg_p) -{ - struct pkgdb_it *it; - gboolean success; - - success = FALSE; - it = NULL; - - /* Are we doing a local query? */ - /* - * If we got a repository name, then we want to make sure it - * corresponds to a real repository. - */ - if (g_strcmp0(reponame, "installed") == 0) - it = pkgdb_query(db, name, MATCH_EXACT); - else if (pkg_repo_find_ident(reponame) != NULL) - it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); - else - pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_NOT_FOUND, - "no such repository"); - - - if (it != NULL) - success = match_id_in_it(it, - backend, - name, - version, - arch, - reponame, - load_flags, - match_id_p, - match_pkg_p); - return success; -} Modified: soc2013/mattbw/backend/db.h ============================================================================== --- soc2013/mattbw/backend/db.h Mon Jul 1 21:59:17 2013 (r253816) +++ soc2013/mattbw/backend/db.h Mon Jul 1 22:13:01 2013 (r253817) @@ -26,19 +26,6 @@ #include "pk-backend.h" /* PkBackend */ #include "pkg.h" /* struct pkgdb */ -#include "iterate.h" /* pk_func_ptr */ - gboolean open_remote_db(struct pkgdb **db, PkBackend *backend); -gboolean -db_query_with_id(const gchar *package_id, - PkBackend *backend, - struct pkgdb *db, - int load_flags, - pkg_func_ptr emitter); -gboolean -db_query_to_job(const gchar *id, - PkBackend *backend, - struct pkgdb *db, - struct pkg_jobs *jobs); #endif /* !_PKGNG_BACKEND_DETAILS_H_ */ Copied and modified: soc2013/mattbw/backend/query.c (from r253789, soc2013/mattbw/backend/iterate.c) ============================================================================== --- soc2013/mattbw/backend/iterate.c Mon Jul 1 09:53:06 2013 (r253789, copy source) +++ soc2013/mattbw/backend/query.c Mon Jul 1 22:13:01 2013 (r253817) @@ -23,7 +23,7 @@ #include "pk-backend.h" #include "pkg.h" -#include "iterate.h" /* Prototypes */ +#include "query.h" /* Prototypes */ #include "db.h" /* open_remote_db */ #include "hash_traverse.h" /* HASH_FOR */ @@ -34,7 +34,23 @@ static gboolean try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const gchar *arch, const gchar *data, gchar **match_id); - +static gboolean +query_split(const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *reponame, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + gchar **match_id_p, + struct pkg **match_pkg_p); +static gboolean +match(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + gchar **match_id_p, + struct pkg **match_pkg_p); gboolean match_id_in_it(struct pkgdb_it *iterator, @@ -203,3 +219,187 @@ return no_error_yet; } + +/* + * Performs a package database query against a PackageID, and then hands the + * matching result to an emitter function. + */ +gboolean +query_emit_match(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + emit_ptr emitter) +{ + gboolean success; + gchar *match_id; + struct pkg *match_pkg; + + success = match(id, backend, db, load_flags, &match_id, &match_pkg); + if (success == TRUE && match_id != NULL && match_pkg != NULL) + emitter(match_pkg, match_id, backend); + + pkg_free(match_pkg); + g_free(match_id); + + return success; +} + +/* + * 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. + */ +gboolean +query_job_match(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + struct pkg_jobs *jobs) +{ + gboolean success; + gchar *match_id; + struct pkg *match_pkg; + + success = match(id, backend, db, PKG_LOAD_BASIC, &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; +} + +/* + * Performs a package database query against a (potentially partial) + * PackageID, retrieving the matched package and its full PackageID. + * + * The exact type of query depends on the repository given. + */ +static gboolean +match(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + gchar **match_id_p, + struct pkg **match_pkg_p) +{ + gboolean query_success; + gboolean split_success; + const gchar *arch; + const gchar *data; + const gchar *name; + const gchar *version; + gchar **strv; + + query_success = FALSE; + split_success = FALSE; + strv = NULL; + + split_success = split_id(id, &strv, &name, &version, &arch, &data); + if (split_success == FALSE) + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_ID_INVALID, + "invalid package id"); + else { + /* + * If the PackageID has a repository specified (even if it's + * "installed" i.e. currently installed package), running + * "get_details_query" directly should handle remote/local + * queries properly. + * + * If there is no repository specified, however (data is NULL), + * we may need to check both the local and (all) remote + * repositories, in that order. (TODO: local packages?) + */ + if (data == NULL) + /* Try local database first. */ + query_success = query_split(name, + version, + arch, + "installed", + backend, + db, + load_flags, + match_id_p, + match_pkg_p); + if (query_success == FALSE) + query_success = query_split(name, version, arch, data, + backend, db, load_flags, 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 (query_success == FALSE) + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_NOT_FOUND, + "package not found"); + g_strfreev(strv); + } + + return query_success; +} + +/* + * Looks the split PackageID up in the package databases. + * + * Usually, a remote query will be done on the repository named by "reponame". + * If reponame is NULL, a remote check will be done against all repostories. + * If it is "installed", a local check will be done. (This is in keeping + * with the special meaning of the "installed" repository in PackageIDs). + */ +static gboolean +query_split(const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *reponame, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + gchar **match_id_p, + struct pkg **match_pkg_p) +{ + struct pkgdb_it *it; + gboolean success; + + success = FALSE; + it = NULL; + + /* Are we doing a local query? */ + /* + * If we got a repository name, then we want to make sure it + * corresponds to a real repository. + */ + if (g_strcmp0(reponame, "installed") == 0) + it = pkgdb_query(db, name, MATCH_EXACT); + else if (pkg_repo_find_ident(reponame) != NULL) + it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); + else + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_NOT_FOUND, + "no such repository"); + + + if (it != NULL) + success = match_id_in_it(it, + backend, + name, + version, + arch, + reponame, + load_flags, + match_id_p, + match_pkg_p); + return success; +} Copied and modified: soc2013/mattbw/backend/query.h (from r253789, soc2013/mattbw/backend/iterate.h) ============================================================================== --- soc2013/mattbw/backend/iterate.h Mon Jul 1 09:53:06 2013 (r253789, copy source) +++ soc2013/mattbw/backend/query.h Mon Jul 1 22:13:01 2013 (r253817) @@ -18,28 +18,29 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef _PKGNG_BACKEND_ITERATE_H_ -#define _PKGNG_BACKEND_ITERATE_H_ +#ifndef _PKGNG_BACKEND_QUERY_H_ +#define _PKGNG_BACKEND_QUERY_H_ #include #include "pk-backend.h" #include "pkg.h" -typedef void (*pkg_func_ptr) (struct pkg *pkg, - const gchar *id, - PkBackend *backend); +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); gboolean -match_id_in_it(struct pkgdb_it *iterator, - PkBackend *backend, - const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *data, - int load_flags, - gchar **match_id_p, - struct pkg **match_pkg_p); +query_emit_match(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + emit_ptr emitter); +gboolean +query_job_match(const gchar *id, + PkBackend *backend, + struct pkgdb *db, + struct pkg_jobs *jobs); gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); -#endif /* !_PKGNG_BACKEND_ITERATE_H_ */ +#endif /* !_PKGNG_BACKEND_QUERY_H_ */