socsvn commit: r255264 - soc2013/mattbw/backend
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Sun Jul 28 13:56:59 UTC 2013
Author: mattbw
Date: Sun Jul 28 13:56:59 2013
New Revision: 255264
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255264
Log:
(untested) Add jobs.c features to add a full batch of PackageIDs to jobs.
This will hopefully replace the jobs-from-query situation shortly, once
the counterpart check-solution-for-PackageID-deficiencies comes along.
Modified:
soc2013/mattbw/backend/jobs.c
soc2013/mattbw/backend/jobs.h
soc2013/mattbw/backend/pkgutils.c
soc2013/mattbw/backend/pkgutils.h
Modified: soc2013/mattbw/backend/jobs.c
==============================================================================
--- soc2013/mattbw/backend/jobs.c Sun Jul 28 12:29:10 2013 (r255263)
+++ soc2013/mattbw/backend/jobs.c Sun Jul 28 13:56:59 2013 (r255264)
@@ -21,6 +21,7 @@
/* Helpers for jobs that don't rely on the query system. */
#include <assert.h> /* assert */
+#include <glib.h> /* gchar, g_... */
#include <stdbool.h> /* bool, true, false */
#include "pk-backend.h" /* pk_..., Pk... */
#include "pkg.h" /* pkg_... */
@@ -30,24 +31,6 @@
#include "pkgutils.h" /* pkgutils_... */
#include "jobs.h" /* jobs_... */
-/* Emits each package queued up in a (solved) job. */
-void
-jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend,
- pkg_info_ptr info)
-{
- struct pkg *pkg;
-
- assert(jobs != NULL);
- assert(backend != NULL);
- assert(info != NULL);
-
- pkg = NULL;
- while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
- assert(pkg != NULL);
- pkgutils_emit(pkg, backend, info(pkg));
- }
-}
-
/* Applies a job with the given error enums and the standard event callback. */
bool
jobs_apply(struct pkg_jobs *jobs, PkBackend *backend,
@@ -71,3 +54,75 @@
return success;
}
+
+/* Adds each PackageID into an already created job. Returns NULL on failure
+ * and a vector of added package name-versions to be freed after solution
+ * on success.
+ */
+char **
+jobs_add_package_ids(struct pkg_jobs *jobs, gchar **package_ids)
+{
+ bool success;
+ char **namevers;
+ guint count;
+ guint i;
+
+ assert(jobs != NULL);
+ assert(package_ids != NULL);
+
+ namevers = NULL;
+ success = false;
+
+ count = g_strv_length(package_ids);
+ if (count == 0)
+ goto cleanup;
+
+ /* Need to convert PackageIDs into name-version pairs. */
+ namevers = calloc(count, sizeof(gchar *));
+ if (namevers == NULL)
+ goto cleanup;
+
+ for (i = 0; i < count; i++) {
+ namevers[i] = pkgutils_package_id_namever(package_ids[i]);
+ if (namevers[i] != NULL)
+ break;
+ }
+
+ /* Make sure we successfully fished out every namever */
+ if (i < count)
+ goto cleanup;
+
+ if (pkg_jobs_add(jobs, MATCH_EXACT, namevers, (int)count) == EPKG_OK)
+ success = true;
+
+cleanup:
+ if (!success) {
+ if (namevers != NULL) {
+ for (i = 0; i < count; i++)
+ free(namevers[i]);
+ free(namevers);
+ }
+ namevers = NULL;
+ }
+
+ return namevers;
+}
+
+/* Emits each package queued up in a (solved) job. */
+void
+jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend,
+ pkg_info_ptr info)
+{
+ struct pkg *pkg;
+
+ assert(jobs != NULL);
+ assert(backend != NULL);
+ assert(info != NULL);
+
+ pkg = NULL;
+ while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
+ assert(pkg != NULL);
+ pkgutils_emit(pkg, backend, info(pkg));
+ }
+}
+
Modified: soc2013/mattbw/backend/jobs.h
==============================================================================
--- soc2013/mattbw/backend/jobs.h Sun Jul 28 12:29:10 2013 (r255263)
+++ soc2013/mattbw/backend/jobs.h Sun Jul 28 13:56:59 2013 (r255264)
@@ -26,7 +26,8 @@
typedef PkInfoEnum (*pkg_info_ptr) (struct pkg *pkg);
-void jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info);
-bool jobs_apply(struct pkg_jobs *jobs, PkBackend *backend, PkErrorEnum no_jobs, PkErrorEnum job_failed);
+bool jobs_apply(struct pkg_jobs *jobs, PkBackend *backend, PkErrorEnum no_jobs, PkErrorEnum job_failed);
+char **jobs_add_package_ids(struct pkg_jobs *jobs, gchar **package_ids);
+void jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info);
#endif /* !_PKGNG_BACKEND_JOBS_H_ */
Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c Sun Jul 28 12:29:10 2013 (r255263)
+++ soc2013/mattbw/backend/pkgutils.c Sun Jul 28 13:56:59 2013 (r255264)
@@ -101,6 +101,31 @@
}
/*
+ * Allocates and returns a string of the form "name-version" that contains
+ * the name and version elements of a PackageID.
+ *
+ * To be freed using free(3).
+ */
+char *
+pkgutils_package_id_namever(gchar *package_id)
+{
+ char *result;
+ gchar **id_splits;
+
+ assert(package_id != NULL);
+
+ id_splits = pk_package_id_split(package_id);
+ assert(id_splits != NULL);
+
+ result = NULL;
+ asprintf(&result, "%s-%s", id_splits[PK_PACKAGE_ID_NAME],
+ id_splits[PK_PACKAGE_ID_VERSION]);
+
+ g_strfreev(id_splits);
+ return result;
+}
+
+/*
* Allocates and returns a string of the form "name-version" that identifies
* the given package's name and version.
*
Modified: soc2013/mattbw/backend/pkgutils.h
==============================================================================
--- soc2013/mattbw/backend/pkgutils.h Sun Jul 28 12:29:10 2013 (r255263)
+++ soc2013/mattbw/backend/pkgutils.h Sun Jul 28 13:56:59 2013 (r255264)
@@ -24,10 +24,11 @@
#include <glib.h>
#include "pk-backend.h"
#include "pkg.h"
-
+
PkInfoEnum pkgutils_pkg_current_state(struct pkg *pkg);
PkInfoEnum pkgutils_pkg_install_state(struct pkg *pkg);
PkInfoEnum pkgutils_pkg_remove_state(struct pkg *pkg);
+char *pkgutils_package_id_namever(gchar *package_id);
char *pkgutils_pkg_namever(struct pkg *pkg);
const char *pkgutils_pk_repo_of(struct pkg *pkg);
gchar *pkgutils_pkg_to_id(struct pkg *pkg);
More information about the svn-soc-all
mailing list