Exemple #1
0
/**
 * pk_package_sack_remove_by_filter:
 * @sack: a valid #PkPackageSack instance
 * @filter_cb: (scope call): a #PkPackageSackFilterFunc, which returns %TRUE for the #PkPackage's to retain
 * @user_data: user data to pass to @filter_cb
 *
 * Removes from the package sack any packages that return %FALSE from the filter
 * function.
 *
 * Return value: %TRUE if a package was removed from the sack
 *
 * Since: 0.6.3
 **/
gboolean
pk_package_sack_remove_by_filter (PkPackageSack *sack,
				  PkPackageSackFilterFunc filter_cb,
				  gpointer user_data)
{
	gboolean ret = FALSE;
	PkPackage *package;
	gint i;
	PkPackageSackPrivate *priv = sack->priv;

	g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE);
	g_return_val_if_fail (filter_cb != NULL, FALSE);

	/* add each that matches the info enum */
	for (i = 0; i < (gint) priv->array->len; i++) {
		package = g_ptr_array_index (priv->array, i);
		if (!filter_cb (package, user_data)) {
			ret = TRUE;
			pk_package_sack_remove_package (sack, package);

			/* ensure we pick up subsequent matches */
			i--;
		}
	}
	return ret;
}
/**
 * pk_package_sack_remove_package_by_id:
 * @sack: a valid #PkPackageSack instance
 * @package_id: a package_id descriptor
 *
 * Removes a package reference from the sack. As soon as one package is removed
 * the search is stopped.
 *
 * Return value: %TRUE if the package was removed from the sack
 *
 * Since: 0.5.2
 **/
gboolean
pk_package_sack_remove_package_by_id (PkPackageSack *sack,
				      const gchar *package_id)
{
	PkPackage *package;
	guint i;
	GPtrArray *array;

	g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE);
	g_return_val_if_fail (package_id != NULL, FALSE);

	array = sack->priv->array;
	for (i = 0; i < array->len; i++) {
		package = g_ptr_array_index (array, i);
		if (g_strcmp0 (package_id, pk_package_get_id (package)) == 0) {
			pk_package_sack_remove_package (sack, package);
			return TRUE;
		}
	}
	return FALSE;
}