/** * pk_backend_new: * * Return value: A new backend class backend. **/ PkBackend * pk_backend_new (void) { PkBackend *backend; backend = g_object_new (PK_TYPE_BACKEND, NULL); return PK_BACKEND (backend); }
/** * pk_backend_refresh_cache_thread: */ static void pk_backend_refresh_cache_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); apt->emitFinished(); return; } PkBackend *backend = PK_BACKEND(pk_backend_job_get_backend(job)); if (pk_backend_is_online(backend)) { apt->refreshCache(); if (_error->PendingError() == true) { show_errors(job, PK_ERROR_ENUM_CANNOT_FETCH_SOURCES, true); } } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline"); } apt->emitFinished(); }
/** * pk_backend_new: * * Return value: A new backend class backend. **/ PkBackend * pk_backend_new (GKeyFile *conf) { PkBackend *backend; backend = g_object_new (PK_TYPE_BACKEND, NULL); backend->priv->conf = g_key_file_ref (conf); return PK_BACKEND (backend); }
/** * pk_backend_finalize: **/ static void pk_backend_finalize (GObject *object) { PkBackend *backend; g_return_if_fail (PK_IS_BACKEND (object)); backend = PK_BACKEND (object); g_free (backend->priv->name); g_object_unref (backend->priv->network); g_object_unref (backend->priv->conf); g_hash_table_destroy (backend->priv->eulas); if (backend->priv->monitor != NULL) g_object_unref (backend->priv->monitor); if (backend->priv->handle != NULL) g_module_close (backend->priv->handle); g_debug ("parent_class->finalize"); G_OBJECT_CLASS (pk_backend_parent_class)->finalize (object); }
/** * pk_backend_finalize: **/ static void pk_backend_finalize (GObject *object) { PkBackend *backend; g_return_if_fail (PK_IS_BACKEND (object)); backend = PK_BACKEND (object); g_free (backend->priv->name); #ifdef PK_BUILD_DAEMON g_object_unref (backend->priv->network); #endif g_key_file_unref (backend->priv->conf); g_hash_table_destroy (backend->priv->eulas); g_mutex_clear (&backend->priv->thread_hash_mutex); g_hash_table_unref (backend->priv->thread_hash); if (backend->priv->monitor != NULL) g_object_unref (backend->priv->monitor); if (backend->priv->handle != NULL) g_module_close (backend->priv->handle); G_OBJECT_CLASS (pk_backend_parent_class)->finalize (object); }
/** * pk_backend_download_packages_thread: */ static void pk_backend_download_packages_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { gchar **package_ids; const gchar *tmpDir; string directory; g_variant_get(params, "(^a&ss)", &package_ids, &tmpDir); directory = _config->FindDir("Dir::Cache::archives"); pk_backend_job_set_allow_cancel(job, true); AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); if (!apt->init()) { g_debug("Failed to create apt cache"); return; } PkBackend *backend = PK_BACKEND(pk_backend_job_get_backend(job)); if (pk_backend_is_online(backend)) { pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); // Create the progress AcqPackageKitStatus Stat(apt, job); // get a fetcher pkgAcquire fetcher(&Stat); 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_job_error_code(job, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "%s", pi); return; } if (apt->cancelled()) { break; } const pkgCache::VerIterator &ver = apt->aptCacheFile()->resolvePkgID(pi); // Ignore packages that could not be found or that exist only due to dependencies. if (ver.end()) { _error->Error("Can't find this package id \"%s\".", pi); continue; } else { if(!ver.Downloadable()) { _error->Error("No downloadable files for %s," "perhaps it is a local or obsolete" "package?", pi); continue; } string storeFileName; if (!apt->getArchive(&fetcher, ver, directory, storeFileName)) { return; } gchar **files = (gchar **) g_malloc(2 * sizeof(gchar *)); files[0] = g_strdup_printf("%s/%s", directory.c_str(), flNotDir(storeFileName).c_str()); files[1] = NULL; pk_backend_job_files(job, pi, files); g_strfreev(files); } } if (fetcher.Run() != pkgAcquire::Continue && apt->cancelled() == false) { // We failed and we did not cancel show_errors(job, PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED); return; } } else { pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_NETWORK, "Cannot download packages whilst offline"); } }