[packagekit] packagekit: Branch 'master' - 5 commits

Richard Hughes hughsient at kemper.freedesktop.org
Mon Oct 15 15:28:49 PDT 2007


 backends/yum/helpers/yumBackend.py |   53 +++++++-
 backends/yum/pk-backend-yum.c      |   11 -
 client/pk-console.c                |    1 
 libgbus/libgbus.c                  |    2 
 libpackagekit/pk-common.c          |    6 
 libpackagekit/pk-package-id.c      |    4 
 libpackagekit/pk-task-common.c     |  235 -------------------------------------
 libpackagekit/pk-task-common.h     |   37 -----
 src/pk-backend.c                   |   31 +++-
 src/pk-engine.c                    |   10 +
 src/pk-spawn.c                     |    4 
 src/pk-transaction-db.c            |   48 +++----
 src/pk-transaction-id.c            |   17 ++
 13 files changed, 132 insertions(+), 327 deletions(-)

New commits:
commit 6f06e1be3645eebfdffe57a5056c1b57687c46d3
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Oct 15 23:20:12 2007 +0100

    use flawfinder to scan for potential security problems

diff --git a/client/pk-console.c b/client/pk-console.c
index 57645f9..6b1495d 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -49,6 +49,7 @@ pk_console_make_space (const gchar *data, guint length, guint *extra)
 	}
 	size = length;
 	if (data != NULL) {
+		/* ITS4: ignore, only used for formatting */
 		size = (length - strlen(data));
 		if (size < 0) {
 			if (extra != NULL) {
diff --git a/libgbus/libgbus.c b/libgbus/libgbus.c
index 6499508..9c29ff2 100644
--- a/libgbus/libgbus.c
+++ b/libgbus/libgbus.c
@@ -70,10 +70,12 @@ name_owner_changed_cb (DBusGProxy     *proxy,
 	}
 
 	if (strcmp (name, libgbus->priv->service) == 0) {
+		/* ITS4: ignore, not used for allocation */
 		if (strlen (prev) != 0 && strlen (new) == 0 && libgbus->priv->connected == TRUE) {
 			g_signal_emit (libgbus, signals [CONNECTION_CHANGED], 0, FALSE);
 			libgbus->priv->connected = FALSE;
 		}
+		/* ITS4: ignore, not used for allocation */
 		if (strlen (prev) == 0 && strlen (new) != 0 && libgbus->priv->connected == FALSE) {
 			g_signal_emit (libgbus, signals [CONNECTION_CHANGED], 0, TRUE);
 			libgbus->priv->connected = TRUE;
diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index f252fe7..e36b427 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -44,6 +44,7 @@ pk_filter_check_part (const gchar *filter)
 	if (filter == NULL) {
 		return FALSE;
 	}
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (filter) == 0) {
 		return FALSE;
 	}
@@ -86,6 +87,7 @@ pk_filter_check (const gchar *filter)
 		pk_warning ("filter null");
 		return FALSE;
 	}
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (filter) == 0) {
 		pk_warning ("filter zero length");
 		return FALSE;
@@ -97,6 +99,7 @@ pk_filter_check (const gchar *filter)
 	ret = FALSE;
 	for (i=0; i<length; i++) {
 		/* only one wrong part is enough to fail the filter */
+		/* ITS4: ignore, not used for allocation */
 		if (strlen (sections[i]) == 0) {
 			goto out;
 		}
@@ -132,8 +135,9 @@ pk_string_id_split (const gchar *id, guint parts)
 		goto out;
 	}
 
-	/* name has to be valid */
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (sections[0]) == 0) {
+		/* name has to be valid */
 		pk_warning ("ident first section is empty");
 		goto out;
 	}
diff --git a/libpackagekit/pk-package-id.c b/libpackagekit/pk-package-id.c
index 9cd339e..8996cd4 100644
--- a/libpackagekit/pk-package-id.c
+++ b/libpackagekit/pk-package-id.c
@@ -77,15 +77,19 @@ pk_package_id_new_from_string (const gchar *package_id)
 
 	/* create new object */
 	ident = pk_package_id_new ();
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (sections[0]) > 0) {
 		ident->name = g_strdup (sections[0]);
 	}
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (sections[1]) > 0) {
 		ident->version = g_strdup (sections[1]);
 	}
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (sections[2]) > 0) {
 		ident->arch = g_strdup (sections[2]);
 	}
+	/* ITS4: ignore, not used for allocation */
 	if (strlen (sections[3]) > 0) {
 		ident->data = g_strdup (sections[3]);
 	}
diff --git a/src/pk-backend.c b/src/pk-backend.c
index d640235..d7eecc0 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -293,9 +293,16 @@ pk_backend_parse_common_output (PkBackend *backend, const gchar *line)
 			goto out;
 		}
 		group = pk_group_enum_from_text (sections[3]);
-		package_size = atol(sections[6]);
-		pk_backend_description (backend, sections[1], sections[2], group, sections[4], sections[5],
-					package_size, sections[7]);
+
+		/* ITS4: ignore, checked for overflow */
+		package_size = atol (sections[6]);
+		if (package_size > 1073741824) {
+			pk_warning ("package size cannot be larger than one Gb");
+		} else {
+			pk_backend_description (backend, sections[1], sections[2],
+						group, sections[4], sections[5],
+						package_size, sections[7]);
+		}
 	} else {
 		pk_warning ("invalid command '%s'", command);
 	}
@@ -339,16 +346,26 @@ pk_backend_parse_common_error (PkBackend *backend, const gchar *line)
 			ret = FALSE;
 			goto out;
 		}
-		percentage = atoi(sections[1]);
-		pk_backend_change_percentage (backend, percentage);
+		/* ITS4: ignore, checked for sanity */
+		percentage = atoi (sections[1]);
+		if (percentage > 100) {
+			pk_warning ("invalid percentage value %i", percentage);
+		} else {
+			pk_backend_change_percentage (backend, percentage);
+		}
 	} else if (strcmp (command, "subpercentage") == 0) {
 		if (size != 2) {
 			g_warning ("invalid command '%s'", command);
 			ret = FALSE;
 			goto out;
 		}
-		percentage = atoi(sections[1]);
-		pk_backend_change_sub_percentage (backend, percentage);
+		/* ITS4: ignore, checked for sanity */
+		percentage = atoi (sections[1]);
+		if (percentage > 100) {
+			pk_warning ("invalid subpercentage value %i", percentage);
+		} else {
+			pk_backend_change_sub_percentage (backend, percentage);
+		}
 	} else if (strcmp (command, "error") == 0) {
 		if (size != 3) {
 			g_warning ("invalid command '%s'", command);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 503b7f3..b69a405 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -561,6 +561,7 @@ pk_engine_finished_cb (PkBackend *backend, PkExitEnum exit, PkEngine *engine)
 
 	/* add to the database */
 	packages = pk_package_list_get_string (item->package_list);
+	/* ITS4: ignore, GString is always NULL terminated */
 	if (strlen (packages) > 0) {
 		pk_transaction_db_set_data (engine->priv->transaction_db, item->tid, packages);
 	}
@@ -986,17 +987,22 @@ pk_engine_get_updates (PkEngine *engine, const gchar *tid, GError **error)
 gboolean
 pk_engine_search_check (const gchar *search, GError **error)
 {
+	guint size;
+
+	/* ITS4: ignore, not used for allocation */
+	size = strlen (search);
+
 	if (search == NULL) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
 			     "Search is null. This isn't supposed to happen...");
 		return FALSE;
 	}
-	if (strlen (search) == 0) {
+	if (size == 0) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
 			     "Search string zero length");
 		return FALSE;
 	}
-	if (strlen (search) < 2) {
+	if (size < 2) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_SEARCH_INVALID,
 			     "The search string length is too small");
 		return FALSE;
diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index 503d779..dcb0fcb 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -82,7 +82,7 @@ pk_spawn_read_fd_into_buffer (gint fd, GString *string)
 	gint bytes_read;
 	gchar buffer[1024];
 
-	/* read as much as we can */
+	/* read as much as we can, TODO: should probably use g_io_channel */
 	while ((bytes_read = read (fd, buffer, 1023)) > 0) {
 		buffer[bytes_read] = '\0';
 		g_string_append (string, buffer);
@@ -103,6 +103,7 @@ pk_spawn_emit_whole_lines (PkSpawn *spawn, GString *string, gboolean is_stdout)
 	gchar *message;
 	guint bytes_processed;
 
+	/* ITS4: ignore, GString is always NULL terminated */
 	if (strlen (string->str) == 0) {
 		return FALSE;
 	}
@@ -128,6 +129,7 @@ pk_spawn_emit_whole_lines (PkSpawn *spawn, GString *string, gboolean is_stdout)
 			g_signal_emit (spawn, signals [PK_SPAWN_STDERR], 0, message);
 		}
 		g_free (message);
+		/* ITS4: ignore, g_strsplit always NULL terminates */
 		bytes_processed += strlen (lines[i]) + 1;
 	}
 
diff --git a/src/pk-transaction-db.c b/src/pk-transaction-db.c
index e493ff2..d033c0a 100644
--- a/src/pk-transaction-db.c
+++ b/src/pk-transaction-db.c
@@ -118,7 +118,12 @@ pk_transaction_sqlite_callback (void *data, gint argc, gchar **argv, gchar **col
 		col = col_name[i];
 		value = argv[i];
 		if (strcmp (col, "succeeded") == 0) {
+			/* ITS4: ignore, checked for sanity */
 			item.succeeded = atoi (value);
+			if (item.succeeded > 1) {
+				pk_warning ("item.succeeded %i! Resetting to 1", item.succeeded);
+				item.succeeded = 1;
+			}
 		} else if (strcmp (col, "role") == 0) {
 			if (value != NULL) {
 				item.role = pk_role_enum_from_text (value);
@@ -137,7 +142,12 @@ pk_transaction_sqlite_callback (void *data, gint argc, gchar **argv, gchar **col
 			}
 		} else if (strcmp (col, "duration") == 0) {
 			if (value != NULL) {
+				/* ITS4: ignore, checked for sanity */
 				item.duration = atoi (value);
+				if (item.duration > 60*60*12) {
+					pk_warning ("insane duartion %i", item.duration);
+					item.duration = 0;
+				}
 			}
 		} else {
 			pk_warning ("%s = %s\n", col, value);
diff --git a/src/pk-transaction-id.c b/src/pk-transaction-id.c
index e869313..876f985 100644
--- a/src/pk-transaction-id.c
+++ b/src/pk-transaction-id.c
@@ -70,7 +70,16 @@ pk_transaction_id_load_job_count (void)
 		pk_warning ("failed to get last job");
 		return FALSE;
 	}
+
+	/* ITS4: ignore, not used for allocation */
 	job_count = atoi (contents);
+
+	/* check we got a sane number */
+	if (job_count > 10240) {
+		pk_warning ("invalid job count!");
+		job_count = 0;
+	}
+
 	pk_debug ("job=%i", job_count);
 	g_free (contents);
 	return job_count;
@@ -111,23 +120,23 @@ pk_transaction_id_equal (const gchar *tid1, const gchar *tid2)
 gchar *
 pk_transaction_id_generate (void)
 {
-	gchar *random;
+	gchar *rand_str;
 	gchar *job;
 	gchar *tid;
 	guint job_count;
 
 	/* load from file */
 	job_count = pk_transaction_id_load_job_count ();
-	random = pk_transaction_id_get_random_hex_string (8);
+	rand_str = pk_transaction_id_get_random_hex_string (8);
 	job = g_strdup_printf ("%i", job_count++);
 
 	/* save the new value */
 	pk_transaction_id_save_job_count (job_count);
 
 	/* make the tid */
-	tid = g_strjoin (";", job, random, "data", NULL);
+	tid = g_strjoin (";", job, rand_str, "data", NULL);
 
-	g_free (random);
+	g_free (rand_str);
 	g_free (job);
 	return tid;
 }
commit 0a26464bfe3b87f6c8ac574b19bbde884d5daa48
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Oct 15 23:10:48 2007 +0100

    remove unused files

diff --git a/libpackagekit/pk-task-common.c b/libpackagekit/pk-task-common.c
deleted file mode 100644
index 352e309..0000000
--- a/libpackagekit/pk-task-common.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <string.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-
-#include "pk-debug.h"
-#include "pk-task-common.h"
-
-/**
- * pk_task_filter_check_part:
- **/
-gboolean
-pk_task_filter_check_part (const gchar *filter)
-{
-	if (filter == NULL) {
-		return FALSE;
-	}
-	if (strlen (filter) == 0) {
-		return FALSE;
-	}
-	if (strcmp (filter, "none") == 0) {
-		return TRUE;
-	}
-	if (strcmp (filter, "installed") == 0) {
-		return TRUE;
-	}
-	if (strcmp (filter, "~installed") == 0) {
-		return TRUE;
-	}
-	if (strcmp (filter, "devel") == 0) {
-		return TRUE;
-	}
-	if (strcmp (filter, "~devel") == 0) {
-		return TRUE;
-	}
-	if (strcmp (filter, "gui") == 0) {
-		return TRUE;
-	}
-	if (strcmp (filter, "~gui") == 0) {
-		return TRUE;
-	}
-	return FALSE;
-}
-
-/**
- * pk_task_filter_check:
- **/
-gboolean
-pk_task_filter_check (const gchar *filter)
-{
-	gchar **sections;
-	guint i;
-	guint length;
-	gboolean ret;
-
-	if (filter == NULL) {
-		pk_warning ("filter null");
-		return FALSE;
-	}
-	if (strlen (filter) == 0) {
-		pk_warning ("filter zero length");
-		return FALSE;
-	}
-
-	/* split by delimeter ';' */
-	sections = g_strsplit (filter, ";", 0);
-	length = g_strv_length (sections);
-	ret = FALSE;
-	for (i=0; i<length; i++) {
-		/* only one wrong part is enough to fail the filter */
-		if (strlen (sections[i]) == 0) {
-			goto out;
-		}
-		if (pk_task_filter_check_part (sections[i]) == FALSE) {
-			goto out;
-		}
-	}
-	ret = TRUE;
-out:
-	g_strfreev (sections);
-	return ret;
-}
-
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef PK_BUILD_TESTS
-#include <libselftest.h>
-
-void
-libst_task_common (LibSelfTest *test)
-{
-	gboolean ret;
-	gchar *text;
-	const gchar *temp;
-
-	if (libst_start (test, "PkTaskCommon", CLASS_AUTO) == FALSE) {
-		return;
-	}
-
-	/************************************************************
-	 ****************          FILTERS         ******************
-	 ************************************************************/
-	temp = NULL;
-	libst_title (test, "test a fail filter (null)");
-	ret = pk_task_filter_check (temp);
-	if (ret == FALSE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "passed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "";
-	libst_title (test, "test a fail filter ()");
-	ret = pk_task_filter_check (temp);
-	if (ret == FALSE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "passed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = ";";
-	libst_title (test, "test a fail filter (;)");
-	ret = pk_task_filter_check (temp);
-	if (ret == FALSE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "passed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "moo";
-	libst_title (test, "test a fail filter (invalid)");
-	ret = pk_task_filter_check (temp);
-	if (ret == FALSE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "passed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "moo;foo";
-	libst_title (test, "test a fail filter (invalid, multiple)");
-	ret = pk_task_filter_check (temp);
-	if (ret == FALSE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "passed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "gui;;";
-	libst_title (test, "test a fail filter (valid then zero length)");
-	ret = pk_task_filter_check (temp);
-	if (ret == FALSE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "passed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "none";
-	libst_title (test, "test a pass filter (none)");
-	ret = pk_task_filter_check (temp);
-	if (ret == TRUE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "failed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "gui";
-	libst_title (test, "test a pass filter (single)");
-	ret = pk_task_filter_check (temp);
-	if (ret == TRUE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "failed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "devel;~gui";
-	libst_title (test, "test a pass filter (multiple)");
-	ret = pk_task_filter_check (temp);
-	if (ret == TRUE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "failed the filter '%s'", temp);
-	}
-
-	/************************************************************/
-	temp = "~gui;~installed";
-	libst_title (test, "test a pass filter (multiple2)");
-	ret = pk_task_filter_check (temp);
-	if (ret == TRUE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "failed the filter '%s'", temp);
-	}
-
-	libst_end (test);
-}
-#endif
-
diff --git a/libpackagekit/pk-task-common.h b/libpackagekit/pk-task-common.h
deleted file mode 100644
index b4b6c51..0000000
--- a/libpackagekit/pk-task-common.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __PK_TASK_H
-#define __PK_TASK_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define	PK_DBUS_SERVICE			"org.freedesktop.PackageKit"
-#define	PK_DBUS_PATH			"/org/freedesktop/PackageKit"
-#define	PK_DBUS_INTERFACE		"org.freedesktop.PackageKit"
-
-gboolean	 pk_task_filter_check			(const gchar	*filter);
-
-G_END_DECLS
-
-#endif /* __PK_TASK_H */
commit a21a5b52c83ba304a95bb97813dd52d576dcbbe5
Merge: 13d47fa... 39e3424...
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Mon Oct 15 17:08:13 2007 -0400

    Merge branch 'master' of git+ssh://rnorwood@git.packagekit.org/srv/git/PackageKit

commit 13d47faa736bbb361cd10392c62ecf7ee61a876d
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Mon Oct 15 17:08:04 2007 -0400

    - Remove the no_percentage_updates and allow_interrupt signals from
      pk-backend-yum.c and put them in yumBackend.py instead.
    - Also audit calls in yumBackend.py to make sure they all set
      allow_interrupt and either set no_percentage_updates, or do
      percentages.

diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index e09fcf6..59406d2 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -129,6 +129,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-name functionality
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+
         searchlist = ['name']
         self._do_search(searchlist, filters, key)
 
@@ -136,6 +139,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-details functionality
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+
         searchlist = ['name', 'summary', 'description', 'group']
         self._do_search(searchlist, filters, key)
 
@@ -143,12 +149,18 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-group functionality
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+        
         self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
 
     def search_file(self,filters,key):
         '''
         Implement the {backend}-search-file functionality
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+        
         self._setup_yum()
         #self.yumbase.conf.cache = 1 # Only look in cache.
         fltlist = filters.split(';')
@@ -213,6 +225,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a list of requires for a given package
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+
         self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend")
 
     def _is_inst(self,pkg):
@@ -295,6 +310,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a list of depends for a given package
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+
         self._setup_yum()
         name = package.split(';')[0]
         pkg,inst = self._findPackage(package)
@@ -319,8 +337,10 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-update-system functionality
         '''
-        self._setup_yum()
+        self.allow_interrupt(False)
         self.percentage(0)
+
+        self._setup_yum()
         txmbr = self.yumbase.update() # Add all updates to Transaction
         if txmbr:
             self._runYumTransaction()
@@ -331,9 +351,11 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-refresh_cache functionality
         '''
+        self.allow_interrupt(True);
+        self.percentage(0)
+
         self._setup_yum()
         pct = 0
-        self.percentage(pct)
         try:
             if len(self.yumbase.repos.listEnabled()) == 0:
                 self.percentage(100)
@@ -361,6 +383,11 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-resolve functionality
         '''
+        self.allow_interrupt(True);
+        self.percentage(None)
+
+        # !!! Shouldn't we self._setup_yum() here?
+
         # Get installed packages
         installedByKey = self.yumbase.rpmdb.searchNevra(name=name)
         for pkg in installedByKey:
@@ -381,8 +408,10 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-install functionality
         This will only work with yum 3.2.4 or higher
         '''
-        self._setup_yum()
+        self.allow_interrupt(False)
         self.percentage(0)
+    
+        self._setup_yum()
         pkg,inst = self._findPackage(package)
         if pkg:
             if inst:
@@ -403,6 +432,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Install the package containing the inst_file file
         Needed to be implemented in a sub class
         '''
+        self.allow_interrupt(False);
+        self.percentage(0)
+
         pkgs_to_inst = []
         self._setup_yum()
         # Check if the inst_file is already installed
@@ -442,8 +474,10 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-install functionality
         This will only work with yum 3.2.4 or higher
         '''
-        self._setup_yum()
+        self.allow_interrupt(False);
         self.percentage(0)
+
+        self._setup_yum()
         pkg,inst = self._findPackage(package)
         if pkg:
             txmbr = self.yumbase.update(name=pkg.name)
@@ -518,8 +552,10 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-remove functionality
         Needed to be implemented in a sub class
         '''
-        self._setup_yum()
+        self.allow_interrupt(False);
         self.percentage(0)
+
+        self._setup_yum()
         pkg,inst = self._findPackage( package)
         if pkg and inst:
             txmbr = self.yumbase.remove(name=pkg.name)
@@ -538,6 +574,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a detailed description for a given package
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+
         self._setup_yum()
         pkg,inst = self._findPackage(package)
         if pkg:
@@ -576,6 +615,9 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-updates functionality
         '''
+        self.allow_interrupt(True)
+        self.percentage(None)
+
         self._setup_yum()
         md = UpdateMetadata()
         # Added extra Update Metadata
@@ -585,7 +627,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
             except:
                 pass # No updateinfo.xml.gz in repo
 
-        self.percentage() # emit no-percentage-updates signal
         ygl = self.yumbase.doPackageLists(pkgnarrow='updates')
         for pkg in ygl.updates:
             # Get info about package in updates info
diff --git a/backends/yum/pk-backend-yum.c b/backends/yum/pk-backend-yum.c
index b42044a..cbbeeff 100644
--- a/backends/yum/pk-backend-yum.c
+++ b/backends/yum/pk-backend-yum.c
@@ -70,7 +70,6 @@ static void
 backend_get_depends (PkBackend *backend, const gchar *package_id)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
 	pk_backend_spawn_helper (backend, "get-depends.py", package_id, NULL);
 }
 
@@ -81,7 +80,6 @@ static void
 backend_get_description (PkBackend *backend, const gchar *package_id)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
 	pk_backend_spawn_helper (backend, "get-description.py", package_id, NULL);
 }
 
@@ -92,7 +90,6 @@ static void
 backend_get_requires (PkBackend *backend, const gchar *package_id)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
 	pk_backend_spawn_helper (backend, "get-requires.py", package_id, NULL);
 }
 
@@ -103,7 +100,6 @@ static void
 backend_get_updates (PkBackend *backend)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_no_percentage_updates (backend);
 	pk_backend_spawn_helper (backend, "get-updates.py", NULL);
 }
 
@@ -162,8 +158,6 @@ static void
 backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_no_percentage_updates (backend);
 	pk_backend_spawn_helper (backend, "search-details.py", filter, search, NULL);
 }
 
@@ -174,8 +168,6 @@ static void
 backend_search_file (PkBackend *backend, const gchar *filter, const gchar *search)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_no_percentage_updates (backend);
 	pk_backend_spawn_helper (backend, "search-file.py", filter, search, NULL);
 }
 
@@ -187,7 +179,6 @@ static void
 backend_search_group (PkBackend *backend, const gchar *filter, const gchar *search)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
 	pk_backend_spawn_helper (backend, "search-group.py", filter, search, NULL);
 }
 #endif
@@ -199,8 +190,6 @@ static void
 backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_allow_interrupt (backend, TRUE);
-	pk_backend_no_percentage_updates (backend);
 	pk_backend_spawn_helper (backend, "search-name.py", filter, search, NULL);
 }
 
commit 39e342442b6bc5c5555f435ed81dc243926175b7
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Oct 15 20:57:23 2007 +0100

    make sure we do sqlite3_open before we try to create the db

diff --git a/src/pk-transaction-db.c b/src/pk-transaction-db.c
index 4f76fdc..e493ff2 100644
--- a/src/pk-transaction-db.c
+++ b/src/pk-transaction-db.c
@@ -326,24 +326,6 @@ pk_transaction_db_class_init (PkTransactionDbClass *klass)
 }
 
 /**
- * pk_transaction_db_create:
- **/
-static void
-pk_transaction_db_create (PkTransactionDb *tdb)
-{
-	const gchar *statement;
-	statement = "CREATE TABLE transactions ("
-		    "transaction_id TEXT primary key,"
-		    "timespec TEXT,"
-		    "duration INTEGER,"
-		    "succeeded INTEGER DEFAULT 0,"
-		    "role TEXT,"
-		    "data TEXT,"
-		    "description TEXT);";
-	sqlite3_exec (tdb->priv->db, statement, NULL, 0, NULL);
-}
-
-/**
  * pk_transaction_db_empty:
  **/
 gboolean
@@ -365,7 +347,8 @@ pk_transaction_db_empty (PkTransactionDb *tdb)
 static void
 pk_transaction_db_init (PkTransactionDb *tdb)
 {
-	gboolean ret;
+	gboolean create_file;
+	const gchar *statement;
 	gint rc;
 
 	g_return_if_fail (tdb != NULL);
@@ -374,10 +357,7 @@ pk_transaction_db_init (PkTransactionDb *tdb)
 	tdb->priv = PK_TRANSACTION_DB_GET_PRIVATE (tdb);
 
 	/* if the database file was not installed (or was nuked) recreate it */
-	ret = g_file_test (PK_TRANSACTION_DB_FILE, G_FILE_TEST_EXISTS);
-	if (ret == FALSE) {
-		pk_transaction_db_create (tdb);
-	}
+	create_file = g_file_test (PK_TRANSACTION_DB_FILE, G_FILE_TEST_EXISTS);
 
 	pk_debug ("trying to open database '%s'", PK_TRANSACTION_DB_FILE);
 	rc = sqlite3_open (PK_TRANSACTION_DB_FILE, &tdb->priv->db);
@@ -385,6 +365,18 @@ pk_transaction_db_init (PkTransactionDb *tdb)
 		pk_warning ("Can't open database: %s\n", sqlite3_errmsg (tdb->priv->db));
 		sqlite3_close (tdb->priv->db);
 		return;
+	} else {
+		if (create_file == FALSE) {
+			statement = "CREATE TABLE transactions ("
+				    "transaction_id TEXT primary key,"
+				    "timespec TEXT,"
+				    "duration INTEGER,"
+				    "succeeded INTEGER DEFAULT 0,"
+				    "role TEXT,"
+				    "data TEXT,"
+				    "description TEXT);";
+			sqlite3_exec (tdb->priv->db, statement, NULL, 0, NULL);
+		}
 	}
 }
 


More information about the PackageKit mailing list