socsvn commit: r254743 - soc2013/mattbw/backend/actions
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Sat Jul 13 07:47:43 UTC 2013
Author: mattbw
Date: Sat Jul 13 07:47:42 2013
New Revision: 254743
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254743
Log:
how did these not get added previously
Added:
soc2013/mattbw/backend/actions/remove_packages.c
soc2013/mattbw/backend/actions/search_groups.c
soc2013/mattbw/backend/actions/search_names.c
Added: soc2013/mattbw/backend/actions/remove_packages.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/actions/remove_packages.c Sat Jul 13 07:47:42 2013 (r254743)
@@ -0,0 +1,157 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <glib.h> /* gboolean */
+#include <stdbool.h> /* bool, true, false */
+#include "../pk-backend.h" /* pk..., Pk... */
+#include "pkg.h" /* pkg... */
+
+#include "../actions.h" /* remove_packages_thread prototype */
+#include "../event.c" /* event_... */
+#include "../pkgutils.h" /* pkgutils_... */
+#include "../query.h" /* query_... */
+#include "../utils.h" /* INTENTIONALLY_IGNORE, ERR */
+
+static bool job (struct pkg_jobs *jobs, struct query *q);
+static bool sim_job(struct pkg_jobs *jobs, struct query *q);
+static bool solve_job(struct query *q, struct pkg_jobs *jobs);
+
+/*
+ * The thread that performs an removePackages operation. Should be invoked
+ * by the pk_backend_remove_packages hook.
+ */
+gboolean
+remove_packages_thread(PkBackend *backend)
+{
+ bool success;
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ success = query_match_id_to_job(backend, PKG_JOBS_remove, job);
+
+ (void)pk_backend_finished(backend);
+ return success ? TRUE : FALSE;
+}
+
+/*
+ * The thread that performs a Simulate removePackages operation. Should be
+ * invoked by the pk_backend_simulate_remove_packages hook.
+ */
+gboolean
+simulate_remove_packages_thread(PkBackend *backend)
+{
+ bool success;
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ success = query_match_id_to_job(backend, PKG_JOBS_remove, sim_job);
+
+ (void)pk_backend_finished(backend);
+ return success ? TRUE : FALSE;
+}
+
+/*
+ * Tries to process the given solved removeation jobs.
+ */
+static bool
+job(struct pkg_jobs *jobs, struct query *q)
+{
+ bool success;
+ PkBackend *backend;
+
+ success = false;
+ backend = query_backend(q);
+ query_set_percentage(q, 0);
+
+ if (solve_job(q, jobs) == false)
+ goto cleanup;
+
+ pkg_event_register(event_cb, backend);
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_REMOVE);
+ if (pkg_jobs_apply(jobs) != EPKG_OK) {
+ ERR(backend,
+ PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE,
+ "job failed");
+ goto cleanup;
+ }
+ success = true;
+
+cleanup:
+ pkg_event_register(NULL, NULL);
+ query_set_percentage(q, 100);
+ return success;
+}
+
+/*
+ * Tries to simulate processing the given removal jobs.
+ */
+static bool
+sim_job(struct pkg_jobs *jobs, struct query *q)
+{
+ bool success;
+ PkBackend *backend;
+ struct pkg *pkg;
+
+ backend = query_backend(q);
+ success = false;
+ query_set_percentage(q, 0);
+
+ if (solve_job(q, jobs) == false)
+ goto cleanup;
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
+ pkg = NULL;
+ while (pkg_jobs(jobs, &pkg) == EPKG_OK)
+ pkgutils_emit(pkg,
+ backend,
+ pkgutils_pkg_remove_state(pkg));
+
+ success = true;
+
+cleanup:
+ query_set_percentage(q, 100);
+ return success;
+}
+
+/*
+ * Solves a job and ensures it has packages available.
+ */
+static bool
+solve_job(struct query *q, struct pkg_jobs *jobs)
+{
+ bool success;
+ PkBackend *backend;
+
+ success = false;
+ backend = query_backend(q);
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_DEP_RESOLVE);
+ if (pkg_jobs_solve(jobs) != EPKG_OK)
+ ERR(backend,
+ PK_ERROR_ENUM_DEP_RESOLUTION_FAILED,
+ "could not solve the job");
+ else if (pkg_jobs_count(jobs) == 0)
+ ERR(backend,
+ PK_ERROR_ENUM_INTERNAL_ERROR,
+ "job contains no packages");
+ else
+ success = true;
+
+ return success;
+}
Added: soc2013/mattbw/backend/actions/search_groups.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/actions/search_groups.c Sat Jul 13 07:47:42 2013 (r254743)
@@ -0,0 +1,99 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "../pk-backend.h"
+#include "pkg.h"
+
+#include "../actions.h" /* search_groups_thread prototype */
+#include "../db.h" /* db_open_remote */
+#include "../group.h" /* group_... */
+#include "../search.h" /* search_... */
+#include "../utils.h" /* INTENTIONALLY_IGNORE */
+
+/*
+ * Searches for a package by group.
+ */
+gboolean
+search_groups_thread(PkBackend *backend)
+{
+ gboolean success;
+ guint groupc;
+ guint i;
+ PkGroupEnum *groupv;
+ struct pkgdb_it *it;
+ gchar **values;
+ struct search search;
+
+ search.db = NULL;
+ groupv = NULL;
+ it = NULL;
+ search.term = NULL;
+ success = FALSE;
+ values = NULL;
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ (void)pk_backend_set_percentage(backend, 0);
+
+ search.db = db_open_remote(backend);
+ if (search.db == NULL)
+ goto cleanup;
+
+ values = pk_backend_get_strv(backend, "values");
+ groupc = g_strv_length(values);
+ if (groupc == 0) {
+ ERR(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "no values");
+ goto cleanup;
+ }
+
+ groupv = calloc(groupc, sizeof(PkGroupEnum));
+ if (groupv == NULL) {
+ ERR(backend, PK_ERROR_ENUM_OOM, "couldn't alloc groupv");
+ goto cleanup;
+ }
+
+ for (i = 0; i < groupc; i++) {
+ groupv[i] = pk_group_enum_from_string(values[i]);
+ if (groupv[i] == PK_GROUP_ENUM_UNKNOWN)
+ ERR(backend, PK_ERROR_ENUM_GROUP_NOT_FOUND, values[i]);
+ }
+
+ search.term = group_list_to_origin_regex(groupc, groupv);
+ if (search.term == NULL || search.term[0] == '\0') {
+ ERR(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "no search.term");
+ goto cleanup;
+ }
+
+ search.type = MATCH_REGEX;
+ search.in = FIELD_ORIGIN;
+ search.sort_by = FIELD_ORIGIN;
+ search.backend = backend;
+ search.filters = pk_backend_get_uint(backend, "filters");
+
+ success = search_do(&search);
+
+cleanup:
+ free(search.term);
+ free(groupv);
+ pkgdb_close(search.db);
+
+ (void)pk_backend_set_percentage(backend, 100);
+ (void)pk_backend_finished(backend);
+ return success;
+}
Added: soc2013/mattbw/backend/actions/search_names.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/actions/search_names.c Sat Jul 13 07:47:42 2013 (r254743)
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "../pk-backend.h"
+#include "pkg.h"
+
+#include "../actions.h" /* search_names_thread prototype */
+#include "../db.h" /* db_open_remote */
+#include "../search.h" /* search_... */
+#include "../utils.h" /* INTENTIONALLY_IGNORE */
+
+/*
+ * Searches for one or more packages by name.
+ */
+gboolean
+search_names_thread(PkBackend *backend)
+{
+ gboolean success;
+ struct search search;
+
+ success = FALSE;
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ (void)pk_backend_set_percentage(backend, 0);
+
+ /* TODO: check search type */
+ search.type = MATCH_REGEX;
+ search.in = FIELD_NAME;
+ search.sort_by = FIELD_NAME;
+ search.filters = pk_backend_get_uint(backend, "filters");
+ search.term = NULL;
+ search.db = NULL;
+ search.backend = backend;
+
+ search.db = db_open_remote(backend);
+ if (search.db != NULL) {
+ guint i;
+ guint len;
+ gchar **values;
+
+ values = pk_backend_get_strv(backend, "values");
+ len = g_strv_length(values);
+
+ success = TRUE;
+ for (i = 0; i < len && success; i++) {
+ search.term = values[i];
+ success = search_do(&search);
+ (void)pk_backend_set_percentage(backend,
+ ((i + 1) * 100) / len);
+ }
+ }
+
+ pkgdb_close(search.db);
+ (void)pk_backend_set_percentage(backend, 100);
+ (void)pk_backend_finished(backend);
+ return success;
+}
More information about the svn-soc-all
mailing list