View | Details | Raw Unified | Return to bug 1008287
Collapse All | Expand All

(-)PackageKit-1.1.5/backends/zypp/pk-backend-zypp.cpp (+118 lines)
Lines 2158-2163 pk_backend_get_details (PkBackend *backe Link Here
2158
	pk_backend_job_thread_create (job, backend_get_details_thread, NULL, NULL);
2158
	pk_backend_job_thread_create (job, backend_get_details_thread, NULL, NULL);
2159
}
2159
}
2160
2160
2161
/**
2162
 * backend_get_details_local_thread:
2163
 */
2164
static void
2165
backend_get_details_local_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
2166
{
2167
	MIL << endl;
2168
	RepoManager manager;
2169
	ZyppJob zjob(job);
2170
	ZYpp::Ptr zypp = zjob.get_zypp();
2171
2172
	gchar **full_paths;
2173
	g_variant_get (params, "(^a&s)", &full_paths);
2174
	
2175
	if (zypp == NULL){
2176
		return;
2177
	}
2178
2179
	pk_backend_job_set_status (job, PK_STATUS_ENUM_QUERY);
2180
2181
	// create a temporary directory
2182
	filesystem::TmpDir tmpDir;
2183
	if (tmpDir == NULL) {
2184
		zypp_backend_finished_error (
2185
			job, PK_ERROR_ENUM_INTERNAL_ERROR,
2186
			"Could not create a temporary directory");
2187
		return;
2188
	}
2189
2190
	for (guint i = 0; full_paths[i]; i++) {
2191
2192
		// check if file is really a rpm
2193
		Pathname rpmPath (full_paths[i]);
2194
		target::rpm::RpmHeader::constPtr rpmHeader = target::rpm::RpmHeader::readPackage (rpmPath, target::rpm::RpmHeader::NOSIGNATURE);
2195
2196
		if (rpmHeader == NULL) {
2197
			zypp_backend_finished_error (
2198
				job, PK_ERROR_ENUM_INTERNAL_ERROR,
2199
				"%s is not valid rpm-File", full_paths[i]);
2200
			return;
2201
		}
2202
2203
		// copy the rpm into tmpdir
2204
		string tempDest = tmpDir.path ().asString () + "/" + rpmHeader->tag_name () + ".rpm";
2205
		if (filesystem::copy (full_paths[i], tempDest) != 0) {
2206
			zypp_backend_finished_error (
2207
				job, PK_ERROR_ENUM_INTERNAL_ERROR,
2208
				"Could not copy the rpm-file into the temp-dir");
2209
			return;
2210
		}
2211
	}
2212
2213
	// create a plaindir-repo and cache it
2214
	RepoInfo tmpRepo;
2215
2216
	try {
2217
		tmpRepo.setType(repo::RepoType::RPMPLAINDIR);
2218
		string url = "dir://" + tmpDir.path ().asString ();
2219
		tmpRepo.addBaseUrl(Url::parseUrl(url));
2220
		tmpRepo.setEnabled (true);
2221
		tmpRepo.setAutorefresh (true);
2222
		tmpRepo.setAlias ("PK_TMP_DIR");
2223
		tmpRepo.setName ("PK_TMP_DIR");
2224
2225
		// add Repo to pool
2226
		manager.addRepository (tmpRepo);
2227
2228
		if (!zypp_refresh_meta_and_cache (manager, tmpRepo)) {
2229
			zypp_backend_finished_error (
2230
			  job, PK_ERROR_ENUM_INTERNAL_ERROR, "Can't refresh repositories");
2231
			return;
2232
		}
2233
		zypp_build_pool (zypp, true);
2234
2235
	} catch (const Exception &ex) {
2236
		zypp_backend_finished_error (
2237
			job, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString ().c_str ());
2238
		return;
2239
	}
2240
2241
	Repository repo = ResPool::instance().reposFind("PK_TMP_DIR");
2242
2243
	for_(it, repo.solvablesBegin(), repo.solvablesEnd()){
2244
		gchar *package_id = NULL;
2245
		Package::Ptr pkg(make<Package>(*it));
2246
2247
		MIL << "Setting " << *it << " for showing details" << endl;
2248
2249
	        package_id = zypp_build_package_id_from_resolvable (PoolItem(*it).resolvable()->satSolvable());
2250
2251
		pk_backend_job_details (job,
2252
			    package_id,
2253
			    pkg->summary().c_str(),
2254
			    pkg->license().c_str(),
2255
			    PK_GROUP_ENUM_UNKNOWN,
2256
			    pkg->description().c_str(),
2257
			    pkg->url().c_str(),
2258
			    pkg->downloadSize().blocks(zypp::ByteCount::B));
2259
		g_free (package_id);
2260
	}
2261
2262
	// remove tmp-dir and the tmp-repo
2263
	try {
2264
		manager.removeRepository (tmpRepo);
2265
	} catch (const repo::RepoNotFoundException &ex) {
2266
		pk_backend_job_error_code (job, PK_ERROR_ENUM_REPO_NOT_FOUND, "%s", ex.asUserString().c_str() );
2267
	}
2268
}
2269
2270
/**
2271
 * pk_backend_get_details_local:
2272
 */
2273
void
2274
pk_backend_get_details_local (PkBackend *backend, PkBackendJob *job, gchar **full_paths)
2275
{
2276
	pk_backend_job_thread_create (job, backend_get_details_local_thread, NULL, NULL);
2277
}
2278
2161
static void
2279
static void
2162
backend_get_distro_upgrades_thread(PkBackendJob *job, GVariant *params, gpointer user_data)
2280
backend_get_distro_upgrades_thread(PkBackendJob *job, GVariant *params, gpointer user_data)
2163
{
2281
{

Return to bug 1008287