socsvn commit: r253779 - in soc2013/mattbw/backend: . actions
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Mon Jul 1 08:30:30 UTC 2013
Author: mattbw
Date: Mon Jul 1 08:30:29 2013
New Revision: 253779
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253779
Log:
(broken) start making way for InstallPackages
Added:
soc2013/mattbw/backend/actions/install-packages.c
Modified:
soc2013/mattbw/backend/db.c
soc2013/mattbw/backend/pk-backend-pkgng.c
Added: soc2013/mattbw/backend/actions/install-packages.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/actions/install-packages.c Mon Jul 1 08:30:29 2013 (r253779)
@@ -0,0 +1,81 @@
+/*-
+ * 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>
+#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 "../licenses.h" /* license_from_pkg */
+
+#include "get-details.h" /* get_details_thread prototype */
+
+static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend);
+static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db);
+
+/*
+ * The thread that performs an InstallPackages operation. Should be invoked by
+ * the pk_backend_install_packages hook.
+ */
+gboolean
+install_packages_thread(PkBackend *backend)
+{
+ return iterate_ids(backend, get_for);
+}
+
+/*
+ * Look up and attempt to install the given PackageID, if it can be found.
+ */
+static gboolean
+get_for(const gchar *id, PkBackend *backend, struct pkgdb *db)
+{
+ struct pkg_jobs *jobs;
+ db_query_to_job(id, backend, db, LOAD_FLAGS, emit_pkg);
+}
+
+/*
+ * Emits the given package's details. To be used as an iterating function.
+ */
+static void
+emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend)
+{
+
+ const char *description;
+ const char *origin;
+ const char *www;
+ int64_t flatsize;
+
+ /* Information not already part of the PackageID */
+ pkg_get(pkg,
+ PKG_DESC, &description,
+ PKG_FLATSIZE, &flatsize,
+ PKG_ORIGIN, &origin,
+ PKG_WWW, &www);
+
+ pk_backend_details(backend,
+ id,
+ license_name_from_pkg(pkg),
+ group_from_origin(origin),
+ description,
+ www,
+ flatsize);
+}
Modified: soc2013/mattbw/backend/db.c
==============================================================================
--- soc2013/mattbw/backend/db.c Mon Jul 1 07:07:35 2013 (r253778)
+++ soc2013/mattbw/backend/db.c Mon Jul 1 08:30:29 2013 (r253779)
@@ -36,7 +36,16 @@
PkBackend *backend,
struct pkgdb *db,
int load_flags,
- pkg_func_ptr emitter);
+ 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,
+ pkg_func_ptr emitter,
+ gchar **match_id_p,
+ struct pkg **match_pkg_p);
/*
* Opens a pkgdb ready for remote operations. This will always return TRUE if
@@ -80,13 +89,9 @@
return success;
}
-
-
/*
* Performs a package database query against a PackageID, and then hands the
* matching results to an emitter function.
- *
- * The exact type of query depends on the repository given.
*/
gboolean
db_query_with_id(const gchar *id,
@@ -95,6 +100,76 @@
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(pkg, match_id, backend);
+
+ pkg_free(pkg);
+ g_free(match_id);
+}
+
+/*
+ * 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.
+ */
+gboolean
+db_query_to_job(const gchar *id,
+ PkBackend *backend,
+ struct pkgdb *db,
+ int load_flags,
+ struct pkg_jobs *jobs)
+{
+ 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) {
+ gchar *name[1];
+
+ name[0] = NULL;
+ pkg_get(PKG_NAME, &(name[0]));
+
+ pkg_jobs_add(jobs, MATCH_EXACT, name, 1);
+ }
+
+ pkg_free(pkg);
+ g_free(match_id);
+}
+
+/*
+ * 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,
+ pkg_func_ptr emitter,
+ gchar **match_id_p,
+ struct pkg **match_pkg_p)
+{
gboolean query_success;
gboolean split_success;
const gchar *arch;
@@ -132,10 +207,12 @@
backend,
db,
load_flags,
- emitter);
+ match_id_p,
+ match_pkg_p);
if (query_success == FALSE)
query_success = db_query_split(name, version, arch, data,
- backend, db, load_flags, emitter);
+ 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.
Modified: soc2013/mattbw/backend/pk-backend-pkgng.c
==============================================================================
--- soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jul 1 07:07:35 2013 (r253778)
+++ soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jul 1 08:30:29 2013 (r253779)
@@ -1,5 +1,4 @@
/*-
- *
* Copyright (C) 2007-2010 Richard Hughes <richard at hughsie.com>
* 2013 Matt Windsor <mattbw at FreeBSD.org>
*
@@ -33,7 +32,7 @@
#include "groups.h" /* available_groups */
#include "actions/get-files.h" /* get_files_thread */
#include "actions/get-details.h"/* get_details_thread */
-#include "actions/get-repo-list.h"/* get_repo_list_thread */
+#include "actions/get-repo-list.h" /* get_repo_list_thread */
#define INTENTIONALLY_IGNORE(x) (void)(x)
@@ -121,38 +120,11 @@
return g_strdup("application/x-rpm;application/x-deb");
}
-/**
- * pk_backend_cancel_timeout:
- */
-static gboolean
-pk_backend_cancel_timeout(gpointer data)
-{
- PkBackend *backend = (PkBackend *)data;
-
- /* we can now cancel again */
- _signal_timeout = 0;
-
- /* now mark as finished */
- pk_backend_error_code(backend, PK_ERROR_ENUM_TRANSACTION_CANCELLED,
- "The task was stopped successfully");
- pk_backend_finished(backend);
- return FALSE;
-}
-
-/**
- * pk_backend_cancel:
+/*
+ * To implement:
+ *
+ * - pk_backend_cancel
*/
-void
-pk_backend_cancel(PkBackend *backend)
-{
- /* cancel the timeout */
- if (_signal_timeout != 0) {
- g_source_remove(_signal_timeout);
-
- /* emulate that it takes us a few ms to cancel */
- g_timeout_add(1500, pk_backend_cancel_timeout, backend);
- }
-}
/**
* pk_backend_get_depends:
@@ -177,8 +149,6 @@
pk_backend_finished(backend);
}
-
-
/*
* Spawns a thread to get the details of the package IDs requested. The
* thread code proper is in "get-details.c".
@@ -432,74 +402,13 @@
void
pk_backend_install_packages(PkBackend *backend, gboolean only_trusted, gchar **package_ids)
{
- const gchar *license_agreement;
- const gchar *eula_id;
- gboolean has_eula;
+ INTENTIONALLY_IGNORE(only_trusted);
- /* FIXME: support only_trusted */
+ pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID);
- if (g_strcmp0(package_ids[0], "vips-doc;7.12.4-2.fc8;noarch;linva") == 0) {
- if (_use_gpg && !_has_signature) {
- pk_backend_repo_signature_required(backend, package_ids[0], "updates",
- "http://example.com/gpgkey",
- "Test Key (Fedora) fedora at example.com",
- "BB7576AC",
- "D8CC 06C2 77EC 9C53 372F C199 B1EE 1799 F24F 1B08",
- "2007-10-04", PK_SIGTYPE_ENUM_GPG);
- pk_backend_error_code(backend, PK_ERROR_ENUM_GPG_FAILURE,
- "GPG signed package could not be verified");
- pk_backend_finished(backend);
- return;
- }
- eula_id = "eula_hughsie_dot_com";
- has_eula = pk_backend_is_eula_valid(backend, eula_id);
- if (_use_eula && !has_eula) {
- license_agreement = "Narrator: In A.D. 2101, war was beginning.\n"
- "Captain: What happen ?\n"
- "Mechanic: Somebody set up us the bomb.\n\n"
- "Operator: We get signal.\n"
- "Captain: What !\n"
- "Operator: Main screen turn on.\n"
- "Captain: It's you !!\n"
- "CATS: How are you gentlemen !!\n"
- "CATS: All your base are belong to us.\n"
- "CATS: You are on the way to destruction.\n\n"
- "Captain: What you say !!\n"
- "CATS: You have no chance to survive make your time.\n"
- "CATS: Ha Ha Ha Ha ....\n\n"
- "Operator: Captain!! *\n"
- "Captain: Take off every 'ZIG' !!\n"
- "Captain: You know what you doing.\n"
- "Captain: Move 'ZIG'.\n"
- "Captain: For great justice.\n";
- pk_backend_eula_required(backend, eula_id, package_ids[0],
- "CATS Inc.", license_agreement);
- pk_backend_error_code(backend, PK_ERROR_ENUM_NO_LICENSE_AGREEMENT,
- "licence not installed so cannot install");
- pk_backend_finished(backend);
- return;
- }
- if (_use_media) {
- _use_media = FALSE;
- pk_backend_media_change_required(backend, PK_MEDIA_TYPE_ENUM_DVD, "linux-disk-1of7", "Linux Disc 1 of 7");
- pk_backend_error_code(backend, PK_ERROR_ENUM_MEDIA_CHANGE_REQUIRED,
- "additional media linux-disk-1of7 required");
- pk_backend_finished(backend);
- return;
- }
- }
- if (_use_trusted && only_trusted) {
- pk_backend_error_code(backend, PK_ERROR_ENUM_CANNOT_INSTALL_REPO_UNSIGNED,
- "Can't install as untrusted");
- pk_backend_finished(backend);
- return;
- }
- pk_backend_set_allow_cancel(backend, TRUE);
- _progress_percentage = 0;
- pk_backend_package(backend, PK_INFO_ENUM_DOWNLOADING,
- "gtkhtml2;2.19.1-4.fc8;i386;fedora",
- "An HTML widget for GTK+ 2.0");
- _signal_timeout = g_timeout_add(100, pk_backend_install_timeout, backend);
+ pk_backend_thread_create(backend, get_repo_list_thread);
+ pk_backend_finished(backend);
}
/**
@@ -841,8 +750,8 @@
pk_backend_message(backend, PK_MESSAGE_ENUM_BROKEN_MIRROR, "fedora-updates-testing-source metadata is invalid");
pk_backend_set_sub_percentage(backend, 100);
pk_backend_package(backend, PK_INFO_ENUM_INSTALLING,
- "gtkhtml2;2.19.1-4.fc8;i386;fedora",
- "An HTML widget for GTK+ 2.0");
+ "gtkhtml2;2.19.1-4.fc8;i386;fedora",
+ "An HTML widget for GTK+ 2.0");
_updated_gtkhtml = TRUE;
pk_backend_set_sub_percentage(backend, 0);
}
@@ -973,8 +882,8 @@
pk_backend_message(backend, PK_MESSAGE_ENUM_BROKEN_MIRROR, "fedora-updates-testing-debuginfo metadata is invalid");
pk_backend_message(backend, PK_MESSAGE_ENUM_BROKEN_MIRROR, "fedora-updates-testing-source metadata is invalid");
pk_backend_package(backend, PK_INFO_ENUM_INSTALLING,
- "gtkhtml2;2.19.1-4.fc8;i386;fedora",
- "An HTML widget for GTK+ 2.0");
+ "gtkhtml2;2.19.1-4.fc8;i386;fedora",
+ "An HTML widget for GTK+ 2.0");
_updated_gtkhtml = TRUE;
}
if (_progress_percentage == 40 && !_updated_powertop) {
@@ -1160,9 +1069,7 @@
}
/*
- * Not supported:
- * - pk_backend_repo_enable
- * - pk_backend_repo_set_data
+ * Not supported: - pk_backend_repo_enable - pk_backend_repo_set_data
*/
/**
More information about the svn-soc-all
mailing list