/**
 * pk_plugin_transaction_action_method:
 */
static void
pk_plugin_transaction_action_method (PkPlugin *plugin,
				     PkTransaction *transaction,
				     PkResults *results)
{
	GPtrArray *invalidated = NULL;
	PkPackage *pkg;
	PkPackageSack *sack;
	const gchar *package_id;
	gchar **package_ids;
	guint i;

	/* get the existing prepared updates */
	sack = pk_plugin_get_existing_prepared_updates (PK_OFFLINE_PREPARED_UPDATE_FILENAME);
	if (pk_package_sack_get_size (sack) == 0)
		goto out;

	/* are there any requested packages that match in prepared-updates */
	package_ids = pk_transaction_get_package_ids (transaction);
	for (i = 0; package_ids[i] != NULL; i++) {
		pkg = pk_package_sack_find_by_id_name_arch (sack, package_ids[i]);
		if (pkg != NULL) {
			g_debug ("%s modified %s, invalidating prepared-updates",
				 package_ids[i], pk_package_get_id (pkg));
			pk_plugin_state_changed (plugin);
			g_object_unref (pkg);
			goto out;
		}
	}

	/* are there any changed deps that match a package in prepared-updates */
	invalidated = pk_results_get_package_array (results);
	for (i = 0; i < invalidated->len; i++) {
		package_id = pk_package_get_id (g_ptr_array_index (invalidated, i));
		pkg = pk_package_sack_find_by_id_name_arch (sack, package_id);
		if (pkg != NULL) {
			g_debug ("%s modified %s, invalidating prepared-updates",
				 package_id, pk_package_get_id (pkg));
			pk_plugin_state_changed (plugin);
			g_object_unref (pkg);
			goto out;
		}
	}
out:
	if (invalidated != NULL)
		g_ptr_array_unref (invalidated);
	g_object_unref (sack);
}
Exemplo n.º 2
0
/**
 * 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;

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

    /* check for success */
    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 only-download then update prepared-updates */
    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_UPDATE_PACKAGES ||
            role == PK_ROLE_ENUM_INSTALL_PACKAGES ||
            role == PK_ROLE_ENUM_REMOVE_PACKAGES ||
            role == PK_ROLE_ENUM_REFRESH_CACHE) {
        pk_plugin_state_changed (plugin);
    }
out:
    return;
}
/**
 * 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;
}