Esempio n. 1
0
static void
backend_find_packages_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	PkBitfield filters;
	const gchar *search;
	gchar **values;
	guint mode;
	GList *list = NULL;
	sqlite3 *db = NULL;
	gint filter_box = 0;

	filters = pk_backend_get_uint (backend, "filters");
	mode = pk_backend_get_uint (backend, "mode");
	values = pk_backend_get_strv (backend, "search");
	/* FIXME: support multiple packages */
	search = values[0];

	pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY);

	if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
		filter_box = filter_box | PKG_INSTALLED;
	}
	if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
		filter_box = filter_box | PKG_AVAILABLE;
	}
	if (pk_bitfield_contain (filters, PK_FILTER_ENUM_DEVELOPMENT)) {
		filter_box = filter_box | PKG_DEVEL;
	}
	if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_DEVELOPMENT)) {
		filter_box = filter_box | PKG_NON_DEVEL;
	}
	if (pk_bitfield_contain (filters, PK_FILTER_ENUM_GUI)) {
		filter_box = filter_box | PKG_GUI;
	}
	if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_GUI)) {
		filter_box = filter_box | PKG_TEXT;
	}
	if (mode == SEARCH_TYPE_DETAILS) {
		filter_box = filter_box | PKG_SEARCH_DETAILS;
	}

	pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID);

	db = db_open ();

	if (mode == SEARCH_TYPE_FILE) {
		list = box_db_repos_search_file_with_filter (db, search, filter_box);
		add_packages_from_list (backend, list, FALSE);
		box_db_repos_package_list_free (list);
	} else if (mode == SEARCH_TYPE_RESOLVE) {
		list = box_db_repos_packages_search_one (db, (gchar *)search);
		add_packages_from_list (backend, list, FALSE);
		box_db_repos_package_list_free (list);
	} else {
		if ((pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
		     pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) ||
		    (!pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
		     !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED))) {
			list = box_db_repos_packages_search_all (db, (gchar *)search, filter_box);
		} else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
			list = box_db_repos_packages_search_installed (db, (gchar *)search, filter_box);
		} else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
			list = box_db_repos_packages_search_available (db, (gchar *)search, filter_box);
		}
		add_packages_from_list (backend, list, FALSE);
		box_db_repos_package_list_free (list);
	}

	db_close (db);
	pk_backend_finished (backend);
}
/**
 * pk_plugin_transaction_finished_end:
 */
void
pk_plugin_transaction_finished_end (PkPlugin *plugin,
				    PkTransaction *transaction)
{
	PkBitfield transaction_flags;
	PkExitEnum exit_enum;
	PkResults *results;
	PkRoleEnum role;

/* only do this if we have systemd */
#ifndef PK_BUILD_SYSTEMD
	g_debug ("No systemd, so no PreparedUpdates");
	return;
#endif

	/* skip simulate actions */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
		goto out;
	}

	/* don't do anything if the method failed */
	results = pk_transaction_get_results (transaction);
	exit_enum = pk_results_get_exit_code (results);
	if (exit_enum != PK_EXIT_ENUM_SUCCESS)
		goto out;

	/* if we're doing UpdatePackages[only-download] then update the
	 * prepared-updates file */
	role = pk_transaction_get_role (transaction);
	transaction_flags = pk_transaction_get_transaction_flags (transaction);
	if (role == PK_ROLE_ENUM_UPDATE_PACKAGES &&
	    pk_bitfield_contain (transaction_flags,
				 PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) {
		pk_plugin_transaction_update_packages (transaction);
		goto out;
	}

	/* if we do get-updates and there's no updates then remove
	 * prepared-updates so the UI doesn't display update & reboot */
	if (role == PK_ROLE_ENUM_GET_UPDATES) {
		pk_plugin_transaction_get_updates (transaction);
		goto out;
	}

	/* delete the prepared updates file as it's no longer valid */
	if (role == PK_ROLE_ENUM_REFRESH_CACHE ||
	    role == PK_ROLE_ENUM_REPO_SET_DATA ||
	    role == PK_ROLE_ENUM_REPO_ENABLE) {
		pk_plugin_state_changed (plugin);
		goto out;
	}

	/* delete the file if the action affected any package already listed in
	 * the prepared updates file */
	if (role == PK_ROLE_ENUM_UPDATE_PACKAGES ||
	    role == PK_ROLE_ENUM_INSTALL_PACKAGES ||
	    role == PK_ROLE_ENUM_REMOVE_PACKAGES) {
		pk_plugin_transaction_action_method (plugin, transaction, results);
	}
out:
	return;
}
Esempio n. 3
0
static gboolean
backend_repo_manager_thread (PkBackend *backend)
{
	// list
	PkBitfield filters;
	bool notDevelopment;
	// enable
	const gchar *repo_id;
	bool enabled;
	bool found = false;
	// generic
	const char *const salt = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/";
	bool list = pk_backend_get_bool(backend, "list");

	if (list) {
		pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
		filters = (PkBitfield) pk_backend_get_uint(backend, "filters");
		notDevelopment = pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_DEVELOPMENT);
	} else {
		pk_backend_set_status (backend, PK_STATUS_ENUM_REQUEST);
		repo_id = pk_backend_get_string(backend, "repo_id");
		enabled = pk_backend_get_bool(backend, "enabled");
	}

	SourcesList _lst;
	if (_lst.ReadSources() == false) {
		_error->
		    Warning("Ignoring invalid record(s) in sources.list file!");
	    //return false;
	}

	if (_lst.ReadVendors() == false) {
		_error->Error("Cannot read vendors.list file");
		show_errors(backend, PK_ERROR_ENUM_FAILED_CONFIG_PARSING);
		pk_backend_finished (backend);
		return false;
	}

	for (SourcesListIter it = _lst.SourceRecords.begin();
	it != _lst.SourceRecords.end(); it++)
	{
		if ((*it)->Type & SourcesList::Comment) {
		    continue;
		}

		string Sections;
		for (unsigned int J = 0; J < (*it)->NumSections; J++) {
			Sections += (*it)->Sections[J];
			Sections += " ";
		}

		if (notDevelopment &&
			((*it)->Type & SourcesList::DebSrc ||
			(*it)->Type & SourcesList::RpmSrc ||
			(*it)->Type & SourcesList::RpmSrcDir ||
			(*it)->Type & SourcesList::RepomdSrc))
		{
			continue;
		}

		string repo;
		repo = (*it)->GetType();
		repo += " " + (*it)->VendorID;
		repo += " " + (*it)->URI;
		repo += " " + (*it)->Dist;
		repo += " " + Sections;
		gchar *hash;
		const gchar allowedChars[] =
		    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		hash = crypt(repo.c_str(), salt);
		g_strcanon(hash, allowedChars, 'D');
		string repoId(hash);

		if (list) {
			pk_backend_repo_detail(backend,
					    repoId.c_str(),
					    repo.c_str(),
					    !((*it)->Type & SourcesList::Disabled));
		} else {
			if (repoId.compare(repo_id) == 0) {
				if (enabled) {
					(*it)->Type = (*it)->Type & ~SourcesList::Disabled;
				} else {
					(*it)->Type |= SourcesList::Disabled;
				}
				found = true;
				break;
			}
		}
	}

	if (!list) {
		if (!found) {
			_error->Error("Could not found the repositorie");
			show_errors(backend, PK_ERROR_ENUM_REPO_NOT_AVAILABLE);
		} else if (!_lst.UpdateSources()) {
			_error->Error("Could not update sources file");
			show_errors(backend, PK_ERROR_ENUM_CANNOT_WRITE_REPO_CONFIG);
		}
	}
	pk_backend_finished (backend);
	return true;
}
Esempio n. 4
0
static void
pk_backend_search_thread (PkBackendJob *job, GVariant* params, gpointer p)
{
	PkBackend *backend = pk_backend_job_get_backend (job);
	PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
	gchar **needles = NULL;
	SearchType type;

	PatternFunc pattern_func;
	GDestroyNotify pattern_free;
	MatchFunc match_func;

	PkRoleEnum role;
	PkBitfield filters = 0;
	gboolean skip_local, skip_remote;

	const alpm_list_t *i;
	alpm_list_t *patterns = NULL;
	_cleanup_error_free_ GError *error = NULL;

	g_return_if_fail (p == NULL);

	role = pk_backend_job_get_role(job);
	switch(role) {
	case PK_ROLE_ENUM_GET_PACKAGES:
		type = SEARCH_TYPE_ALL;
		g_variant_get (params, "(t)", &filters);
		break;
	case PK_ROLE_ENUM_GET_DETAILS:
		type = SEARCH_TYPE_DETAILS;
		g_variant_get (params, "(^a&s)", &needles);
		break;
	case PK_ROLE_ENUM_SEARCH_FILE:
		type = SEARCH_TYPE_FILES;
		g_variant_get (params, "(t^a&s)", &filters, &needles);
		break;
	case PK_ROLE_ENUM_SEARCH_GROUP:
		type = SEARCH_TYPE_GROUP;
		g_variant_get (params, "(t^a&s)", &filters, &needles);
		break;
	case PK_ROLE_ENUM_SEARCH_NAME:
		type = SEARCH_TYPE_NAME;
		g_variant_get (params, "(t^a&s)", &filters, &needles);
		break;
	case PK_ROLE_ENUM_WHAT_PROVIDES:
		type = SEARCH_TYPE_PROVIDES;
		g_variant_get (params, "(t^a&s)", &filters, &needles);
		break;
	case PK_ROLE_ENUM_SEARCH_DETAILS:
		type = SEARCH_TYPE_DETAILS;
		g_variant_get (params, "(t^a&s)",
					  &filters,
					  &needles);
		break;
	default:
		g_assert_not_reached ();
		break;
	}

	g_return_if_fail (type < SEARCH_TYPE_LAST);

	pattern_func = pattern_funcs[type];
	pattern_free = pattern_frees[type];
	match_func = match_funcs[type];

	g_return_if_fail (pattern_func != NULL);
	g_return_if_fail (match_func != NULL);

	skip_local = pk_bitfield_contain (filters,
					  PK_FILTER_ENUM_NOT_INSTALLED);
	skip_remote = pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED);

	/* convert search terms to the pattern requested */
	if (needles) {
		for (; *needles != NULL; ++needles) {
			gpointer pattern = pattern_func (backend, *needles, &error);

			if (pattern == NULL)
				goto out;

			patterns = alpm_list_add (patterns, pattern);
		}
	}

	/* find installed packages first */
	if (!skip_local)
		pk_backend_search_db (job, priv->localdb, match_func, patterns);

	if (skip_remote)
		goto out;

	for (i = alpm_get_syncdbs (priv->alpm); i != NULL; i = i->next) {
		if (pk_backend_job_is_cancelled (job))
			break;

		pk_backend_search_db (job, i->data, match_func, patterns);
	}
out:
	if (pattern_free != NULL)
		alpm_list_free_inner (patterns, pattern_free);
	alpm_list_free (patterns);
	pk_alpm_finish (job, error);
}
Esempio n. 5
0
/**
 * backend_get_packages:
 */
static void
backend_get_packages (PkBackend *backend, PkBitfield filters)
{
	PkFilterEnum list_order[] = {
	    PK_FILTER_ENUM_INSTALLED,
	    PK_FILTER_ENUM_NOT_INSTALLED,
	    PK_FILTER_ENUM_UNKNOWN
	};
	PkFilterEnum *list_filter;

	slapt_pkg_list_t *pkglist;
	slapt_pkg_info_t *pkg;
	slapt_pkg_info_t *other_pkg;
	unsigned int i;
	const gchar *package_id;

	slapt_pkg_list_t *installed;
	slapt_pkg_list_t *available;

	PkInfoEnum state;
	const char *summary;

	installed = slapt_get_installed_pkgs();
	available = slapt_get_available_pkgs();

	pk_backend_set_status (backend, PK_STATUS_ENUM_REQUEST);
	for (list_filter = list_order; *list_filter != PK_FILTER_ENUM_UNKNOWN; list_filter++) {

	    if (*list_filter == PK_FILTER_ENUM_INSTALLED) {
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED))
		    break;
		pkglist = installed;
	    } else if (*list_filter == PK_FILTER_ENUM_NOT_INSTALLED) {
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED))
		    break;
		pkglist = available;
	    } else {
		continue;
	    }

	    for (i = 0; i < pkglist->pkg_count; i++) {
		pkg = pkglist->pkgs[i];

		/* check so that we don't show installed pkgs twice */
		if (*list_filter == PK_FILTER_ENUM_NOT_INSTALLED &&
		    !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
		    other_pkg = slapt_get_exact_pkg(installed,
		                                    pkg->name, pkg->version);
		    if (other_pkg != NULL) {
			continue;
		    }
		}

		/* only display the newest pkg in each pkglist */
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NEWEST)) {
		    other_pkg = slapt_get_newest_pkg(pkglist, pkg->name);
		    if (slapt_cmp_pkgs(pkg, other_pkg) <= 0) {
			continue;
		    }
		}

		state = pkg->installed ? PK_INFO_ENUM_INSTALLED : PK_INFO_ENUM_AVAILABLE;
		package_id = _get_string_from_pkg(pkg);
		summary = _get_pkg_summary(pkg);
		pk_backend_package (backend, state, package_id, summary);
		g_free((gpointer) summary);
		g_free((gpointer) package_id);
	    }

	}

	slapt_free_pkg_list(available);
	slapt_free_pkg_list(installed);

	pk_backend_finished (backend);
}
Esempio n. 6
0
static void pk_backend_install_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) {
	gchar *dest_dir_name, **pkg_tokens, **pkg_ids;
	guint i;
	gdouble percent_step;
	GSList *repo, *install_list = NULL, *l;
	sqlite3_stmt *pkglist_stmt = NULL, *collection_stmt = NULL;
    PkBitfield transaction_flags = 0;
	PkInfoEnum ret;
	PkBackendKatjaJobData *job_data = pk_backend_job_get_user_data(job);

	g_variant_get(params, "(t^a&s)", &transaction_flags, &pkg_ids);
	pk_backend_job_set_status(job, PK_STATUS_ENUM_DEP_RESOLVE);

	if ((sqlite3_prepare_v2(job_data->db,
							"SELECT summary, cat FROM pkglist NATURAL JOIN repos "
							"WHERE name LIKE @name AND ver LIKE @ver AND arch LIKE @arch AND repo LIKE @repo",
							-1,
							&pkglist_stmt,
							NULL) != SQLITE_OK) ||
		(sqlite3_prepare_v2(job_data->db,
						   "SELECT (c.collection_pkg || ';' || p.ver || ';' || p.arch || ';' || r.repo), p.summary, "
						   "p.full_name, p.ext FROM collections AS c "
						   "JOIN pkglist AS p ON c.collection_pkg = p.name "
						   "JOIN repos AS r ON p.repo_order = r.repo_order "
						   "WHERE c.name LIKE @name AND r.repo LIKE @repo",
						   -1,
						   &collection_stmt,
						   NULL) != SQLITE_OK)) {
		pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db));
		goto out;
	}

	for (i = 0; pkg_ids[i]; i++) {
		pkg_tokens = pk_package_id_split(pkg_ids[i]);
		sqlite3_bind_text(pkglist_stmt, 1, pkg_tokens[PK_PACKAGE_ID_NAME], -1, SQLITE_TRANSIENT);
		sqlite3_bind_text(pkglist_stmt, 2, pkg_tokens[PK_PACKAGE_ID_VERSION], -1, SQLITE_TRANSIENT);
		sqlite3_bind_text(pkglist_stmt, 3, pkg_tokens[PK_PACKAGE_ID_ARCH], -1, SQLITE_TRANSIENT);
		sqlite3_bind_text(pkglist_stmt, 4, pkg_tokens[PK_PACKAGE_ID_DATA], -1, SQLITE_TRANSIENT);

		if (sqlite3_step(pkglist_stmt) == SQLITE_ROW) {

			/* If it isn't a collection */
			if (g_strcmp0((gchar *) sqlite3_column_text(pkglist_stmt, 1), "collections")) {
				if (pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
					pk_backend_job_package(job, PK_INFO_ENUM_INSTALLING,
										   pkg_ids[i],
										   (gchar *) sqlite3_column_text(pkglist_stmt, 0));
				} else {
					install_list = g_slist_append(install_list, g_strdup(pkg_ids[i]));
				}
			} else {
				sqlite3_bind_text(collection_stmt, 1, pkg_tokens[PK_PACKAGE_ID_NAME], -1, SQLITE_TRANSIENT);
				sqlite3_bind_text(collection_stmt, 2, pkg_tokens[PK_PACKAGE_ID_DATA], -1, SQLITE_TRANSIENT);

				while (sqlite3_step(collection_stmt) == SQLITE_ROW) {
					ret = katja_pkg_is_installed((gchar *) sqlite3_column_text(collection_stmt, 2));
					if ((ret == PK_INFO_ENUM_INSTALLING) || (ret == PK_INFO_ENUM_UPDATING)) {
						if ((pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) &&
							!g_strcmp0((gchar *) sqlite3_column_text(collection_stmt, 3), "obsolete")) {
							/* TODO: Don't just skip obsolete packages but remove them */
						} else if (pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
							pk_backend_job_package(job, ret,
												   (gchar *) sqlite3_column_text(collection_stmt, 0),
												   (gchar *) sqlite3_column_text(collection_stmt, 1));
						} else {
							install_list = g_slist_append(install_list,
														  g_strdup((gchar *) sqlite3_column_text(collection_stmt, 0)));
						}
					}
				}

				sqlite3_clear_bindings(collection_stmt);
				sqlite3_reset(collection_stmt);
			}
		}

		sqlite3_clear_bindings(pkglist_stmt);
		sqlite3_reset(pkglist_stmt);
		g_strfreev(pkg_tokens);
	}

	if (install_list && !pk_bitfield_contain(transaction_flags, PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
		/* / 2 means total percentage for installing and for downloading */
		percent_step = 100.0 / g_slist_length(install_list) / 2;

		/* Download the packages */
		pk_backend_job_set_status(job, PK_STATUS_ENUM_DOWNLOAD);
		dest_dir_name = g_build_filename(LOCALSTATEDIR, "cache", "PackageKit", "downloads", NULL);
		for (l = install_list, i = 0; l; l = g_slist_next(l), i++) {
			pk_backend_job_set_percentage(job, percent_step * i);
			pkg_tokens = pk_package_id_split(l->data);
			repo = g_slist_find_custom(repos, pkg_tokens[PK_PACKAGE_ID_DATA], katja_cmp_repo);

			if (repo)
				katja_pkgtools_download(KATJA_PKGTOOLS(repo->data), job,
										dest_dir_name,
										pkg_tokens[PK_PACKAGE_ID_NAME]);
			g_strfreev(pkg_tokens);
		}
		g_free(dest_dir_name);

		/* Install the packages */
		pk_backend_job_set_status(job, PK_STATUS_ENUM_INSTALL);
		for (l = install_list; l; l = g_slist_next(l), i++) {
			pk_backend_job_set_percentage(job, percent_step * i);
			pkg_tokens = pk_package_id_split(l->data);
			repo = g_slist_find_custom(repos, pkg_tokens[PK_PACKAGE_ID_DATA], katja_cmp_repo);

			if (repo)
				katja_pkgtools_install(KATJA_PKGTOOLS(repo->data), job, pkg_tokens[PK_PACKAGE_ID_NAME]);
			g_strfreev(pkg_tokens);
		}
	}
	g_slist_free_full(install_list, g_free);

out:
	sqlite3_finalize(pkglist_stmt);
	sqlite3_finalize(collection_stmt);

	pk_backend_job_finished (job);
}
/**
 * pk_plugin_transaction_finished_results:
 */
void
pk_plugin_transaction_finished_results (PkPlugin *plugin,
					PkTransaction *transaction)
{
	gchar **package_ids = NULL;
	gchar *package_id_tmp;
	GPtrArray *array = NULL;
	GPtrArray *list = NULL;
	guint i;
	PkInfoEnum info;
	PkPackage *item;
	PkResults *results;
	PkRoleEnum role;

	/* skip simulate actions */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
		goto out;
	}

	/* skip only-download */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) {
		goto out;
	}

	/* load */
	if (plugin->priv->db == NULL)
		pk_transaction_plugin_load_db (plugin, transaction);

	/* no database */
	if (plugin->priv->db == NULL)
		goto out;

	/* check the role */
	role = pk_transaction_get_role (transaction);
	if (role != PK_ROLE_ENUM_INSTALL_PACKAGES)
		goto out;

	/* connect to backend */
	if (!pk_backend_is_implemented (plugin->backend,
					PK_ROLE_ENUM_GET_FILES)) {
		g_debug ("cannot get files");
		goto out;
	}

	/* get results */
	results = pk_transaction_get_results (transaction);
	array = pk_results_get_package_array (results);

	/* filter on INSTALLING | UPDATING */
	list = g_ptr_array_new_with_free_func (g_free);
	for (i=0; i<array->len; i++) {
		item = g_ptr_array_index (array, i);
		info = pk_package_get_info (item);
		if (info == PK_INFO_ENUM_INSTALLING ||
		    info == PK_INFO_ENUM_UPDATING) {
			/* we convert the package_id data to be 'installed' */
			package_id_tmp = pk_package_id_build (pk_package_get_name (item),
							      pk_package_get_version (item),
							      pk_package_get_arch (item),
							      "installed");
			g_ptr_array_add (list, package_id_tmp);
		}
	}

	/* process file lists on these packages */
	if (list->len == 0)
		goto out;
	g_debug ("processing %i packages for desktop files", list->len);

	/* get all the files touched in the packages we just installed */
	pk_backend_reset_job (plugin->backend, plugin->job);
	pk_backend_job_set_vfunc (plugin->job,
				  PK_BACKEND_SIGNAL_FINISHED,
				  (PkBackendJobVFunc) pk_plugin_finished_cb,
				  plugin);
	pk_backend_job_set_vfunc (plugin->job,
				  PK_BACKEND_SIGNAL_FILES,
				  (PkBackendJobVFunc) pk_plugin_files_cb,
				  plugin);
	pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS);
	pk_backend_job_set_percentage (plugin->job, 101);
	package_ids = pk_ptr_array_to_strv (list);
	pk_backend_get_files (plugin->backend, plugin->job, package_ids);

	/* wait for finished */
	g_main_loop_run (plugin->priv->loop);

	pk_backend_job_set_percentage (plugin->job, 100);
out:
	if (array != NULL)
		g_ptr_array_unref (array);
	if (list != NULL)
		g_ptr_array_unref (list);
	g_strfreev (package_ids);
}
/**
 * pk_plugin_transaction_finished_end:
 */
void
pk_plugin_transaction_finished_end (PkPlugin *plugin,
				    PkTransaction *transaction)
{
	gchar *error_msg = NULL;
	gchar *path;
	gchar *statement;
	gfloat step;
	gint rc;
	GPtrArray *array = NULL;
	guint i;
	PkRoleEnum role;

	/* skip simulate actions */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
		goto out;
	}

	/* skip only-download */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) {
		goto out;
	}

	/* load */
	if (plugin->priv->db == NULL)
		pk_transaction_plugin_load_db (plugin, transaction);

	/* no database */
	if (plugin->priv->db == NULL)
		goto out;

	/* check the role */
	role = pk_transaction_get_role (transaction);
	if (role != PK_ROLE_ENUM_REFRESH_CACHE)
		goto out;

	/* connect to backend */
	if (!pk_backend_is_implemented (plugin->backend,
					PK_ROLE_ENUM_SEARCH_FILE)) {
		g_debug ("cannot search files");
		goto out;
	}

	/* use a local backend instance */
	pk_backend_reset_job (plugin->backend, plugin->job);
	pk_backend_job_set_vfunc (plugin->job,
				  PK_BACKEND_SIGNAL_FINISHED,
				  (PkBackendJobVFunc) pk_plugin_finished_cb,
				  plugin);
	pk_backend_job_set_vfunc (plugin->job,
				  PK_BACKEND_SIGNAL_PACKAGE,
				  (PkBackendJobVFunc) pk_plugin_package_cb,
				  plugin);
	pk_backend_job_set_status (plugin->job,
				   PK_STATUS_ENUM_SCAN_APPLICATIONS);

	/* reset hash */
	g_hash_table_remove_all (plugin->priv->hash);
	pk_backend_job_set_percentage (plugin->job, 101);

	/* first go through the existing data, and look for
	 * modifications and removals */
	statement = g_strdup ("SELECT filename, md5 FROM cache");
	rc = sqlite3_exec (plugin->priv->db,
			   statement,
			   pk_plugin_sqlite_cache_rescan_cb,
			   plugin,
			   &error_msg);
	g_free (statement);
	if (rc != SQLITE_OK) {
		g_warning ("SQL error: %s\n", error_msg);
		sqlite3_free (error_msg);
		goto out;
	}

	array = g_ptr_array_new_with_free_func (g_free);
	pk_plugin_get_desktop_files (plugin,
				     PK_DESKTOP_DEFAULT_APPLICATION_DIR,
				     array);

	if (array->len) {
		step = 100.0f / array->len;
		pk_backend_job_set_status (plugin->job,
				       PK_STATUS_ENUM_GENERATE_PACKAGE_LIST);

		/* process files in an array */
		for (i=0; i<array->len; i++) {
			pk_backend_job_set_percentage (plugin->job, i * step);
			path = g_ptr_array_index (array, i);
			pk_plugin_sqlite_add_filename (plugin,
						       path,
						       NULL);
		}
	}

	pk_backend_job_set_percentage (plugin->job, 100);
	pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_FINISHED);
out:
	if (array != NULL)
		g_ptr_array_unref (array);
}
Esempio n. 9
0
static void
pk_opkg_package_list_cb (pkg_t *pkg, void *data)
{
	SearchParams *params = (SearchParams*) data;
	gchar *uid;
	gchar *haystack;
	gint status, match;
	PkBitfield filters = params->filters;

	if (!pkg->name)
		return;

	switch (params->search_type)
	{
		case SEARCH_NAME:
			if (!pkg->name)
				return;
			haystack = g_utf8_strdown (pkg->name, -1);
			match = (g_strrstr (haystack, params->needle) != NULL);
			g_free (haystack);
			if (!match)
				return;
			break;
		case SEARCH_DESCRIPTION:
			if (!pkg->description)
				return;
			haystack = g_utf8_strdown (pkg->description, -1);
			match = (g_strrstr (haystack, params->needle) != NULL);
			g_free (haystack);
			if (!match)
				return;
			break;
		case SEARCH_TAG:
			if (!pkg->tags)
				return;
			if (!g_strrstr (pkg->tags, params->needle))
				return;
			break;
	}

	uid = g_strdup_printf ("%s;%s;%s;",
		pkg->name, pkg->version, pkg->architecture);

	if (pkg->state_status == SS_INSTALLED)
		status = PK_INFO_ENUM_INSTALLED;
	else
		status = PK_INFO_ENUM_AVAILABLE;

	/* check filters */

	if (pk_bitfield_contain(filters, PK_FILTER_ENUM_DEVELOPMENT) && 
		!opkg_is_devel_pkg (pkg))
		goto end_handle;
	if (pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_DEVELOPMENT) && 
		opkg_is_devel_pkg (pkg))
		goto end_handle;
	if (pk_bitfield_contain(filters, PK_FILTER_ENUM_GUI) && 
		!opkg_is_gui_pkg (pkg))
		goto end_handle;
	if (pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_GUI) && 
		opkg_is_gui_pkg (pkg))
		goto end_handle;
	if (pk_bitfield_contain(filters, PK_FILTER_ENUM_INSTALLED) && 
		(pkg->state_status != SS_INSTALLED))
		goto end_handle;
	if (pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_INSTALLED) && 
		(pkg->state_status == SS_INSTALLED))
		goto end_handle;

	pk_backend_job_package (params->backend, status, uid, pkg->description);

end_handle:
	g_free(uid);

}
Esempio n. 10
0
/**
 * dnf_emit_package_list_filter:
 */
void
dnf_emit_package_list_filter (PkBackendJob *job,
			      PkBitfield filters,
			      GPtrArray *pkglist)
{
	DnfPackage *found;
	DnfPackage *pkg;
	guint i;
	g_autoptr(GHashTable) hash_cost = NULL;
	g_autoptr(GHashTable) hash_installed = NULL;

	/* if a package exists in multiple repos, show the one with the lowest
	 * cost of downloading */
	hash_cost = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	for (i = 0; i < pkglist->len; i++) {
		pkg = g_ptr_array_index (pkglist, i);
		if (dnf_package_installed (pkg))
			continue;

		/* if the NEVRA does not already exist in the array, just add */
		found = g_hash_table_lookup (hash_cost,
					     dnf_package_get_nevra (pkg));
		if (found == NULL) {
			g_hash_table_insert (hash_cost,
					     g_strdup (dnf_package_get_nevra (pkg)),
					     (gpointer) pkg);
			continue;
		}

		/* a lower cost package */
		if (dnf_package_get_cost (pkg) < dnf_package_get_cost (found)) {
			dnf_package_set_info (found, PK_INFO_ENUM_BLOCKED);
			g_hash_table_replace (hash_cost,
					      g_strdup (dnf_package_get_nevra (pkg)),
					      (gpointer) pkg);
		} else {
			dnf_package_set_info (pkg, PK_INFO_ENUM_BLOCKED);
		}
	}

	/* add all the installed packages to a hash */
	hash_installed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	for (i = 0; i < pkglist->len; i++) {
		pkg = g_ptr_array_index (pkglist, i);
		if (!dnf_package_installed (pkg))
			continue;
		g_hash_table_insert (hash_installed,
				     g_strdup (dnf_package_get_nevra (pkg)),
				     (gpointer) pkg);
	}

	/* anything remote in metadata-only mode needs to be unavailable */
	for (i = 0; i < pkglist->len; i++) {
		DnfRepo *repo;
		pkg = g_ptr_array_index (pkglist, i);
		if (dnf_package_installed (pkg))
			continue;
		repo = dnf_package_get_repo (pkg);
		if (repo == NULL)
			continue;
		if (dnf_repo_get_enabled (repo) != DNF_REPO_ENABLED_METADATA)
			continue;
		dnf_package_set_info (pkg, PK_INFO_ENUM_UNAVAILABLE);
	}

	for (i = 0; i < pkglist->len; i++) {
		pkg = g_ptr_array_index (pkglist, i);

		/* blocked */
		if ((PkInfoEnum) dnf_package_get_info (pkg) == PK_INFO_ENUM_BLOCKED)
			continue;

		/* GUI */
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_GUI) && !dnf_package_is_gui (pkg))
			continue;
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_GUI) && dnf_package_is_gui (pkg))
			continue;

		/* DEVELOPMENT */
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_DEVELOPMENT) && !dnf_package_is_devel (pkg))
			continue;
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_DEVELOPMENT) && dnf_package_is_devel (pkg))
			continue;

		/* DOWNLOADED */
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_DOWNLOADED) && !dnf_package_is_downloaded (pkg))
			continue;
		if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_DOWNLOADED) && dnf_package_is_downloaded (pkg))
			continue;

		/* if this package is available and the very same NEVRA is
		 * installed, skip this package */
		if (!dnf_package_installed (pkg)) {
			found = g_hash_table_lookup (hash_installed,
						     dnf_package_get_nevra (pkg));
			if (found != NULL)
				continue;
		}

		dnf_emit_package (job, PK_INFO_ENUM_UNKNOWN, pkg);
	}
}