예제 #1
0
/**
 * pk_plugin_transaction_get_updates:
 */
static void
pk_plugin_transaction_get_updates (PkTransaction *transaction)
{
    gchar *path;
    GPtrArray *array;
    PkResults *results;

    results = pk_transaction_get_results (transaction);
    path = g_build_filename (LOCALSTATEDIR,
                             "lib",
                             "PackageKit",
                             "prepared-update",
                             NULL);
    array = pk_results_get_package_array (results);
    if (array->len != 0) {
        g_debug ("got %i updates, so ignoring %s",
                 array->len, path);
        goto out;
    }
    if (g_file_test (path, G_FILE_TEST_EXISTS)) {
        g_debug ("Removing %s as no updates", path);
        g_unlink (path);
    } else {
        g_debug ("No %s present, so no need to delete", path);
    }
out:
    g_free (path);
    g_ptr_array_unref (array);
}
/**
 * pk_plugin_transaction_get_updates:
 */
static void
pk_plugin_transaction_get_updates (PkTransaction *transaction)
{
	GPtrArray *array;
	PkResults *results;

	results = pk_transaction_get_results (transaction);
	array = pk_results_get_package_array (results);
	if (array->len != 0) {
		g_debug ("got %i updates, so ignoring %s",
			 array->len, PK_OFFLINE_PREPARED_UPDATE_FILENAME);
		goto out;
	}
	if (g_file_test (PK_OFFLINE_PREPARED_UPDATE_FILENAME,
			 G_FILE_TEST_EXISTS)) {
		g_debug ("Removing %s as no updates",
			 PK_OFFLINE_PREPARED_UPDATE_FILENAME);
		g_unlink (PK_OFFLINE_PREPARED_UPDATE_FILENAME);
	} else {
		g_debug ("No %s present, so no need to delete",
			 PK_OFFLINE_PREPARED_UPDATE_FILENAME);
	}
out:
	g_ptr_array_unref (array);
}
예제 #3
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_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 */
	g_debug ("processing %i packags for desktop files", list->len);
	if (list->len == 0)
		goto out;

	/* 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)
{
	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;
}