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

Richard Hughes hughsient at kemper.freedesktop.org
Mon Sep 10 11:07:25 PDT 2007


 backends/alpm/pk-backend-alpm.c        |  207 +++----
 backends/apt/pk-backend-apt.cpp        |   60 +-
 backends/apt/pk-task-apt.cpp.delete.me |  939 ---------------------------------
 python/packagekit.py                   |   28 
 src/pk-engine.c                        |   51 -
 src/pk-engine.h                        |    1 
 src/pk-job-list.c                      |   29 +
 src/pk-job-list.h                      |    2 
 8 files changed, 228 insertions(+), 1089 deletions(-)

New commits:
diff-tree 96e23e778e31752611d5cc99d6e5c957f12b737e (from ca3f2f7b0636a9bff3557f5d1c39611dc951f3ae)
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Sep 10 19:06:03 2007 +0100

    re-enable the check for duplicate system updates after abstracting it in a nice way

diff --git a/src/pk-engine.c b/src/pk-engine.c
index e1bb191..b3c77d7 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -112,6 +112,7 @@ pk_engine_error_get_type (void)
 			ENUM_ENTRY (PK_ENGINE_ERROR_DENIED, "PermissionDenied"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_NOT_SUPPORTED, "NotSupported"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_NO_SUCH_JOB, "NoSuchJob"),
+			ENUM_ENTRY (PK_ENGINE_ERROR_JOB_EXISTS_WITH_ROLE, "JobExistsWithRole"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_REFUSED_BY_POLICY, "RefusedByPolicy"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_PACKAGE_ID_INVALID, "PackageIdInvalid"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_SEARCH_INVALID, "SearchInvalid"),
@@ -539,7 +540,7 @@ pk_engine_refresh_cache (PkEngine *engin
 	ret = pk_backend_refresh_cache (task, force);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -572,7 +573,7 @@ pk_engine_get_updates (PkEngine *engine,
 	ret = pk_backend_get_updates (task);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -670,7 +671,7 @@ pk_engine_search_name (PkEngine *engine,
 	ret = pk_backend_search_name (task, filter, search);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -716,7 +717,7 @@ pk_engine_search_details (PkEngine *engi
 	ret = pk_backend_search_details (task, filter, search);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -762,7 +763,7 @@ pk_engine_search_group (PkEngine *engine
 	ret = pk_backend_search_group (task, filter, search);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -808,7 +809,7 @@ pk_engine_search_file (PkEngine *engine,
 	ret = pk_backend_search_file (task, filter, search);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -850,7 +851,7 @@ pk_engine_get_depends (PkEngine *engine,
 	ret = pk_backend_get_depends (task, package_id);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -892,7 +893,7 @@ pk_engine_get_requires (PkEngine *engine
 	ret = pk_backend_get_requires (task, package_id);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -926,7 +927,7 @@ pk_engine_get_description (PkEngine *eng
 	ret = pk_backend_get_description (task, package_id);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		g_object_unref (task);
 		return FALSE;
 	}
@@ -963,30 +964,20 @@ pk_engine_update_system (PkEngine *engin
 		return;
 	}
 
-#if 0
-	guint i;
-	guint length;
-	PkRoleEnum role;
-	/* check for existing job doing an update */
-	length = engine->priv->array->len;
-	for (i=0; i<length; i++) {
-		item = (PkJobListItem *) g_ptr_array_index (engine->priv->array, i);
-		ret = pk_backend_get_job_role (item->task, &role, NULL);
-		if (ret == TRUE && role == PK_ROLE_ENUM_SYSTEM_UPDATE) {
-			error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_DENIED,
-					     "operation not yet supported by backend");
-			dbus_g_method_return_error (context, error);
-			return;
-		}
+	/* are we already performing an update? */
+	if (pk_job_list_role_present (engine->priv->job_list, PK_ROLE_ENUM_SYSTEM_UPDATE) == TRUE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_JOB_EXISTS_WITH_ROLE,
+				     "Already performing system update");
+		dbus_g_method_return_error (context, error);
+		return;
 	}
-#endif
 
 	/* create a new task and start it */
 	task = pk_engine_new_task (engine);
 	ret = pk_backend_update_system (task);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-				     "operation not yet supported by backend");
+				     "Operation not yet supported by backend");
 		g_object_unref (task);
 		dbus_g_method_return_error (context, error);
 		return;
@@ -1037,7 +1028,7 @@ pk_engine_remove_package (PkEngine *engi
 	ret = pk_backend_remove_package (task, package_id, allow_deps);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-				     "operation not yet supported by backend");
+				     "Operation not yet supported by backend");
 		g_object_unref (task);
 		dbus_g_method_return_error (context, error);
 		return;
@@ -1090,7 +1081,7 @@ pk_engine_install_package (PkEngine *eng
 	ret = pk_backend_install_package (task, package_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-				     "operation not yet supported by backend");
+				     "Operation not yet supported by backend");
 		g_object_unref (task);
 		dbus_g_method_return_error (context, error);
 		return;
@@ -1143,7 +1134,7 @@ pk_engine_update_package (PkEngine *engi
 	ret = pk_backend_update_package (task, package_id);
 	if (ret == FALSE) {
 		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-				     "operation not yet supported by backend");
+				     "Operation not yet supported by backend");
 		g_object_unref (task);
 		dbus_g_method_return_error (context, error);
 		return;
@@ -1307,7 +1298,7 @@ pk_engine_cancel_job_try (PkEngine *engi
 	ret = pk_backend_cancel_job_try (item->task);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
-			     "operation not yet supported by backend");
+			     "Operation not yet supported by backend");
 		return FALSE;
 	}
 
diff --git a/src/pk-engine.h b/src/pk-engine.h
index 3906db8..10fb6b9 100644
--- a/src/pk-engine.h
+++ b/src/pk-engine.h
@@ -58,6 +58,7 @@ typedef enum
 	PK_ENGINE_ERROR_DENIED,
 	PK_ENGINE_ERROR_NOT_SUPPORTED,
 	PK_ENGINE_ERROR_NO_SUCH_JOB,
+	PK_ENGINE_ERROR_JOB_EXISTS_WITH_ROLE,
 	PK_ENGINE_ERROR_REFUSED_BY_POLICY,
 	PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
 	PK_ENGINE_ERROR_SEARCH_INVALID,
diff --git a/src/pk-job-list.c b/src/pk-job-list.c
index e790669..e4ad202 100644
--- a/src/pk-job-list.c
+++ b/src/pk-job-list.c
@@ -100,6 +100,35 @@ pk_job_list_save_job_count (PkJobList *j
 }
 
 /**
+ * pk_job_list_role_present:
+ *
+ * if there is a queued job with this role, useful to avoid having
+ * multiple system updates queued
+ **/
+gboolean
+pk_job_list_role_present (PkJobList *job_list, PkRoleEnum role)
+{
+	guint i;
+	guint length;
+	PkRoleEnum role_temp;
+	PkJobListItem *item;
+
+	g_return_val_if_fail (job_list != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_JOB_LIST (job_list), FALSE);
+
+	/* check for existing job doing an update */
+	length = job_list->priv->array->len;
+	for (i=0; i<length; i++) {
+		item = (PkJobListItem *) g_ptr_array_index (job_list->priv->array, i);
+		pk_backend_get_job_role (item->task, &role_temp, NULL);
+		if (role_temp == role) {
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+/**
  * pk_job_list_add:
  **/
  /* create transaction_id, add to array, mark changed */
diff --git a/src/pk-job-list.h b/src/pk-job-list.h
index d930fed..576a0b0 100644
--- a/src/pk-job-list.h
+++ b/src/pk-job-list.h
@@ -64,6 +64,8 @@ gboolean	 pk_job_list_remove			(PkJobLis
 							 PkTask		*task);
 gboolean	 pk_job_list_commit			(PkJobList	*job_list,
 							 PkTask		*task);
+gboolean	 pk_job_list_role_present		(PkJobList	*job_list,
+							 PkRoleEnum	 role);
 GArray		*pk_job_list_get_array			(PkJobList	*job_list);
 guint		 pk_job_list_get_size			(PkJobList	*job_list);
 PkJobListItem	*pk_job_list_get_item_from_job		(PkJobList	*job_list,
diff-tree ca3f2f7b0636a9bff3557f5d1c39611dc951f3ae (from parents)
Merge: 12399e6b53694892bab85e8521a1ba8bedfb1dd1 1a4dde9039f4b4c2a64ceb8f5b622a32ce73e1c3
Author: Andreas Obergrusberger <tradiaz at yahoo.de>
Date:   Mon Sep 10 16:45:33 2007 +0200

    Merge branch 'master' of ssh://tradiaz@hughsient.no-ip.org/srv/git/PackageKit

diff-tree 1a4dde9039f4b4c2a64ceb8f5b622a32ce73e1c3 (from 2e3c6757ebbc0f06d491cc793295fa8fae0e59e9)
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Sep 10 14:34:50 2007 +0200

    Actually remove old apt backend

diff --git a/backends/apt/pk-task-apt.cpp.delete.me b/backends/apt/pk-task-apt.cpp.delete.me
deleted file mode 100644
index 898c765..0000000
--- a/backends/apt/pk-task-apt.cpp.delete.me
+++ /dev/null
@@ -1,939 +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.
- */
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!                                                         !!!!!!!!!
-//!!!!!   Do not edit this file! Edit backends/$backend         !!!!!!!!!
-//!!!!!                                                         !!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-#include <apt-pkg/pkgcachegen.h>
-#include <apt-pkg/pkgcache.h>
-#include <apt-pkg/cachefile.h>
-#include <apt-pkg/progress.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/init.h>
-#include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/acquire.h>
-#include <apt-pkg/acquire-item.h>
-
-#include <regex.h>
-#include <string.h>
-#include <math.h>
-
-#include "pk-debug.h"
-#include "pk-task.h"
-#include "pk-task-common.h"
-#include "config.h"
-#include "pk-network.h"
-#include "pk-package-id.h"
-
-static void pk_task_class_init(PkTaskClass * klass);
-static void pk_task_init(PkTask * task);
-static void pk_task_finalize(GObject * object);
-
-#define PK_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TASK, PkTaskPrivate))
-
-struct PkTaskPrivate
-{
-	guint progress_percentage;
-	PkNetwork *network;
-};
-
-static guint signals[PK_TASK_LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE(PkTask, pk_task, G_TYPE_OBJECT)
-
-static pkgCacheFile *fileCache = NULL;
-pkgSourceList *SrcList = 0;
-
-static pkgCacheFile *getCache()
-{
-	if (fileCache == NULL)
-	{
-		MMap *Map = 0;
-		OpTextProgress Prog;
-		if (pkgInitConfig(*_config) == false)
-			pk_debug("pkginitconfig was false");
-		if (pkgInitSystem(*_config, _system) == false)
-			pk_debug("pkginitsystem was false");
-		// Open the cache file
-		SrcList = new pkgSourceList;
-		SrcList->ReadMainList();
-
-		// Generate it and map it
-		pkgMakeStatusCache(*SrcList, Prog, &Map, true);
-
-		fileCache = new pkgCacheFile();
-
-		if (fileCache->Open(Prog, FALSE) == FALSE)
-		{
-			pk_debug("I need more privelges");
-			fileCache->Close();
-			fileCache = NULL;
-		}
-		else
-			pk_debug("cache inited");
-	}
-	return fileCache;
-}
-
-
-/**
- * pk_task_get_actions
- **/
-gchar *
-pk_task_get_actions (void)
-{
-	gchar *actions;
-	actions = pk_action_enum_build (PK_ACTION_ENUM_REFRESH_CACHE,
-				        PK_ACTION_ENUM_UPDATE_SYSTEM,
-				        PK_ACTION_ENUM_SEARCH_NAME,
-				        PK_ACTION_ENUM_SEARCH_DETAILS,
-				        PK_ACTION_ENUM_GET_DESCRIPTION,
-				        0);
-	return actions;
-}
-
-/**
- * pk_task_get_updates:
- **/
-gboolean pk_task_get_updates(PkTask * task)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
- 	pk_task_not_implemented_yet(task, "GetUpdates");
-	return FALSE;
-}
-
-typedef struct
-{
-	PkTask *task;
-} UpdateData;
-
-class UpdatePercentage:public pkgAcquireStatus
-{
-	double old;
-	PkTask *task;
-
-	public:
-	UpdatePercentage(PkTask *tk)
-	{
-		old = -1;
-		task = tk;
-	}
-	
-	virtual bool MediaChange(string Media,string Drive)
-	{
-		pk_debug("PANIC!: we don't handle mediachange");
-		return FALSE;
-	}
-	
-	virtual bool Pulse(pkgAcquire *Owner)
-	{
-		pkgAcquireStatus::Pulse(Owner);
-		double percent = double(CurrentBytes*100.0)/double(TotalBytes);
-		if (old!=percent)
-		{
-			pk_task_change_percentage(task,(guint)percent);
-			pk_task_change_sub_percentage(task,((guint)(percent*100.0))%100);
-			old = percent;
-		}
-		return true;	
-	}
-};
-
-// DoUpdate - Update the package lists 
-// Swiped from apt-get's update mode
-void *DoUpdate(gpointer data)
-{
-	UpdateData *ud = (UpdateData*)data;
-	pkgCacheFile *Cache;
-	bool Failed = false;
-	bool TransientNetworkFailure = false;
-	OpTextProgress Prog;
-	
-	/* easy as that */
-	pk_task_change_job_status(ud->task, PK_STATUS_ENUM_REFRESH_CACHE);
-
-	Cache = getCache();
-
-	// Get the source list
-	pkgSourceList List;
-	if (List.ReadMainList() == false)
-	{
-		pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Failure reading lists");
-		pk_task_finished(ud->task, PK_EXIT_ENUM_FAILED);
-		return NULL;
-	}
-
-	// Lock the list directory
-	FileFd Lock;
-	if (_config->FindB("Debug::NoLocking", false) == false)
-	{
-		Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
-		if (_error->PendingError() == true)
-		{
-			_error->DumpErrors();
-			pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Unable to lock the list directory");
-			pk_task_finished(ud->task, PK_EXIT_ENUM_FAILED);
-			return NULL;
-		}
-	}
-
-	// Create the download object
-	UpdatePercentage *Stat = new UpdatePercentage(ud->task);
-	pkgAcquire Fetcher(Stat);
-
-	// Populate it with the source selection
-	if (List.GetIndexes(&Fetcher) == false)
-	{
-		pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Generic Error");
-		goto do_update_clean;
-	}
-
-	// Run it
-	if (Fetcher.Run() == pkgAcquire::Failed)
-	{
-		pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Generic Error");
-		goto do_update_clean;
-	}
-
-	for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
-	{
-		if ((*I)->Status == pkgAcquire::Item::StatDone)
-			continue;
-
-		(*I)->Finished();
-
-		fprintf(stderr, "Failed to fetch %s  %s\n", (*I)->DescURI().c_str(), (*I)->ErrorText.c_str());
-
-		if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
-		{
-			TransientNetworkFailure = true;
-			continue;
-		}
-
-		Failed = true;
-	}
-
-	// Clean out any old list files
-	if (!TransientNetworkFailure && _config->FindB("APT::Get::List-Cleanup", true) == true)
-	{
-		if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
-		{
-			pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Generic Error");
-			goto do_update_clean;
-		}
-	}
-
-	// Prepare the cache.   
-	Cache = getCache();
-	if (Cache->BuildCaches(Prog,false) == false)
-	{
-		pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Generic Error");
-		goto do_update_clean;
-	}
-
-	if (TransientNetworkFailure == true)
-		pk_debug("Some index files failed to download, they have been ignored, or old ones used instead.");
-	else if (Failed == true)
-	{
-		pk_task_error_code(ud->task, PK_ERROR_ENUM_UNKNOWN, "Generic Error");
-		goto do_update_clean;
-	}
-
-	delete Stat;
-	pk_task_finished(ud->task, PK_EXIT_ENUM_SUCCESS);
-	return NULL;
-
-	do_update_clean:
-	delete Stat;
-	pk_task_finished(ud->task, PK_EXIT_ENUM_FAILED);
-	return NULL;
-}
-
-/**
- * pk_task_refresh_cache:
- **/
-gboolean pk_task_refresh_cache(PkTask * task, gboolean force)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
-	/* check network state */
-	if (pk_network_is_online(task->priv->network) == FALSE)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		return TRUE;
-	}
-
-	UpdateData *data = g_new(UpdateData, 1);
-	if (data == NULL)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_UNKNOWN, "can't allocate memory for update task");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-	}
-	else
-	{
-		data->task = task;
-		if (g_thread_create(DoUpdate,data, false, NULL) == NULL)
-		{
-			pk_task_error_code(task, PK_ERROR_ENUM_UNKNOWN, "can't spawn update thread");
-			pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		}
-	}
-	return TRUE;
-}
-
-/**
- * pk_task_update_system:
- **/
-gboolean pk_task_update_system(PkTask * task)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
-	/* not implimented yet */
-	return FALSE;
-}
-
-#ifdef APT_PKG_RPM
-typedef pkgCache::VerFile AptCompFile;
-#elif defined(APT_PKG_DEB)
-typedef pkgCache::DescFile AptCompFile;
-#else
-#error Need either rpm or deb defined
-#endif
-
-struct ExDescFile
-{
-	AptCompFile *Df;
-	const char *verstr;
-	const char *arch;
-	gboolean installed;
-	gboolean available;
-	char *repo;
-	bool NameMatch;
-};
-
-// LocalitySort - Sort a version list by package file locality		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static int LocalityCompare(const void *a, const void *b)
-{
-	pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
-	pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
-
-	if (A == 0 && B == 0)
-		return 0;
-	if (A == 0)
-		return 1;
-	if (B == 0)
-		return -1;
-
-	if (A->File == B->File)
-		return A->Offset - B->Offset;
-	return A->File - B->File;
-}
-
-static void LocalitySort(AptCompFile **begin,
-		  unsigned long Count,size_t Size)
-{
-	qsort(begin,Count,Size,LocalityCompare);
-}
-
-typedef enum {SEARCH_NAME=1, SEARCH_DETAILS, SEARCH_FILE} SearchDepth;
-
-struct search_task
-{
-	PkTask *task;
-	gchar *search;
-	gchar *filter;
-	SearchDepth depth;
-};
-
-static gboolean buildExDesc(ExDescFile *DFList, unsigned int pid, pkgCache::VerIterator V)
-{
-	// Find the proper version to use. 
-	DFList[pid].available = false;
-	if (V.end() == false)
-	{
-	#ifdef APT_PKG_RPM
-		DFList[pid].Df = V.FileList();
-	#else	
-		DFList[pid].Df = V.DescriptionList().FileList();
-	#endif
-		DFList[pid].verstr = V.VerStr();
-		DFList[pid].arch = V.Arch();
-		for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
-		{
-			// Locate the associated index files so we can derive a description
-			pkgIndexFile *Indx;
-			bool hasLocal = _system->FindIndex(VF.File(),Indx);
-			if (SrcList->FindIndex(VF.File(),Indx) == false && !hasLocal)
-			{
-			   pk_debug("Cache is out of sync, can't x-ref a package file");
-			   break;
-			}
-			gchar** items = g_strsplit_set(Indx->Describe(true).c_str()," \t",-1);
-			DFList[pid].repo = g_strdup(items[1]); // should be in format like "http://ftp.nl.debian.org unstable/main Packages"
-			DFList[pid].installed = hasLocal;
-			g_strfreev(items);
-			DFList[pid].available = true;
-			if (hasLocal)
-				break;
-		}	 
-	}
-	return DFList[pid].available;
-}
-
-// do_search_task
-// Swiped from apt-cache's search mode
-static void *do_search_task(gpointer data)
-{
-	search_task *st = (search_task *) data;
-	ExDescFile *DFList = NULL;
-
-	pk_task_change_job_status(st->task, PK_STATUS_ENUM_QUERY);
-	pk_task_no_percentage_updates(st->task);
-
-	pk_debug("finding %s", st->search);
-	pkgCache & pkgCache = *(getCache());
-	pkgDepCache::Policy Plcy;
-	// Create the text record parser
-	pkgRecords Recs(pkgCache);
-
-	// Compile the regex pattern
-	regex_t *Pattern = new regex_t;
-	memset(Pattern, 0, sizeof(*Pattern));
-	if (regcomp(Pattern, st->search, REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
-	{
-		pk_task_error_code(st->task, PK_ERROR_ENUM_UNKNOWN, "regex compilation error");
-		pk_task_finished(st->task, PK_EXIT_ENUM_FAILED);
-		goto search_task_cleanup;
-	}
-
-	DFList = new ExDescFile[pkgCache.HeaderP->PackageCount + 1];
-	memset(DFList, 0, sizeof(*DFList) * pkgCache.HeaderP->PackageCount + 1);
-
-	// Map versions that we want to write out onto the VerList array.
-	for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
-	{
-		DFList[P->ID].NameMatch = true;
-		if (regexec(Pattern, P.Name(), 0, 0, 0) == 0)
-			DFList[P->ID].NameMatch &= true;
-		else
-			DFList[P->ID].NameMatch = false;
-
-		// Doing names only, drop any that dont match..
-		if (st->depth == SEARCH_NAME && DFList[P->ID].NameMatch == false)
-			continue;
-
-		// Find the proper version to use. 
-		pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
-		buildExDesc(DFList, P->ID, V);
-	}
-
-	// Include all the packages that provide matching names too
-	for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
-	{
-		if (DFList[P->ID].NameMatch == false)
-			continue;
-
-		for (pkgCache::PrvIterator Prv = P.ProvidesList(); Prv.end() == false; Prv++)
-		{
-			pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
-			if (buildExDesc(DFList, Prv.OwnerPkg()->ID, V))
-				DFList[Prv.OwnerPkg()->ID].NameMatch = true;
-		}
-	}
-
-	LocalitySort(&DFList->Df, pkgCache.HeaderP->PackageCount, sizeof(*DFList));
-
-	// Iterate over all the version records and check them
-	for (ExDescFile * J = DFList; J->Df != 0; J++)
-	{
-#ifdef APT_PKG_RPM
-		pkgRecords::Parser & P = Recs.Lookup(pkgCache::VerFileIterator(pkgCache, J->Df));
-#else
-		pkgRecords::Parser & P = Recs.Lookup(pkgCache::DescFileIterator(pkgCache, J->Df));
-#endif
-
-		gboolean Match = true;
-		if (J->NameMatch == false)
-		{
-			string LongDesc = P.LongDesc();
-			if (regexec(Pattern, LongDesc.c_str(), 0, 0, 0) == 0)
-				Match = true;
-			else
-				Match = false;
-		}
-
-		if (Match == true)// && pk_task_filter_package_name(st->task,P.Name().c_str()))
-		{
-			gchar *pid = pk_package_id_build(P.Name().c_str(),J->verstr,J->arch,J->repo);
-			pk_task_package(st->task, J->installed, pid, P.ShortDesc().c_str());
-			g_free(pid);
-		}
-	}
-
-	pk_task_finished(st->task, PK_EXIT_ENUM_SUCCESS);
-
-  search_task_cleanup:
-	for (ExDescFile * J = DFList; J->Df != 0; J++)
-	{
-		g_free(J->repo);
-	}
-	delete[]DFList;
-	regfree(Pattern);
-	g_free(st->search);
-	g_free(st);
-
-	return NULL;
-}
-
-/**
- * pk_task_search
- **/
-static gboolean
-pk_task_search(PkTask * task, const gchar * filter, const gchar * search, SearchDepth which)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
-	if (pk_task_filter_check(filter) == FALSE)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_FILTER_INVALID, "filter '%s' not valid", filter);
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		return TRUE;
-	}
-
-	search_task *data = g_new(struct search_task, 1);
-	if (data == NULL)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_UNKNOWN, "can't allocate memory for search task");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-	}
-	else
-	{
-		data->task = task;
-		data->search = g_strdup(search);
-		data->filter = g_strdup(filter);
-		data->depth = which;
-
-		if (g_thread_create(do_search_task, data, false, NULL) == NULL)
-		{
-			pk_task_error_code(task, PK_ERROR_ENUM_UNKNOWN, "can't spawn thread");
-			pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		}
-	}
-	return TRUE;
-}
-
-/**
- * pk_task_search_details:
- **/
-gboolean pk_task_search_details(PkTask * task, const gchar * filter, const gchar * search)
-{
-	return pk_task_search(task, filter, search, SEARCH_DETAILS);
-}
-
-/**
- * pk_task_search_name:
- **/
-gboolean pk_task_search_name(PkTask * task, const gchar * filter, const gchar * search)
-{
-	return pk_task_search(task, filter, search, SEARCH_NAME);
-}
-
-/**
- * pk_task_search_group:
- **/
-gboolean pk_task_search_group(PkTask * task, const gchar * filter, const gchar * search)
-{
-	pk_task_not_implemented_yet(task, "SearchGroup");
-	return TRUE;
-}
-
-void *do_search_file(gpointer data)
-{
-	search_task *st = (search_task*)data;
-	gchar *sdir = g_path_get_dirname(_config->Find("Dir::State::status").c_str());
-	gchar *ldir = g_build_filename(sdir,"info",NULL);
-	g_free(sdir);
-	GError *error = NULL;
-	GDir *list = g_dir_open(ldir,0,&error);
-	if (error!=NULL)
-	{
-		pk_task_error_code(st->task, PK_ERROR_ENUM_INTERNAL_ERROR, "can't open %s",ldir);
-		g_free(ldir);
-		g_error_free(error);
-		pk_task_finished(st->task, PK_EXIT_ENUM_FAILED);
-		return NULL;
-	}
-	const gchar * fname = NULL;
-	while ((fname = g_dir_read_name(list))!=NULL)
-	{
-		//pk_task_package(st->task, J->installed, pid, P.ShortDesc().c_str());
-	}
-	pk_task_error_code(st->task, PK_ERROR_ENUM_INTERNAL_ERROR, "search file is incomplete");
-	pk_task_finished(st->task, PK_EXIT_ENUM_FAILED);
-	g_dir_close(ldir);
-	g_free(ldir);
-	//pk_task_finished(st->task, PK_EXIT_ENUM_SUCCESS);
-	return NULL;
-}
-
-/**
- * pk_task_search_file:
- **/
-gboolean pk_task_search_file(PkTask * task, const gchar * filter, const gchar * search)
-{
-	search_task *data = g_new(struct search_task, 1);
-	if (data == NULL)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_UNKNOWN, "can't allocate memory for search task");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-	}
-	else
-	{
-		data->task = task;
-		data->search = g_strdup(search);
-		data->filter = g_strdup(filter);
-		data->depth = SEARCH_FILE;
-
-		if (g_thread_create(do_search_file, data, false, NULL) == NULL)
-		{
-			pk_task_error_code(task, PK_ERROR_ENUM_INTERNAL_ERROR, "can't spawn thread");
-			pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		}
-	}
-	return TRUE;
-}
-
-/**
- * pk_task_get_depends:
- **/
-gboolean pk_task_get_depends(PkTask * task, const gchar * package)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
- 	pk_task_not_implemented_yet (task, "GetDepends");
-	return FALSE;
-}
-/**
- * pk_task_get_requires:
- **/
-gboolean pk_task_get_requires(PkTask * task, const gchar * package)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
- 	pk_task_not_implemented_yet (task, "GetRequires");
-	return FALSE;
-}
-
-struct desc_task
-{
-	PkTask *task;
-	PkPackageId *pi;
-};
-
-static GHashTable *PackageRecord(pkgCache::VerIterator V)
-{
-	GHashTable *ret = NULL;
-	
-	pkgCache & pkgCache = *(getCache());
-	// Find an appropriate file
-	pkgCache::VerFileIterator Vf = V.FileList();
-	for (; Vf.end() == false; Vf++)
-	{
-		if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
-			break;
-		if (Vf.end() == true)
-			Vf = V.FileList();
-	}
-		
-	// Check and load the package list file
-	pkgCache::PkgFileIterator I = Vf.File();
-	if (I.IsOk() == false)
-		return NULL;
-	
-	FileFd PkgF(I.FileName(),FileFd::ReadOnly);
-	if (_error->PendingError() == true)
-		return NULL;
-	
-	// Read the record
-	char *Buffer = new char[pkgCache.HeaderP->MaxVerFileSize+1];
-	Buffer[V.FileList()->Size] = '\0';
-	if (PkgF.Seek(V.FileList()->Offset) == false ||
-		 PkgF.Read(Buffer,V.FileList()->Size) == false)
-	{
-		delete [] Buffer;
-		return NULL;
-	}
-	//pk_debug("buffer: '%s'\n",Buffer);
-	ret = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
-	gchar ** lines = g_strsplit(Buffer,"\n",-1);
-	guint i;
-	for (i=0;i<g_strv_length(lines);i++)
-	{
-		gchar ** parts = g_strsplit_set(lines[i],": ",2);
-		if (g_strv_length(parts)>1)
-		{
-			//pk_debug("entry =  '%s' : '%s'",parts[0],parts[1]);
-			if (parts[0][0]=='\0')
-			{
-				gchar *oldval = g_strdup((const gchar*)g_hash_table_lookup(ret,"Description"));
-				g_hash_table_insert(ret,g_strdup("Description"),g_strconcat(oldval, "\n",parts[1],NULL));
-				//pk_debug("new entry =  '%s'",(const gchar*)g_hash_table_lookup(ret,"Description"));
-				g_free(oldval);
-			}
-			else
-				g_hash_table_insert(ret,g_strdup(parts[0]),g_strdup(parts[1]));
-		}
-		g_strfreev(parts);
-	}
-	g_strfreev(lines);
-	return ret;
-
-}
-
-// get_desc_task
-static void *get_desc_task(gpointer data)
-{
-	desc_task *dt = (desc_task *) data;
-
-	pk_task_change_job_status(dt->task, PK_STATUS_ENUM_QUERY);
-	pk_task_no_percentage_updates(dt->task);
-
-	pk_debug("finding %s", dt->pi->name);
-	pkgCache & pkgCache = *(getCache());
-	pkgDepCache::Policy Plcy;
-
-	// Map versions that we want to write out onto the VerList array.
-	for (pkgCache::PkgIterator P = pkgCache.PkgBegin(); P.end() == false; P++)
-	{
-		if (strcmp(dt->pi->name, P.Name())!=0)
-			continue;
-
-		// Find the proper version to use. 
-		pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
-		GHashTable *pkg = PackageRecord(V);
-		pk_task_description(dt->task,dt->pi->name,PK_GROUP_ENUM_OTHER,(const gchar*)g_hash_table_lookup(pkg,"Description"),"");
-		g_hash_table_unref(pkg);
-	}
-	pk_task_finished(dt->task, PK_EXIT_ENUM_SUCCESS);
-	return NULL;
-}
-
-/**
- * pk_task_get_description:
- **/
-gboolean pk_task_get_description(PkTask * task, const gchar * package)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
- 	desc_task *data = g_new(struct desc_task, 1);
-	if (data == NULL)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_INTERNAL_ERROR, "can't allocate memory for search task");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		return TRUE;
-	}
-
-	data->task = task;
-	data->pi = pk_package_id_new_from_string(package);
-	if (data->pi == NULL)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-		return TRUE;
-	}
-
-	if (g_thread_create(get_desc_task, data, false, NULL) == NULL)
-	{
-		pk_task_error_code(task, PK_ERROR_ENUM_INTERNAL_ERROR, "can't spawn thread");
-		pk_task_finished(task, PK_EXIT_ENUM_FAILED);
-	}
-	return TRUE;
-}
-
-/**
- * pk_task_remove_package:
- **/
-gboolean pk_task_remove_package(PkTask * task, const gchar * package, gboolean allow_deps)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
- 	pk_task_not_implemented_yet(task, "RemovePackage");
-	return FALSE;
-}
-
-/**
- * pk_task_install_package:
- **/
-gboolean pk_task_install_package(PkTask * task, const gchar * package)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	if (pk_task_assign(task) == FALSE)
-	{
-		return FALSE;
-	}
-
- 	pk_task_not_implemented_yet(task, "InstallPackage");
-	return FALSE;
-}
-
-/**
- * pk_task_cancel_job_try:
- **/
-gboolean pk_task_cancel_job_try(PkTask * task)
-{
-	g_return_val_if_fail(task != NULL, FALSE);
-	g_return_val_if_fail(PK_IS_TASK(task), FALSE);
-
-	/* check to see if we have an action */
-	if (task->assigned == FALSE)
-	{
-		pk_warning("Not assigned");
-		return FALSE;
-	}
-
- 	pk_task_not_implemented_yet (task, "CancelJobTry");
-	return FALSE;
-}
-
-/**
- * pk_task_update_package:
- **/
-gboolean
-pk_task_update_package (PkTask *task, const gchar *package_id)
-{
-	g_return_val_if_fail (task != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-
-	if (pk_task_assign (task) == FALSE) {
-		return FALSE;
-	}
-
-	pk_task_not_implemented_yet (task, "UpdatePackage");
-	return TRUE;
-}
-
-/**
- * pk_task_class_init:
- **/
-static void pk_task_class_init(PkTaskClass * klass)
-{
-	GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
-	object_class->finalize = pk_task_finalize;
-	pk_task_setup_signals(object_class, signals);
-	g_type_class_add_private(klass, sizeof(PkTaskPrivate));
-}
-
-/**
- * pk_task_init:
- **/
-static void pk_task_init(PkTask * task)
-{
-	task->priv = PK_TASK_GET_PRIVATE(task);
-	task->priv->network = pk_network_new();
-	task->signals = signals;
-	pk_task_common_init(task);
-}
-
-/**
- * pk_task_finalize:
- **/
-static void pk_task_finalize(GObject * object)
-{
-	PkTask *task;
-	g_return_if_fail(object != NULL);
-	g_return_if_fail(PK_IS_TASK(object));
-	task = PK_TASK(object);
-	g_return_if_fail(task->priv != NULL);
-	G_OBJECT_CLASS(pk_task_parent_class)->finalize(object);
-}
-
-/**
- * pk_task_new:
- **/
-PkTask *pk_task_new(void)
-{
-	PkTask *task;
-	task = (PkTask *) g_object_new(PK_TYPE_TASK, NULL);
-	return PK_TASK(task);
-}
-
diff-tree 2e3c6757ebbc0f06d491cc793295fa8fae0e59e9 (from 126c19c7f5d47153f408fe22f7a90da02e4b6243)
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Sep 10 14:13:06 2007 +0200

    Partial fix for job handling in python API
    For the moment, the python API returns all signals, irregardless
    of job id. We may wish to abstract the notion of a job id into
    a client-side object instead.

diff --git a/python/packagekit.py b/python/packagekit.py
index 934c45b..58304d0 100644
--- a/python/packagekit.py
+++ b/python/packagekit.py
@@ -65,16 +65,17 @@ def dbusException(func):
 			raise
 	return wrapper
 
-def job_id(func):
-	def wrapper(*args,**kwargs):
-		jid = func(*args,**kwargs)
-		if jid == -1:
-			raise PackageKitJobFailure
-		else:
-			return jid
-	return wrapper
 
 class PackageKit:
+	def job_id(func):
+		def wrapper(*args,**kwargs):
+			jid = func(*args,**kwargs)
+			if jid == -1:
+				raise PackageKitJobFailure
+			else:
+				return jid
+		return wrapper
+
 	def __init__(self):
 		DBusGMainLoop(set_as_default=True)
 		bus = dbus.SystemBus()
@@ -87,7 +88,7 @@ class PackageKit:
 			else:
 				raise PackageKitException(e)
 
-		self.job = None
+		#self.job = None
 		self.progress = 0.0
 		bus.add_signal_receiver(self.catchall_signal_handler, interface_keyword='dbus_interface', member_keyword='member',dbus_interface="org.freedesktop.PackageKit")
 	
@@ -96,10 +97,11 @@ class PackageKit:
 		self.loop.run()
 
 	def catchall_signal_handler(self,*args, **kwargs):
-		if args[0] != self.job and kwargs['member']!="JobListChanged":
-			return
+		#if args[0] != self.job and kwargs['member']!="JobListChanged":
+		#	print "args",args,kwargs
+		#	return
 		if kwargs['member'] == "Finished":
-			loop.quit()
+			self.loop.quit()
 			self.Finish()
 		elif kwargs['member'] == "PercentageChanged":
 			progress = float(args[1])+(progress%1.0)
@@ -143,5 +145,5 @@ class PackageKit:
 		return pk_iface.RefreshCache(force)
 
 # hack to avoid exporting them
-del job_id
+#del job_id
 del dbusException
diff-tree 126c19c7f5d47153f408fe22f7a90da02e4b6243 (from 9147991ef351d8b5a0b5aed464f3b77ab0630aec)
Author: Tom Parker <palfrey at tevp.net>
Date:   Mon Sep 10 14:18:20 2007 +0200

    Add search file to apt; remove old backend
    Search file capability has now been added to the new APT backend,
    and as this was the last unported feature of the "delete.me",
    that has now been removed. In the process of doing this,
    the pk_backend_search internal function has been redone a little
    in order to support different search thread choices, and to avoid
    needing two search_task generators.

diff --git a/backends/apt/pk-backend-apt.cpp b/backends/apt/pk-backend-apt.cpp
index e743cbe..21b0bba 100644
--- a/backends/apt/pk-backend-apt.cpp
+++ b/backends/apt/pk-backend-apt.cpp
@@ -52,7 +52,8 @@ typedef struct {
 
 typedef enum {
 	SEARCH_NAME = 1,
-	SEARCH_DETAILS
+	SEARCH_DETAILS,
+	SEARCH_FILE
 } SearchDepth;
 
 struct search_task {
@@ -461,7 +462,7 @@ static void *get_search_thread(gpointer 
 				Match = false;
 		}
 
-		if (Match == true)// && pk_task_filter_package_name(st->backend,P.Name().c_str()))
+		if (Match == true)// && pk_backend_filter_package_name(st->backend,P.Name().c_str()))
 		{
 			gchar *pid = pk_package_id_build(P.Name().c_str(),J->verstr,J->arch,J->repo);
 			pk_backend_package(st->backend, J->installed, pid, P.ShortDesc().c_str());
@@ -487,9 +488,10 @@ search_task_cleanup:
 /**
  * pk_backend_search
  **/
-static gboolean
-pk_backend_search(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which)
+static void
+pk_backend_search(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, void *(*search_thread)(gpointer data))
 {
+	g_return_if_fail (backend != NULL);
 	search_task *data = g_new(struct search_task, 1);
 	if (data == NULL)
 	{
@@ -503,13 +505,12 @@ pk_backend_search(PkBackend * backend, c
 		data->filter = g_strdup(filter);
 		data->depth = which;
 
-		if (g_thread_create(get_search_thread, data, false, NULL) == NULL)
+		if (g_thread_create(search_thread, data, false, NULL) == NULL)
 		{
-			pk_backend_error_code(backend, PK_ERROR_ENUM_UNKNOWN, "Failed to spawn thread");
+			pk_backend_error_code(backend, PK_ERROR_ENUM_CREATE_THREAD_FAILED, "Failed to spawn thread");
 			pk_backend_finished(backend, PK_EXIT_ENUM_FAILED);
 		}
 	}
-	return TRUE;
 }
 
 static GHashTable *PackageRecord(pkgCache::VerIterator V)
@@ -639,8 +640,7 @@ backend_get_description (PkBackend *back
 static void
 backend_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
 {
-	g_return_if_fail (backend != NULL);
-	pk_backend_search(backend, filter, search, SEARCH_DETAILS);
+	pk_backend_search(backend, filter, search, SEARCH_DETAILS, get_search_thread);
 }
 
 /**
@@ -649,8 +649,44 @@ backend_search_details (PkBackend *backe
 static void
 backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
 {
-	g_return_if_fail (backend != NULL);
-	pk_backend_search(backend, filter, search, SEARCH_NAME);
+	pk_backend_search(backend, filter, search, SEARCH_NAME, get_search_thread);
+}
+
+static void *do_search_file(gpointer data)
+{
+	search_task *st = (search_task*)data;
+	gchar *sdir = g_path_get_dirname(_config->Find("Dir::State::status").c_str());
+	gchar *ldir = g_build_filename(sdir,"info",NULL);
+	g_free(sdir);
+	GError *error = NULL;
+	GDir *list = g_dir_open(ldir,0,&error);
+	if (error!=NULL)
+	{
+		pk_backend_error_code(st->backend, PK_ERROR_ENUM_INTERNAL_ERROR, "can't open %s",ldir);
+		g_free(ldir);
+		g_error_free(error);
+		pk_backend_finished(st->backend, PK_EXIT_ENUM_FAILED);
+		return NULL;
+	}
+	const gchar * fname = NULL;
+	while ((fname = g_dir_read_name(list))!=NULL)
+	{
+		//pk_backend_package(st->backend, J->installed, pid, P.ShortDesc().c_str());
+	}
+	pk_backend_error_code(st->backend, PK_ERROR_ENUM_INTERNAL_ERROR, "search file is incomplete");
+	pk_backend_finished(st->backend, PK_EXIT_ENUM_FAILED);
+	g_dir_close(list);
+	g_free(ldir);
+	//pk_backend_finished(st->backend, PK_EXIT_ENUM_SUCCESS);
+	return NULL;
+}
+
+/**
+ * backend_search_file:
+ **/
+static void backend_search_file(PkBackend *backend, const gchar *filter, const gchar *search)
+{
+	pk_backend_search(backend, filter, search, SEARCH_FILE, do_search_file);
 }
 
 extern "C" PK_BACKEND_OPTIONS (
@@ -670,7 +706,7 @@ extern "C" PK_BACKEND_OPTIONS (
 	backend_refresh_cache,			/* refresh_cache */
 	NULL,					/* remove_package */
 	backend_search_details,			/* search_details */
-	NULL,					/* search_file */
+	backend_search_file,			/* search_file */
 	NULL,					/* search_group */
 	backend_search_name,			/* search_name */
 	NULL,					/* update_package */
diff-tree 12399e6b53694892bab85e8521a1ba8bedfb1dd1 (from 9147991ef351d8b5a0b5aed464f3b77ab0630aec)
Author: Andreas Obergrusberger <tradiaz at yahoo.de>
Date:   Mon Sep 10 14:16:51 2007 +0200

    polished alpm backend

diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index 42cd080..044db56 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -32,8 +32,22 @@
 
 static int progress_percentage;
 
+typedef struct _PackageSource 
+{
+  pmpkg_t *pkg;
+  gchar *repo;
+  guint installed;
+} PackageSource;
+
+
+static void
+package_source_free (PackageSource *source)
+{
+  alpm_pkg_free (source->pkg);
+}
+
 alpm_list_t *
-my_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
+my_list_mmerge (alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
 {
   alpm_list_t *newlist, *lp;
 
@@ -90,7 +104,7 @@ pkg_equal (pmpkg_t *p1, pmpkg_t *p2)
 }
 
 alpm_list_t *
-my_list_remove_node(alpm_list_t *node)
+my_list_remove_node (alpm_list_t *node)
 {
   if(!node) return(NULL);
 
@@ -110,45 +124,103 @@ my_list_remove_node(alpm_list_t *node)
   return(ret);
 }
 
-
-/*static int 
+static int 
 list_cmp_fn (const void *n1, const void *n2)
 {
   return 0;
-}*/
-
-
+}
 
 static void
-add_package (PkBackend *backend, pmpkg_t *package, pmdb_t *db, guint installed)
+add_package (PkBackend *backend, PackageSource *package)
 { 
   gchar *pkg_string;
-  pkg_string = pk_package_id_build(alpm_pkg_get_name (package), 
-				     alpm_pkg_get_version (package), 
-				     alpm_pkg_get_arch (package), 
-				     alpm_db_get_name (db));
+  pkg_string = pk_package_id_build(alpm_pkg_get_name (package->pkg), 
+				     alpm_pkg_get_version (package->pkg), 
+				     alpm_pkg_get_arch (package->pkg), 
+				     package->repo);
 
-  pk_backend_package (backend, installed, pkg_string, alpm_pkg_get_desc (package));
+  pk_backend_package (backend, package->installed, pkg_string, alpm_pkg_get_desc (package->pkg));
 
   g_free(pkg_string);
 }
 
-
-
-
 static void
-add_packages_from_list (PkBackend *backend, alpm_list_t *list, pmdb_t *db, guint installed)
+add_packages_from_list (PkBackend *backend, alpm_list_t *list)
 {
-  pmpkg_t *package = NULL;
+  PackageSource *package = NULL;
   alpm_list_t *li = NULL;
 
   for (li = list; li != NULL; li = alpm_list_next (li)) {
-    package = (pmpkg_t *)li->data;
-    add_package (backend, package, db, installed);
+    package = (PackageSource *)li->data;
+    add_package (backend, package);
   }
 }
 
+alpm_list_t *
+find_packages ( const gchar *name, pmdb_t *db)
+{
+  if (db == NULL || name == NULL) return NULL;
+
+  alpm_list_t *needle = NULL;
+  alpm_list_t *result = NULL;
+  alpm_list_t *localresult = NULL;
+  pmdb_t *localdb = NULL;
+  const gchar *dbname = NULL;
+
+  needle = alpm_list_add (needle, (gchar *)name);
+  dbname = alpm_db_get_name (db);
+  result = alpm_db_search (db, needle);
+
+  alpm_list_t *i = NULL;
+
+  if (db != localdb)
+    {
+      localdb = alpm_option_get_localdb ();
+      if (localdb != NULL)
+	localresult = alpm_db_search (localdb, needle);
+    }
+
+  for (i = result; i; i = alpm_list_next (i))
+    {
+      PackageSource *source = g_malloc (sizeof (PackageSource));
+
+      source->pkg = (pmpkg_t *)i->data;
+      source->repo = (gchar *)dbname;
+
+      if (localresult != NULL)
+	{
+	  alpm_list_t *icmp = NULL;
+	  for (icmp = localresult; icmp; icmp = alpm_list_next (icmp))
+	    if (pkg_equal ((pmpkg_t *)icmp->data, (pmpkg_t *)i->data))
+	      source->installed = TRUE;
+	    else source->installed = FALSE;
+	}
+      else if (localdb == db) source->installed = TRUE;
+      else  source->installed = FALSE;
+
+      i->data = source;
+    }
+
+  return result;
+}
 
+static void
+filter_packages_installed (alpm_list_t *packages, gboolean filter)
+{
+  alpm_list_t *i;
+  for (i = packages; i; )
+    {
+      if (((PackageSource *)i->data)->installed == filter)
+	{
+	  alpm_list_t *temp = i;
+	  i = alpm_list_next (i);
+	  package_source_free ((PackageSource *)temp->data);
+	  my_list_remove_node (temp);
+	  continue;
+	}
+      i = alpm_list_next (i);
+    }
+}
 
 /**
  * backend_destroy:
@@ -233,15 +305,13 @@ static void
 backend_get_description (PkBackend *backend, const gchar *package_id)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_description (backend, "gnome-power-manager;2.6.19;i386;fedora", PK_GROUP_ENUM_PROGRAMMING,
-"Scribus is an desktop open source page layout program with "
-"the aim of producing commercial grade output in PDF and "
-"Postscript, primarily, though not exclusively for Linux.\n"
-"\n"
-"While the goals of the program are for ease of use and simple easy to "
-"understand tools, Scribus offers support for professional publishing "
-"features, such as CMYK color, easy PDF creation, Encapsulated Postscript "
-"import/export and creation of color separations.", "http://live.gnome.org/GnomePowerManager");
+	PkPackageId *id = pk_package_id_new_from_string (package_id);
+	if (id == NULL)
+	  {
+	    pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
+	    return;
+	  }
+	//pk_backend_description (backend, package_id, PK_GROUP_ENUM_PROGRAMMING, "sdgd");
 	pk_backend_finished (backend, PK_EXIT_ENUM_SUCCESS);
 }
 
@@ -384,22 +454,11 @@ static void
 backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_no_percentage_updates (backend);
-
-	gboolean installed = TRUE;
-	gboolean ninstalled = TRUE;
-	pmdb_t *localdb = NULL;
-	alpm_list_t *syncdbs = NULL;
+	alpm_list_t *result = NULL;
+	alpm_list_t *dbs = NULL;
 	gchar **sections = NULL;
-	alpm_list_t *needle = NULL;
-	alpm_list_t *localresult = NULL;
+	gboolean installed = TRUE, ninstalled = TRUE;
 
-	localdb = alpm_option_get_localdb ();
-	if (localdb == NULL)
-	  {
-	    pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
-	    return;
-	  }
 
 	sections = g_strsplit (filter, ";", 0);
 	int i = 0;
@@ -417,61 +476,19 @@ backend_search_name (PkBackend *backend,
 	}
 	g_strfreev (sections);
 
-	needle = alpm_list_add (NULL, (void *)search);
-
 	pk_debug ("alpm: searching for \"%s\" - searchin in installed: %i, ~installed: %i",
-		  (char *)needle->data, installed, ninstalled);
+		  search, installed, ninstalled);
 
-	if (ninstalled)
-	  {
-	    syncdbs = alpm_option_get_syncdbs ();
-	    if (syncdbs != NULL && alpm_list_count (syncdbs) != 0)
-	      {
-		alpm_list_t *i;
-		localresult = alpm_db_search (localdb, needle);
-		for (i = syncdbs; i; i = alpm_list_next (i))
-		  {
-		    alpm_list_t *curresult = alpm_db_search ((pmdb_t *)syncdbs->data, needle);
-
-		    if (curresult != NULL && localresult != NULL)
-		      {
-			alpm_list_t *icmp;
-			alpm_list_t *icmp2;
-			for (icmp = curresult; icmp; icmp = alpm_list_next (icmp))
-			  {
-
-			    for (icmp2 = localresult; icmp2; icmp2 = alpm_list_next (icmp2))
-			      {
-				gboolean success = FALSE;
-				if (pkg_equal (icmp->data, icmp2->data))
-				  {
-				    if (installed)
-				      {
-					success = TRUE;
-					add_package (backend, (pmpkg_t *)icmp->data, (pmdb_t *)i->data, TRUE);
-					break;
-				      }
-				  }
-				if (success == FALSE)
-				  add_package (backend, (pmpkg_t *)icmp->data, (pmdb_t *)i->data, FALSE);
-			      }
-			  }
-			alpm_list_free (curresult);
-		      }
-		  }
-	      }
-	  }
+	if (installed) dbs = alpm_list_add (dbs, alpm_option_get_localdb ());
+	if (ninstalled) dbs = my_list_mmerge (dbs, alpm_option_get_syncdbs (), list_cmp_fn);
 
-	if (installed && ninstalled)
-	  {
-	      {
-		pk_debug ("searching in local db");
-		alpm_list_t * localresult = alpm_db_search (localdb, needle);
-		//pk_debug (alpm_pkg_get_name (localresult->data));
-		pk_debug ("%i", (int)localresult);
-		add_packages_from_list (backend, localresult, localdb, TRUE);
-	      }
-	  }
+	for (; dbs; dbs = alpm_list_next (dbs))
+	  result = my_list_mmerge (result, find_packages (search, (pmdb_t *)dbs->data), list_cmp_fn);
+
+	if (!installed) filter_packages_installed (result, TRUE);
+	if (!ninstalled) filter_packages_installed (result, FALSE);	
+	
+	add_packages_from_list (backend, result);
 	pk_backend_finished  (backend, PK_EXIT_ENUM_SUCCESS); 
 }
 
diff-tree 9147991ef351d8b5a0b5aed464f3b77ab0630aec (from 3c623dd47802d1bb83060924764ed31fef65fef6)
Author: Andreas Obergrusberger <tradiaz at yahoo.de>
Date:   Mon Sep 10 11:59:18 2007 +0200

    alpm update

diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index 1140f16..42cd080 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -386,8 +386,8 @@ backend_search_name (PkBackend *backend,
 	g_return_if_fail (backend != NULL);
 	pk_backend_no_percentage_updates (backend);
 
-	gboolean installed = FALSE;
-	gboolean ninstalled = FALSE;
+	gboolean installed = TRUE;
+	gboolean ninstalled = TRUE;
 	pmdb_t *localdb = NULL;
 	alpm_list_t *syncdbs = NULL;
 	gchar **sections = NULL;
@@ -419,7 +419,7 @@ backend_search_name (PkBackend *backend,
 
 	needle = alpm_list_add (NULL, (void *)search);
 
-	pk_debug ("alpm: searching for \"%s\" - filter installed: %i, ~installed: %i",
+	pk_debug ("alpm: searching for \"%s\" - searchin in installed: %i, ~installed: %i",
 		  (char *)needle->data, installed, ninstalled);
 
 	if (ninstalled)



More information about the PackageKit mailing list