Date: Mon, 29 Jul 2013 18:02:29 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255308 - soc2013/mattbw/backend Message-ID: <201307291802.r6TI2TkB037125@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Mon Jul 29 18:02:29 2013 New Revision: 255308 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255308 Log: Quick-fixed a logical error in the new jobs handling. I forgot that jobs need to be set up to use a specific repository, and that as PackageIDs have individual repositories specified then one cannot just send all the PackageIDs to the default repository. For now, the old behaviour of one job per PackageID has been quickly pencilled back in. A possible workaround would be to sort through the PackageIDs and sift them into separate repository piles with one job for each, but this will take some implementing and would complicate the backend code. Modified: soc2013/mattbw/backend/jobs.c Modified: soc2013/mattbw/backend/jobs.c ============================================================================== --- soc2013/mattbw/backend/jobs.c Mon Jul 29 17:03:42 2013 (r255307) +++ soc2013/mattbw/backend/jobs.c Mon Jul 29 18:02:29 2013 (r255308) @@ -33,6 +33,7 @@ #include "jobs.h" /* jobs_... */ #include "pkgutils.h" /* pkgutils_... */ +static bool jobs_do_repo(struct pkgdb *db, const struct jobs_spec *spec, gchar **idv, unsigned int idc, const char *reponame); static void free_namevers(char ***namev_p, unsigned int namec); /* Applies a job with the given error enums and the standard event callback. */ @@ -126,7 +127,8 @@ } if (success && reject_non_updates && - pkgutils_pkg_install_state(pkg) != PK_INFO_ENUM_UPDATING) + pkgutils_pkg_install_state(pkg) != + PK_INFO_ENUM_UPDATING) success = false; } } @@ -149,18 +151,18 @@ { bool success; unsigned int count; - gchar **package_ids; + unsigned int i; + char *repo; struct pkgdb *db; - struct pkg_jobs *jobs; - char **namevers; + gchar **package_ids; + gchar **splits; + assert(spec != NULL); assert(spec->backend != NULL); assert(spec->info != NULL); success = false; - namevers = NULL; - jobs = NULL; package_ids = NULL; if (spec->use_package_ids) @@ -174,20 +176,77 @@ if (db == NULL) goto cleanup; - /* UpdateSystem is a job with no packages, so there's no need to use - * the full query approach. + /* + * HACK ALERT + * + * We'd ideally like to do one job for all PackageIDs but, because + * there could be more than one repo being used (as each PackageID has + * its own repo), we need to do one job per PackageID. + * TODO: consider bundling PackageIDs up into separate jobs per repo? */ + if (package_ids == NULL) + success = jobs_do_repo(db, spec, NULL, 0, ""); + else { + + for (i = 0, success = true; i < count && success; i++) { + /* Nastily inefficient */ + splits = pk_package_id_split(package_ids[i]); + if (splits == NULL) + repo = strdup(""); + else + repo = strdup(splits[PK_PACKAGE_ID_DATA]); + g_strfreev(splits); + + success = jobs_do_repo(db, spec, package_ids + i, + 1, repo); + free(repo); + } + } + +cleanup: + pkgdb_close(db); + + return success; +} + +/* + * Performs a job on a certain batch of PackageIDs, each with the same repo. + * count can be 0, in which case no PackageIDs are used. + */ +bool +jobs_do_repo(struct pkgdb *db, const struct jobs_spec *spec, gchar **idv, + unsigned int idc, const char *reponame) +{ + bool success; + struct pkg_jobs *jobs; + char **namevers; + + assert(db != NULL); + assert(spec != NULL); + assert(idv == NULL || idc > 0); + assert(idv != NULL || idc == 0); + + success = NULL; + namevers = NULL; jobs = NULL; + if (pkg_jobs_new(&jobs, spec->type, db) != EPKG_OK) { ERR(spec->backend, PK_ERROR_ENUM_INTERNAL_ERROR, "could not init pkg_jobs"); goto cleanup; } - if (package_ids != NULL) { + if (reponame != NULL && + (pkg_jobs_set_repository(jobs, reponame) != EPKG_OK)) { + ERR(spec->backend, + PK_ERROR_ENUM_REPO_NOT_FOUND, + "could not set repo"); + goto cleanup; + } + if (idv != NULL) { STATUS(spec->backend, PK_STATUS_ENUM_DEP_RESOLVE); - namevers = jobs_add_package_ids(jobs, package_ids); + namevers = jobs_add_package_ids(jobs, idv); if (namevers == NULL) { ERR(spec->backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, @@ -201,8 +260,8 @@ "could not solve the job"); goto cleanup; } - if (package_ids != NULL && - (jobs_check_package_ids(jobs, package_ids, + if (idv != NULL && + (jobs_check_package_ids(jobs, idv, spec->reject_non_updates) == false)) { ERR(spec->backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, @@ -222,8 +281,7 @@ cleanup: pkg_jobs_free(jobs); - pkgdb_close(db); - free_namevers(&namevers, count); + free_namevers(&namevers, idc); return success; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307291802.r6TI2TkB037125>