예제 #1
0
/**
 * backend_refresh_cache_thread:
 */
static gboolean
backend_refresh_cache_thread (PkBackend *backend)
{
	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_REFRESH_CACHE);
	// Lock the list directory
	FileFd Lock;
	if (_config->FindB("Debug::NoLocking", false) == false)
	{
		Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
		if (_error->PendingError() == true) {
			pk_backend_error_code (backend, PK_ERROR_ENUM_CANNOT_GET_LOCK, "Unable to lock the list directory");
			delete m_apt;
			pk_backend_finished (backend);
			return false;
	// 	 return _error->Error(_("Unable to lock the list directory"));
		}
	}
	// Create the progress
	AcqPackageKitStatus Stat(m_apt, backend, _cancel);

	// do the work
	if (_config->FindB("APT::Get::Download",true) == true) {
		ListUpdate(Stat, *m_apt->packageSourceList);
	}

	// Rebuild the cache.
	pkgCacheFile Cache;
	OpTextProgress Prog(*_config);
	if (Cache.BuildCaches(Prog, true) == false) {
		if (_error->PendingError() == true) {
			show_errors(backend, PK_ERROR_ENUM_CANNOT_GET_LOCK);
		}
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	// missing gpg signature would appear here
	// TODO we need a better enum
	if (_error->PendingError() == false && _error->empty() == false) {
		show_warnings(backend, PK_MESSAGE_ENUM_UNTRUSTED_PACKAGE);
	}

	pk_backend_finished (backend);
	delete m_apt;
	return true;
}
예제 #2
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;
}
예제 #3
0
static gboolean
backend_search_file_thread (PkBackend *backend)
{
	const gchar *search;
	PkBitfield filters;

	search = pk_backend_get_string (backend, "search");
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");

	pk_backend_set_allow_cancel (backend, true);

	// as we can only search for installed files lets avoid the opposite
	if (!pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
		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<string> packages = search_file (backend, search, _cancel);
		vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output;
		for(vector<string>::iterator i = packages.begin();
		    i != packages.end(); ++i)
		{
			if (_cancel) {
			    break;
			}
			pkgCache::PkgIterator pkg = m_apt->packageCache->FindPkg(i->c_str());
			pkgCache::VerIterator ver = m_apt->find_ver(pkg);
			if (ver.end() == true)
			{
				continue;
			}
			output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(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;
}
예제 #4
0
static void
backend_search_group (PkBackend *backend, PkBitfield filters, gchar **search)
{
	SearchParams *params;

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);

	params = g_new0 (SearchParams, 1);
	params->filters = filters;
	params->search_type = SEARCH_TAG;
	params->needle = g_strdup_printf ("group::%s", search[0]);
	params->backend = backend;

	pk_backend_set_pointer (backend, "search-params", params);
	pk_backend_thread_create (backend, backend_search_thread);
}
예제 #5
0
/**
 * backend_search_description:
 */
static void
backend_search_description (PkBackend *backend, PkBitfield filters, gchar **search)
{
	SearchParams *params;

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);

	params = g_new0 (SearchParams, 1);
	params->filters = filters;
	params->search_type = SEARCH_DESCRIPTION;
	params->needle = g_utf8_strdown (search[0], -1);
	params->backend = backend;

	pk_backend_set_pointer (backend, "search-params", params);
	pk_backend_thread_create (backend, backend_search_thread);
}
예제 #6
0
static void
pk_backend_search_name (PkBackend *backend, PkBitfield filters, gchar **search)
{
	SearchParams *params;

	pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY);
	pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID);

	params = g_new0 (SearchParams, 1);
	params->filters = filters;
	params->search_type = SEARCH_NAME;
	params->needle = g_utf8_strdown (search[0], -1);
	params->backend = backend;

	pk_backend_set_pointer (backend, "search-params", params);
	pk_backend_job_thread_create (job, backend_search_thread, NULL, NULL);
}
예제 #7
0
static gboolean
backend_get_packages_thread (PkBackend *backend)
{
	PkBitfield filters;
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");
	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> > output;
	output.reserve(m_apt->packageCache->HeaderP->PackageCount);
	for(pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin();
	    !pkg.end(); ++pkg)
	{
		if (_cancel) {
			break;
		}
		// Ignore packages that exist only due to dependencies.
		if(pkg.VersionList().end() && pkg.ProvidesList().end())
			continue;

		// Don't insert virtual packages as they don't have all kinds of info
		pkgCache::VerIterator ver = m_apt->find_ver(pkg);
		if (ver.end() == false) {
			output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver));
		}
	}

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

	delete m_apt;

	pk_backend_finished (backend);
	return true;
}
예제 #8
0
static void
pk_backend_remove_packages (PkBackend *backend, PkBackendJob *job, gchar **package_ids, gboolean allow_deps, gboolean autoremove)
{
	gpointer *params;

	pk_backend_job_set_status (job, PK_STATUS_ENUM_REMOVE);
	pk_backend_job_set_percentage (job, PK_BACKEND_PERCENTAGE_INVALID);

	/* params is a small array we can pack our thread parameters into */
	params = g_new0 (gpointer, 2);

	params[0] = g_strdupv (package_ids);
	params[1] = GINT_TO_POINTER (allow_deps);
	params[2] = GINT_TO_POINTER (autoremove);

	pk_backend_set_pointer (backend, "remove-params", params);

	pk_backend_job_thread_create (job, backend_remove_packages_thread, NULL, NULL);
}
예제 #9
0
static gboolean
backend_search_package_thread (PkBackend *backend)
{
	const gchar *search;
	PkBitfield filters;

	search = pk_backend_get_string (backend, "search");
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");

	pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
	pk_backend_set_allow_cancel (backend, true);

	matcher *m_matcher = new matcher(string(search));
	if (m_matcher->hasError()) {
		egg_debug("Regex compilation error");
		delete m_matcher;
		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_matcher;
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	if (_error->PendingError() == true)
	{
		delete m_matcher;
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
	pkgDepCache::Policy Plcy;
	vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output;
	if (pk_backend_get_bool (backend, "search_details")) {
		for (pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) {
			if (_cancel) {
				break;
			}
			// Ignore packages that exist only due to dependencies.
			if (pkg.VersionList().end() && pkg.ProvidesList().end()) {
				continue;
			}

			if (m_matcher->matches(pkg.Name())) {
				// Don't insert virtual packages instead add what it provides
				pkgCache::VerIterator ver = m_apt->find_ver(pkg);
				if (ver.end() == false) {
					output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver));
				} else {
					// iterate over the provides list
					for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; Prv++) {
						ver = m_apt->find_ver(Prv.OwnerPkg());

						// check to see if the provided package isn't virtual too
						if (ver.end() == false)
						{
							// we add the package now because we will need to
							// remove duplicates later anyway
							output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(Prv.OwnerPkg(), ver));
						}
					}
				}
			} else {
				// Don't insert virtual packages instead add what it provides
				pkgCache::VerIterator ver = m_apt->find_ver(pkg);
				if (ver.end() == false) {
					if (m_matcher->matches(get_default_short_description(ver, m_apt->packageRecords))
					    || m_matcher->matches(get_default_long_description(ver, m_apt->packageRecords))
					    || m_matcher->matches(get_short_description(ver, m_apt->packageRecords))
					    || m_matcher->matches(get_long_description(ver, m_apt->packageRecords)))
					{
						output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver));
					}
				} else {
					// iterate over the provides list
					for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; Prv++) {
						ver = m_apt->find_ver(Prv.OwnerPkg());

						// check to see if the provided package isn't virtual too
						if (ver.end() == false)
						{
							// we add the package now because we will need to
							// remove duplicates later anyway
							if (m_matcher->matches(Prv.OwnerPkg().Name())
							    || m_matcher->matches(get_default_short_description(ver, m_apt->packageRecords))
							    || m_matcher->matches(get_default_long_description(ver, m_apt->packageRecords))
							    || m_matcher->matches(get_short_description(ver, m_apt->packageRecords))
							    || m_matcher->matches(get_long_description(ver, m_apt->packageRecords)))
							{
								output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(Prv.OwnerPkg(), ver));
							}
						}
					}
				}
			}
		}
	} else {
		for (pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) {
			if (_cancel) {
				break;
			}
			// Ignore packages that exist only due to dependencies.
			if (pkg.VersionList().end() && pkg.ProvidesList().end()) {
				continue;
			}

			if (m_matcher->matches(pkg.Name())) {
				// Don't insert virtual packages instead add what it provides
				pkgCache::VerIterator ver = m_apt->find_ver(pkg);
				if (ver.end() == false) {
					output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver));
				} else {
					// iterate over the provides list
					for (pkgCache::PrvIterator Prv = pkg.ProvidesList(); Prv.end() == false; Prv++) {
						ver = m_apt->find_ver(Prv.OwnerPkg());

						// check to see if the provided package isn't virtual too
						if (ver.end() == false)
						{
							// we add the package now because we will need to
							// remove duplicates later anyway
							output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(Prv.OwnerPkg(), ver));
						}
					}
				}
			}
		}
	}

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

	delete m_matcher;
	delete m_apt;

	pk_backend_set_percentage (backend, 100);
	pk_backend_finished (backend);
	return true;
}
예제 #10
0
static gboolean
backend_search_group_thread (PkBackend *backend)
{
	const gchar *group;
	PkBitfield filters;

	group = pk_backend_get_string (backend, "search");
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");
	pk_backend_set_allow_cancel (backend, true);

	if (group == NULL) {
		pk_backend_error_code (backend,
				       PK_ERROR_ENUM_GROUP_NOT_FOUND,
				       group);
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_percentage (backend, 0);

	PkGroupEnum pkGroup = pk_group_enum_from_text (group);

	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> > output;
	for (pkgCache::PkgIterator pkg = m_apt->packageCache->PkgBegin(); !pkg.end(); ++pkg) {
		if (_cancel) {
			break;
		}
		// Ignore packages that exist only due to dependencies.
		if (pkg.VersionList().end() && pkg.ProvidesList().end()) {
			continue;
		}

		// Ignore virtual packages
		pkgCache::VerIterator ver = m_apt->find_ver(pkg);
		if (ver.end() == false) {
			string section = pkg.VersionList().Section();

			size_t found;
			found = section.find_last_of("/");
			section = section.substr(found + 1);

			// Don't insert virtual packages instead add what it provides
			if (pkGroup == get_enum_group(section)) {
				output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(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_set_percentage (backend, 100);
	pk_backend_finished (backend);
	return true;
}
예제 #11
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;
}
예제 #12
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;
}
예제 #13
0
static gboolean
backend_what_provides_thread (PkBackend *backend)
{
	PkProvidesEnum provides;
	PkBitfield filters;
	const gchar *search;
	const gchar *provides_text;
	gchar **values;
	bool error = false;

	filters  = (PkBitfield)     pk_backend_get_uint (backend, "filters");
	provides = (PkProvidesEnum) pk_backend_get_uint (backend, "provides");
	search   = pk_backend_get_string (backend, "search");
	values   = g_strsplit (search, "&", 0);

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	if (provides == PK_PROVIDES_ENUM_MIMETYPE ||
	    provides == PK_PROVIDES_ENUM_CODEC ||
	    provides == PK_PROVIDES_ENUM_ANY) {
		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");
			g_strfreev (values);
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}


		pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
		vector<string> packages;
		vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output;
		if (provides == PK_PROVIDES_ENUM_MIMETYPE) {
			packages = searchMimeType (backend, values, error, _cancel);
		} else if (provides == PK_PROVIDES_ENUM_CODEC) {
			m_apt->povidesCodec(output, values);
		} else {
			// any...
			packages = searchMimeType (backend, values, error, _cancel);
			m_apt->povidesCodec(output, values);
		}

		for(vector<string>::iterator i = packages.begin();
		    i != packages.end(); ++i)
		{
			if (_cancel) {
			    break;
			}
			pkgCache::PkgIterator pkg = m_apt->packageCache->FindPkg(i->c_str());
			pkgCache::VerIterator ver = m_apt->find_ver(pkg);
			if (ver.end() == true) {
				continue;
			}
			output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver));
		}

		if (error) {
			// check if app-install-data is installed
			pkgCache::PkgIterator pkg;
			pkg = m_apt->packageCache->FindPkg("app-install-data");
			if (pkg->CurrentState != pkgCache::State::Installed) {
				pk_backend_error_code (backend,
						       PK_ERROR_ENUM_INTERNAL_ERROR,
						       "You need the app-install-data "
						       "package to be able to look for "
						       "applications that can handle "
						       "this kind of file");
			}
		} else {
			// It's faster to emmit the packages here rather than in the matching part
			m_apt->emit_packages(output, filters);
		}

		delete m_apt;
	} else {
		provides_text = pk_provides_enum_to_text (provides);
		pk_backend_error_code (backend,
				       PK_ERROR_ENUM_NOT_SUPPORTED,
				       "Provides %s not supported",
				       provides_text);
	}

	g_strfreev (values);
	pk_backend_finished (backend);
	return true;
}
예제 #14
0
static gboolean
backend_get_or_update_system_thread (PkBackend *backend)
{
	PkBitfield filters;
	bool getUpdates;
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");
	getUpdates = pk_backend_get_bool(backend, "getUpdates");
	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);

	pkgCacheFile Cache;
	OpTextProgress Prog(*_config);
	int timeout = 10;
	// TODO test this
	while (Cache.Open(Prog, !getUpdates) == false) {
		// failed to open cache, try checkDeps then..
		// || Cache.CheckDeps(CmdL.FileSize() != 1) == false
		if (getUpdates == true || (timeout <= 0)) {
			pk_backend_error_code(backend,
					      PK_ERROR_ENUM_NO_CACHE,
					      "Could not open package cache.");
			return false;
		} else {
			pk_backend_set_status (backend, PK_STATUS_ENUM_WAITING_FOR_LOCK);
			sleep(1);
			timeout--;
		}
	}
	pk_backend_set_status (backend, PK_STATUS_ENUM_RUNNING);

	if (pkgDistUpgrade(*Cache) == false)
	{
		show_broken(backend, Cache, false);
		egg_debug ("Internal error, DistUpgrade broke stuff");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	bool res = true;
	if (getUpdates) {
		vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > update,
									    kept;

		for(pkgCache::PkgIterator pkg=m_apt->packageCache->PkgBegin();
		    !pkg.end();
		    ++pkg)
		{
			if((*Cache)[pkg].Upgrade()    == true &&
			(*Cache)[pkg].NewInstall() == false) {
				update.push_back(
					pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, m_apt->find_candidate_ver(pkg)));
			} else if ((*Cache)[pkg].Upgradable() == true &&
				pkg->CurrentVer != 0 &&
				(*Cache)[pkg].Delete() == false) {
				kept.push_back(
					pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, m_apt->find_candidate_ver(pkg)));
			}
		}

		m_apt->emitUpdates(update, filters);
		m_apt->emit_packages(kept, filters, PK_INFO_ENUM_BLOCKED);
	} else {
		res = m_apt->installPackages(Cache);
	}

	delete m_apt;
	pk_backend_finished (backend);
	return res;
}
예제 #15
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;
}
예제 #16
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;
}