Ejemplo n.º 1
0
static gboolean
backend_get_depends_requires_thread (PkBackend *backend)
{
	GList *list = NULL;
	sqlite3 *db;
	gchar **package_ids;
	int deps_type;
        gchar **package_id_data;

	db = db_open ();
	package_ids = pk_backend_get_strv (backend, "package_ids");
	deps_type = pk_backend_get_uint (backend, "type");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	if (deps_type == DEPS_TYPE_DEPENDS)
		list = box_db_repos_get_depends (db, package_id_data[PK_PACKAGE_ID_NAME]);
	else if (deps_type == DEPS_TYPE_REQUIRES)
		list = box_db_repos_get_requires (db, package_id_data[PK_PACKAGE_ID_NAME]);

	add_packages_from_list (backend, list, FALSE);
	box_db_repos_package_list_free (list);

	db_close (db);

	pk_backend_finished (backend);
	return TRUE;
}
Ejemplo n.º 2
0
static void
backend_install_packages_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	gint err, i;
	gchar **package_ids;
	gchar **parts;

	package_ids = pk_backend_get_strv (backend, "pkids");

	err = 0;

	for (i = 0; package_ids[i]; i++)
	{
		pk_backend_job_package (job, PK_INFO_ENUM_INSTALLING, package_ids[i], NULL);

		parts = pk_package_id_split (package_ids[i]);

		err = opkg_install_package (parts[PK_PACKAGE_ID_NAME], pk_opkg_progress_cb, backend);
		if (err)
			handle_install_error (backend, err);

		g_strfreev (parts);
		if (err != 0)
			break;
	}

	pk_backend_job_finished (job);
}
Ejemplo n.º 3
0
static gboolean
pk_backend_resolve_thread (PkBackend *self)
{
	gchar **packages;
	GError *error = NULL;

	g_return_val_if_fail (self != NULL, FALSE);

	packages = pk_backend_get_strv (self, "package_ids");

	g_return_val_if_fail (packages != NULL, FALSE);

	for (; *packages != NULL; ++packages) {
		if (pk_backend_cancelled (self)) {
			break;
		}

		/* find a package with the given id or name */
		if (pk_package_id_check (*packages)) {
			if (!pk_backend_resolve_package (self, *packages,
							 &error)) {
				break;
			}
		} else {
			if (!pk_backend_resolve_name (self, *packages,
						      &error)) {
				break;
			}
		}
	}

	return pk_backend_finish (self, error);
}
Ejemplo n.º 4
0
static gboolean
backend_get_details_thread (PkBackend *backend)
{
	PackageSearch *ps;
	GList *list;
	sqlite3 *db;
	gchar **package_ids;
	gchar **package_id_data;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	db = db_open ();

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	/* only one element is returned */
	list = box_db_repos_packages_search_by_data (db, package_id_data[PK_PACKAGE_ID_NAME], package_id_data[PK_PACKAGE_ID_VERSION]);

	if (list == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "cannot find package by id");
		db_close (db);
		return FALSE;
	}
	ps = (PackageSearch*) list->data;

	pk_backend_details (backend, package_ids[0], "unknown", PK_GROUP_ENUM_OTHER, ps->description, "", 0);

	box_db_repos_package_list_free (list);

	db_close (db);
	pk_backend_finished (backend);
	return TRUE;
}
Ejemplo n.º 5
0
static gboolean
backend_install_packages_thread (PkBackend *backend)
{
	gint err, i;
	gchar **package_ids;
	gchar **parts;

	package_ids = pk_backend_get_strv (backend, "pkids");

	err = 0;

	for (i = 0; package_ids[i]; i++)
	{
		pk_backend_package (backend, PK_INFO_ENUM_INSTALLING, package_ids[i], NULL);

		parts = pk_package_id_split (package_ids[i]);

		err = opkg_install_package (parts[PK_PACKAGE_ID_NAME], pk_opkg_progress_cb, backend);
		if (err)
			handle_install_error (backend, err);

		g_strfreev (parts);
		if (err != 0)
			break;
	}

	pk_backend_finished (backend);
	return (err == 0);
}
static gboolean
pk_backend_depends_on_thread (PkBackend *self)
{
	gchar **packages;
	alpm_list_t *i, *pkgs = NULL;
	GError *error = NULL;

	g_return_val_if_fail (self != NULL, FALSE);

	packages = pk_backend_get_strv (self, "package_ids");

	g_return_val_if_fail (packages != NULL, FALSE);

	/* construct an initial package list */
	for (; *packages != NULL; ++packages) {
		alpm_pkg_t *pkg;

		if (pk_backend_cancelled (self)) {
			break;
		}

		pkg = pk_backend_find_pkg (self, *packages, &error);
		if (pkg == NULL) {
			break;
		}

		pkgs = alpm_list_add (pkgs, pkg);
	}

	/* package list might be modified along the way but that is ok */
	for (i = pkgs; i != NULL; i = i->next) {
		const alpm_list_t *depends;

		if (pk_backend_cancelled (self) || error != NULL) {
			break;
		}

		depends = alpm_pkg_depends_on (i->data);
		for (; depends != NULL; depends = depends->next) {
			gchar *depend;

			if (pk_backend_cancelled (self) || error != NULL) {
				break;
			}

			depend = alpm_dep_compute_string (depends->data);
			pkgs = pk_backend_find_provider (self, pkgs, depend,
							 &error);
			free (depend);
		}
	}

	alpm_list_free (pkgs);
	return pk_backend_finish (self, NULL);
}
static gboolean
pk_backend_required_by_thread (PkBackend *self)
{
	gchar **packages;
	alpm_list_t *i, *pkgs = NULL;
	GError *error = NULL;

	g_return_val_if_fail (self != NULL, FALSE);

	packages = pk_backend_get_strv (self, "package_ids");

	g_return_val_if_fail (packages != NULL, FALSE);

	/* construct an initial package list */
	for (; *packages != NULL; ++packages) {
		alpm_pkg_t *pkg;

		if (pk_backend_cancelled (self)) {
			break;
		}

		pkg = pk_backend_find_pkg (self, *packages, &error);
		if (pkg == NULL) {
			break;
		}

		pkgs = alpm_list_add (pkgs, pkg);
	}

	/* package list might be modified along the way but that is ok */
	for (i = pkgs; i != NULL; i = i->next) {
		alpm_list_t *requiredby;

		if (pk_backend_cancelled (self) || error != NULL) {
			break;
		}

		requiredby = alpm_pkg_compute_requiredby (i->data);
		for (; requiredby != NULL; requiredby = requiredby->next) {
			if (pk_backend_cancelled (self) || error != NULL) {
				break;
			}

			pkgs = pk_backend_find_requirer (self, pkgs,
							 requiredby->data,
							 &error);
		}

		FREELIST (requiredby);
	}

	alpm_list_free (pkgs);
	return pk_backend_finish (self, error);
}
Ejemplo n.º 8
0
static gboolean
backend_get_files_thread (PkBackend *backend)
{
	gchar **package_ids;
	gchar *pi;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	if (package_ids == NULL) {
		pk_backend_error_code (backend,
				       PK_ERROR_ENUM_PACKAGE_ID_INVALID,
				       "Invalid package id");
		pk_backend_finished (backend);
		return false;
	}

	aptcc *m_apt = new aptcc(backend, _cancel);
	pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
	if (m_apt->init()) {
		egg_debug ("Failed to create apt cache");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	for (uint i = 0; i < g_strv_length(package_ids); i++) {
		pi = package_ids[i];
		if (pk_package_id_check(pi) == false) {
			pk_backend_error_code (backend,
					       PK_ERROR_ENUM_PACKAGE_ID_INVALID,
					       pi);
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver;
		pkg_ver = m_apt->find_package_id(pi);
		if (pkg_ver.second.end() == true)
		{
			pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find package");
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		emit_files (backend, pi);
	}

	delete m_apt;
	pk_backend_finished (backend);
	return true;
}
Ejemplo n.º 9
0
static void
backend_install_files_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	gboolean result;
	gchar **full_paths;

	pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY);

	full_paths = pk_backend_get_strv (backend, "full_paths");
	result = box_package_install (full_paths[0], ROOT_DIRECTORY, common_progress, backend, FALSE);

	pk_backend_job_finished (job);

	return result;
}
Ejemplo n.º 10
0
static gboolean
backend_install_files_thread (PkBackend *backend)
{
	gboolean result;
	gchar **full_paths;

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	full_paths = pk_backend_get_strv (backend, "full_paths");
	result = box_package_install (full_paths[0], ROOT_DIRECTORY, common_progress, backend, FALSE);

	pk_backend_finished (backend);

	return result;
}
Ejemplo n.º 11
0
/**
 * backend_get_details:
 */
static gboolean
backend_get_details_thread (PkBackend *backend)
{
	gchar **package_ids;
        gchar **parts;
	int group_index;
	PkGroupEnum group = 0;
	pkg_t *pkg;
	gchar *newid;

        package_ids = pk_backend_get_strv(backend, "package_ids");
	parts = pk_package_id_split (package_ids[0]);

	if (!parts)
	{
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
		pk_backend_finished (backend);
		return FALSE;
	}

	pkg = opkg_find_package (parts[PK_PACKAGE_ID_NAME], parts[PK_PACKAGE_ID_VERSION], parts[PK_PACKAGE_ID_ARCH], parts[PK_PACKAGE_ID_DATA]);
	g_strfreev (parts);

	if (!pkg)
	{
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL);
		pk_backend_finished (backend);
		return FALSE;
	}

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

	if (pkg->tags) {
		for (group_index = 0; group < PK_GROUP_ENUM_LAST; group_index++) {
			group = 1 << group_index;
			if (!(group & backend_get_groups(backend))) continue;
			if (opkg_check_tag(pkg, (const gchar *)pk_group_enum_to_string(group))) 
				break;
		}
	}

	pk_backend_details (backend, newid, NULL, group, pkg->description, NULL, pkg->size);
	g_free (newid);
	pk_backend_finished (backend);
	return TRUE;
}
Ejemplo n.º 12
0
static gboolean
pk_backend_get_files_thread (PkBackend *self)
{
	gchar **packages;
	GError *error = NULL;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (alpm != NULL, FALSE);

	packages = pk_backend_get_strv (self, "package_ids");

	g_return_val_if_fail (packages != NULL, FALSE);

	for (; *packages != NULL; ++packages) {
		alpm_pkg_t *pkg;
		const gchar *root;

		GString *files;
		alpm_filelist_t *filelist;
		gsize i;

		if (pk_backend_cancelled (self)) {
			break;
		}

		pkg = pk_backend_find_pkg (self, *packages, &error);
		if (pkg == NULL) {
			break;
		}

		root = alpm_option_get_root (alpm);
		files = g_string_new ("");

		filelist = alpm_pkg_get_files (pkg);
		for (i = 0; i < filelist->count; ++i) {
			const gchar *file = filelist->files[i].name;
			g_string_append_printf (files, "%s%s;", root, file);
		}

		g_string_truncate (files, MAX (files->len, 1) - 1);
		pk_backend_job_files (self, *packages, files->str);
		g_string_free (files, TRUE);
	}

	return pk_backend_finish (self, error);
}
Ejemplo n.º 13
0
static void
backend_update_packages_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	gboolean result = TRUE;
	gchar **package_ids;
	size_t i;

	pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY);
	/* FIXME: support only_trusted */
	package_ids = pk_backend_get_strv (backend, "package_ids");

	for (i = 0; i < g_strv_length (package_ids); i++)
	{
		result |= box_package_install (package_ids[i], ROOT_DIRECTORY, common_progress, backend, FALSE);
	}

	pk_backend_job_finished (job);
}
Ejemplo n.º 14
0
static void
backend_remove_packages_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	gchar **package_ids;
	gchar **package_id_data;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	pk_backend_job_set_status (job, PK_STATUS_ENUM_REMOVE);

	if (!box_package_uninstall (package_id_data[PK_PACKAGE_ID_NAME], ROOT_DIRECTORY, common_progress, backend, FALSE))
	{
		pk_backend_job_error_code (job, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Cannot uninstall");
	}

	pk_backend_finished (backend);
}
Ejemplo n.º 15
0
static gboolean
backend_update_packages_thread (PkBackend *backend)
{
	gboolean result = TRUE;
	gchar **package_ids;
	size_t i;

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	/* FIXME: support only_trusted */
	package_ids = pk_backend_get_strv (backend, "package_ids");

	for (i = 0; i < g_strv_length (package_ids); i++)
	{
		result |= box_package_install (package_ids[i], ROOT_DIRECTORY, common_progress, backend, FALSE);
	}

	pk_backend_finished (backend);
	return result;
}
Ejemplo n.º 16
0
static gboolean
backend_remove_packages_thread (PkBackend *backend)
{
	gchar **package_ids;
	gchar **package_id_data;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	pk_backend_set_status (backend, PK_STATUS_ENUM_REMOVE);

	if (!box_package_uninstall (package_id_data[PK_PACKAGE_ID_NAME], ROOT_DIRECTORY, common_progress, backend, FALSE))
	{
		pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Cannot uninstall");
	}

	pk_backend_finished (backend);
	return TRUE;
}
Ejemplo n.º 17
0
static PacmanList *
backend_remove_list_targets (PkBackend *backend)
{
	gchar **package_ids;
	guint iterator;
	PacmanList *list = NULL;

	g_return_val_if_fail (backend != NULL, NULL);

	package_ids = pk_backend_get_strv (backend, "package_ids");

	g_return_val_if_fail (package_ids != NULL, NULL);

	for (iterator = 0; package_ids[iterator] != NULL; ++iterator) {
		gchar **package_id_data = pk_package_id_split (package_ids[iterator]);
		list = pacman_list_add (list, g_strdup (package_id_data[PK_PACKAGE_ID_NAME]));
		g_strfreev (package_id_data);
	}

	return list;
}
Ejemplo n.º 18
0
static gboolean
pk_backend_transaction_add_targets (PkBackend *self, GError **error)
{
	gchar **paths;

	g_return_val_if_fail (self != NULL, FALSE);

	paths = pk_backend_get_strv (self, "full_paths");

	g_return_val_if_fail (paths != NULL, FALSE);

	for (; *paths != NULL; ++paths) {
		if (alpm_add_file (*paths) < 0) {
			alpm_errno_t errno = alpm_errno (alpm);
			g_set_error (error, ALPM_ERROR, errno, "%s: %s",
				     *paths, alpm_strerror (errno));
			return FALSE;
		}
	}

	return TRUE;
}
Ejemplo n.º 19
0
static void
backend_get_files_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	gchar *files;
	sqlite3 *db;
	gchar **package_ids;
	gchar **package_id_data;

	db = db_open();
	package_ids = pk_backend_get_strv (backend, "package_ids");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY);

	files = box_db_repos_get_files_string (db, package_id_data[PK_PACKAGE_ID_NAME], package_id_data[PK_PACKAGE_ID_VERSION]);
	pk_backend_job_files (job, package_ids[0], files);

	db_close (db);
	g_free (files);

	pk_backend_finished (backend);
}
Ejemplo n.º 20
0
static gboolean
backend_get_files_thread (PkBackend *backend)
{
	gchar *files;
	sqlite3 *db;
	gchar **package_ids;
	gchar **package_id_data;

	db = db_open();
	package_ids = pk_backend_get_strv (backend, "package_ids");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	files = box_db_repos_get_files_string (db, package_id_data[PK_PACKAGE_ID_NAME], package_id_data[PK_PACKAGE_ID_VERSION]);
	pk_backend_files (backend, package_ids[0], files);

	db_close (db);
	g_free (files);

	pk_backend_finished (backend);
	return TRUE;
}
Ejemplo n.º 21
0
static gboolean
backend_manage_packages_thread (PkBackend *backend)
{
	gchar **package_ids;
	gchar *pi;
	bool simulate;
	bool remove;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	simulate = pk_backend_get_bool (backend, "simulate");
	remove = pk_backend_get_bool (backend, "remove");

	pk_backend_set_allow_cancel (backend, true);

	aptcc *m_apt = new aptcc(backend, _cancel);
	pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
	if (m_apt->init()) {
		egg_debug ("Failed to create apt cache");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > pkgs;
	for (uint i = 0; i < g_strv_length(package_ids); i++) {
		if (_cancel) {
			break;
		}

		pi = package_ids[i];
		if (pk_package_id_check(pi) == false) {
			pk_backend_error_code (backend,
					       PK_ERROR_ENUM_PACKAGE_ID_INVALID,
					       pi);
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver;
		pkg_ver = m_apt->find_package_id(pi);
		// Ignore packages that could not be found or that exist only due to dependencies.
		if (pkg_ver.second.end() == true)
		{
			pk_backend_error_code (backend,
					       PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
					       "couldn't find package");

			delete m_apt;
			pk_backend_finished (backend);
			return false;
		} else {
			pkgs.push_back(pkg_ver);
		}
	}

	if (!m_apt->runTransaction(pkgs, simulate, remove)) {
		// Print transaction errors
		cout << "runTransaction failed" << endl;
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	delete m_apt;
	pk_backend_finished (backend);
	return true;
}
Ejemplo n.º 22
0
/**
 * backend_download_packages_thread:
 */
static gboolean
backend_download_packages_thread (PkBackend *backend)
{
	gchar **package_ids;
	string directory;

	package_ids = pk_backend_get_strv(backend, "package_ids");
	directory = _config->FindDir("Dir::Cache::archives") + "partial/";
	pk_backend_set_allow_cancel (backend, true);

	aptcc *m_apt = new aptcc(backend, _cancel);
	pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
	if (m_apt->init()) {
		egg_debug ("Failed to create apt cache");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	// Create the progress
	AcqPackageKitStatus Stat(m_apt, backend, _cancel);

	// get a fetcher
	pkgAcquire fetcher(&Stat);
	string filelist;
	gchar *pi;

	// TODO this might be useful when the item is in the cache
// 	for (pkgAcquire::ItemIterator I = fetcher.ItemsBegin(); I < fetcher.ItemsEnd();)
// 	{
// 		if ((*I)->Local == true)
// 		{
// 			I++;
// 			continue;
// 		}
//
// 		// Close the item and check if it was found in cache
// 		(*I)->Finished();
// 		if ((*I)->Complete == false) {
// 			Transient = true;
// 		}
//
// 		// Clear it out of the fetch list
// 		delete *I;
// 		I = fetcher.ItemsBegin();
// 	}

	for (uint i = 0; i < g_strv_length(package_ids); i++) {
		pi = package_ids[i];
		if (pk_package_id_check(pi) == false) {
			pk_backend_error_code (backend,
					       PK_ERROR_ENUM_PACKAGE_ID_INVALID,
					       pi);
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		if (_cancel) {
			break;
		}

		pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver;
		pkg_ver = m_apt->find_package_id(pi);
		// Ignore packages that could not be found or that exist only due to dependencies.
		if (pkg_ver.second.end() == true)
		{
			_error->Error("Can't find this package id \"%s\".", pi);
			continue;
		} else {
			if(!pkg_ver.second.Downloadable()) {
				_error->Error("No downloadable files for %s,"
					      "perhaps it is a local or obsolete" "package?",
					      pi);
				continue;
			}

			string storeFileName;
			if (get_archive(&fetcher,
					m_apt->packageSourceList,
					m_apt->packageRecords,
					pkg_ver.second,
					directory,
					storeFileName))
			{
				Stat.addPackagePair(pkg_ver);
			}
			string destFile = directory + "/" + flNotDir(storeFileName);
			if (filelist.empty()) {
				filelist = destFile;
			} else {
				filelist.append(";" + destFile);
			}
		}
	}

	if (fetcher.Run() != pkgAcquire::Continue
	    && _cancel == false)
	// We failed and we did not cancel
	{
		show_errors(backend, PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED);
		delete m_apt;
		pk_backend_finished (backend);
		return _cancel;
	}

	// send the filelist
	pk_backend_files(backend, NULL, filelist.c_str());

	delete m_apt;
	pk_backend_finished (backend);
	return true;
}
Ejemplo n.º 23
0
static gboolean
backend_resolve_thread (PkBackend *backend)
{
	gchar **package_ids;
	PkBitfield filters;

	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");
	package_ids = pk_backend_get_strv (backend, "package_ids");
	pk_backend_set_allow_cancel (backend, true);

	aptcc *m_apt = new aptcc(backend, _cancel);
	pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
	if (m_apt->init()) {
		egg_debug ("Failed to create apt cache");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	gchar *pi;
	vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output;
	for (uint i = 0; i < g_strv_length(package_ids); i++) {
		if (_cancel) {
			break;
		}

		pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver;
		pi = package_ids[i];
		if (pk_package_id_check(pi) == false) {
			pkg_ver.first = m_apt->packageCache->FindPkg(pi);
			// Ignore packages that could not be found or that exist only due to dependencies.
			if (pkg_ver.first.end() == true ||
			    (pkg_ver.first.VersionList().end() && pkg_ver.first.ProvidesList().end()))
			{
				continue;
			}

			pkg_ver.second = m_apt->find_ver(pkg_ver.first);
			// check to see if the provided package isn't virtual too
			if (pkg_ver.second.end() == false)
			{
				output.push_back(pkg_ver);
			}

			pkg_ver.second = m_apt->find_candidate_ver(pkg_ver.first);
			// check to see if the provided package isn't virtual too
			if (pkg_ver.second.end() == false)
			{
				output.push_back(pkg_ver);
			}
		} else {
			pkg_ver = m_apt->find_package_id(pi);
			// check to see if we found the package
			if (pkg_ver.second.end() == false)
			{
				output.push_back(pkg_ver);
			}
		}
	}
	// It's faster to emmit the packages here rather than in the matching part
	m_apt->emit_packages(output, filters);

	delete m_apt;

	pk_backend_finished (backend);
	return true;
}
Ejemplo n.º 24
0
static gboolean
pk_backend_get_details_thread (PkBackend *self)
{
	gchar **packages;
	GError *error = NULL;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (localdb != NULL, FALSE);

	packages = pk_backend_get_strv (self, "package_ids");

	g_return_val_if_fail (packages != NULL, FALSE);

	for (; *packages != NULL; ++packages) {
		alpm_pkg_t *pkg;
		const alpm_list_t *i;

		GString *licenses;
		PkGroupEnum group;
		const gchar *desc, *url;
		gulong size;

		if (pk_backend_cancelled (self)) {
			break;
		}

		pkg = pk_backend_find_pkg (self, *packages, &error);
		if (pkg == NULL) {
			break;
		}

		i = alpm_pkg_get_licenses (pkg);
		if (i == NULL) {
			licenses = g_string_new ("Unknown");
		} else {
			licenses = g_string_new ((const gchar *) i->data);
			while ((i = i->next) != NULL) {
				const gchar *license = (const gchar *) i->data;
				/* assume OR although it may not be correct */
				g_string_append_printf (licenses, " or %s",
							license);
			}
		}

		group = pk_group_enum_from_string (alpm_pkg_get_group (pkg));
		desc = alpm_pkg_get_desc (pkg);
		url = alpm_pkg_get_url (pkg);

		if (alpm_pkg_get_origin (pkg) == ALPM_PKG_FROM_LOCALDB) {
			size = alpm_pkg_get_isize (pkg);
		} else {
			size = alpm_pkg_download_size (pkg);
		}

		pk_backend_job_details (self, *packages, licenses->str, group,
					desc, url, size);
		g_string_free (licenses, TRUE);
	}

	return pk_backend_finish (self, error);
}
Ejemplo n.º 25
0
static gboolean
backend_get_depends_or_requires_thread (PkBackend *backend)
{
	gchar **package_ids;
	PkBitfield filters;
	gchar *pi;
	bool recursive;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");
	recursive = pk_backend_get_bool (backend, "recursive");

	pk_backend_set_allow_cancel (backend, true);

	aptcc *m_apt = new aptcc(backend, _cancel);
	pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
	if (m_apt->init()) {
		egg_debug ("Failed to create apt cache");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	bool depends = pk_backend_get_bool(backend, "get_depends");

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output;
	for (uint i = 0; i < g_strv_length(package_ids); i++) {
		if (_cancel) {
			break;
		}
		pi = package_ids[i];
		if (pk_package_id_check(pi) == false) {
			pk_backend_error_code (backend,
					       PK_ERROR_ENUM_PACKAGE_ID_INVALID,
					       pi);
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		pair<pkgCache::PkgIterator, pkgCache::VerIterator> pkg_ver;
		pkg_ver = m_apt->find_package_id(pi);
		if (pkg_ver.second.end() == true)
		{
			pk_backend_error_code (backend,
					       PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
					       "Couldn't find package");
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		if (depends) {
			m_apt->get_depends(output, pkg_ver.first, recursive);
		} else {
			m_apt->get_requires(output, pkg_ver.first, recursive);
		}
	}

	// It's faster to emmit the packages here than in the matching part
	m_apt->emit_packages(output, filters);

	delete m_apt;
	pk_backend_finished (backend);
	return true;
}
Ejemplo n.º 26
0
static gboolean
backend_get_update_detail_thread (PkBackend *backend)
{
	guint iterator;

	gchar **package_ids;

	g_return_val_if_fail (local_database != NULL, FALSE);
	g_return_val_if_fail (backend != NULL, FALSE);

	package_ids = pk_backend_get_strv (backend, "package_ids");

	g_return_val_if_fail (package_ids != NULL, FALSE);

	/* collect details about updates */
	for (iterator = 0; package_ids[iterator] != NULL; ++iterator) {
		PacmanPackage *package, *upgrades;
		PacmanDatabase *database;

		gchar *upgrades_id, *replaces_ids, *vendor_url;
		const gchar *message;

		PkRestartEnum restart;
		PkUpdateStateEnum state;

		GTimeVal built = { 0 }, installed = { 0 };
		gchar *issued, *updated;

		if (backend_cancelled (backend)) {
			break;
		}

		package = backend_get_package (backend, package_ids[iterator]);
		if (package == NULL) {
			backend_finished (backend);
			return FALSE;
		}

		upgrades = pacman_database_find_package (local_database, pacman_package_get_name (package));
		if (upgrades != NULL) {
			upgrades_id = pacman_package_make_id (upgrades);
			if (pacman_package_compare_pkgver (package, upgrades) != 0) {
				message = "Update to newest upstream version";
			} else {
				message = "Update to newest release";
			}
		} else {
			upgrades_id = NULL;
			message = "Install as a replacement for an older package";
		}

		database = pacman_package_get_database (package);
		replaces_ids = pacman_package_make_replaces_ids (package);
		vendor_url = pacman_package_make_vendor_url (package);

		if (g_str_has_prefix (pacman_package_get_name (package), "kernel")) {
			restart = PK_RESTART_ENUM_SYSTEM;
		} else {
			restart = PK_RESTART_ENUM_NONE;
		}

		if (g_str_has_suffix (pacman_database_get_name (database), "testing")) {
			state = PK_UPDATE_STATE_ENUM_TESTING;
		} else {
			state = PK_UPDATE_STATE_ENUM_STABLE;
		}

		built.tv_sec = pacman_package_get_build_date (package);
		if (built.tv_sec > 0) {
			issued = g_time_val_to_iso8601 (&built);
		} else {
			issued = NULL;
		}

		if (upgrades != NULL) {
			installed.tv_sec = pacman_package_get_install_date (upgrades);
			if (installed.tv_sec > 0) {
				updated = g_time_val_to_iso8601 (&installed);
			} else {
				updated = NULL;
			}
		} else {
			updated = NULL;
		}

		pk_backend_update_detail (backend, package_ids[iterator], upgrades_id, replaces_ids, vendor_url, NULL, NULL, restart, message, NULL, state, issued, updated);

		g_free (issued);
		g_free (updated);

		g_free (vendor_url);
		g_free (replaces_ids);
		g_free (upgrades_id);
	}

	backend_finished (backend);
	return TRUE;
}
Ejemplo n.º 27
0
static gboolean
backend_find_packages_thread (PkBackend *backend)
{
	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_set_status (backend, 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_set_percentage (backend, 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);
	return TRUE;
}
Ejemplo n.º 28
0
static gboolean
pk_backend_get_update_detail_thread (PkBackend *self)
{
	gchar **packages;
	GError *error = NULL;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (localdb != NULL, FALSE);

	packages = pk_backend_get_strv (self, "package_ids");

	g_return_val_if_fail (packages != NULL, FALSE);

	/* collect details about updates */
	for (; *packages != NULL; ++packages) {
		pmpkg_t *pkg, *old;
		pmdb_t *db;

		gchar *upgrades, *replaces, *urls;
		const gchar *reason;

		PkRestartEnum restart;
		PkUpdateStateEnum state;

		GTimeVal built = { 0 }, installed = { 0 };
		gchar *issued, *updated;

		if (pk_backend_cancelled (self)) {
			break;
		}

		pkg = pk_backend_find_pkg (self, *packages, &error);
		if (pkg == NULL) {
			break;
		}

		old = alpm_db_get_pkg (localdb, alpm_pkg_get_name (pkg));
		if (old != NULL) {
			upgrades = alpm_pkg_build_id (old);
			if (alpm_pkg_same_pkgver (pkg, old)) {
				reason = "Update to a newer release";
			} else {
				reason = "Update to a new upstream version";
			}
		} else {
			upgrades = NULL;
			reason = "Install to replace an older package";
		}

		db = alpm_pkg_get_db (pkg);
		replaces = alpm_pkg_build_replaces (pkg);
		urls = alpm_pkg_build_urls (pkg);

		if (g_str_has_prefix (alpm_pkg_get_name (pkg), "kernel")) {
			restart = PK_RESTART_ENUM_SYSTEM;
		} else {
			restart = PK_RESTART_ENUM_NONE;
		}

		if (g_str_has_suffix (alpm_db_get_name (db), "testing")) {
			state = PK_UPDATE_STATE_ENUM_TESTING;
		} else {
			state = PK_UPDATE_STATE_ENUM_STABLE;
		}

		built.tv_sec = alpm_pkg_get_builddate (pkg);
		if (built.tv_sec > 0) {
			issued = g_time_val_to_iso8601 (&built);
		} else {
			issued = NULL;
		}

		if (upgrades != NULL) {
			installed.tv_sec = alpm_pkg_get_installdate (old);
			if (installed.tv_sec > 0) {
				updated = g_time_val_to_iso8601 (&installed);
			} else {
				updated = NULL;
			}
		} else {
			updated = NULL;
		}

		pk_backend_update_detail (self, *packages, upgrades, replaces,
					  urls, NULL, NULL, restart, reason,
					  NULL, state, issued, updated);

		g_free (issued);
		g_free (updated);

		g_free (urls);
		g_free (replaces);
		g_free (upgrades);
	}

	return pk_backend_finish (self, error);
}