/** * gs_plugin_app_remove: */ gboolean gs_plugin_app_remove (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { const gchar *epi_desktop; g_autofree gchar *basename = NULL; g_autofree gchar *app_desktop = NULL; g_autoptr(GFile) file_epi = NULL; g_autoptr(GFile) file_app = NULL; /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), "Epiphany") != 0) return TRUE; epi_desktop = gs_app_get_source_id_default (app); if (epi_desktop == NULL) return TRUE; /* remove the epi 'config' file */ gs_app_set_state (app, AS_APP_STATE_REMOVING); file_epi = g_file_new_for_path (epi_desktop); if (!g_file_delete (file_epi, NULL, error)) return FALSE; /* remove the shared desktop file */ basename = g_file_get_basename (file_epi); app_desktop = g_build_filename (g_get_user_data_dir (), "applications", gs_app_get_id (app), NULL); file_app = g_file_new_for_path (app_desktop); if (!g_file_delete (file_app, NULL, error)) return FALSE; gs_app_set_state (app, AS_APP_STATE_AVAILABLE); return TRUE; }
static gboolean gs_plugin_add_sources_related (GsPlugin *plugin, GHashTable *hash, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); guint i; GsApp *app; GsApp *app_tmp; PkBitfield filter; ProgressData data; const gchar *id; gboolean ret = TRUE; g_autoptr(GsAppList) installed = gs_app_list_new (); g_autoptr(PkResults) results = NULL; g_autoptr(AsProfileTask) ptask = NULL; data.app = NULL; data.plugin = plugin; data.ptask = NULL; ptask = as_profile_start_literal (gs_plugin_get_profile (plugin), "packagekit::add-sources-related"); g_assert (ptask != NULL); filter = pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED, PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, PK_FILTER_ENUM_NOT_COLLECTIONS, -1); results = pk_client_get_packages (PK_CLIENT(priv->task), filter, cancellable, gs_plugin_packagekit_progress_cb, &data, error); if (!gs_plugin_packagekit_results_valid (results, error)) return FALSE; ret = gs_plugin_packagekit_add_results (plugin, installed, results, error); if (!ret) return FALSE; for (i = 0; i < gs_app_list_length (installed); i++) { g_auto(GStrv) split = NULL; app = gs_app_list_index (installed, i); split = pk_package_id_split (gs_app_get_source_id_default (app)); if (g_str_has_prefix (split[PK_PACKAGE_ID_DATA], "installed:")) { id = split[PK_PACKAGE_ID_DATA] + 10; app_tmp = g_hash_table_lookup (hash, id); if (app_tmp != NULL) { g_debug ("found package %s from %s", gs_app_get_source_default (app), id); gs_app_add_related (app_tmp, app); } } } return TRUE; }
/** * gs_plugin_refine: */ gboolean gs_plugin_refine (GsPlugin *plugin, GList **list, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GList *l; GsApp *app; const gchar *tmp; for (l = *list; l != NULL; l = l->next) { app = GS_APP (l->data); if (gs_app_get_id_kind (app) != AS_ID_KIND_WEB_APP) continue; gs_app_set_size (app, 4096); tmp = gs_app_get_source_id_default (app); if (tmp != NULL) continue; if (!gs_plugin_refine_app (plugin, app, error)) return FALSE; } return TRUE; }
/** * gs_plugin_refine_app: */ gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { Header h; const gchar *fn; gint rc; g_auto(rpmdbMatchIterator) mi = NULL; g_auto(rpmts) ts = NULL; /* not required */ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION) == 0 && (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) == 0 && (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0 && (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION) == 0) return TRUE; /* no need to run the plugin */ if (gs_app_get_source_default (app) != NULL && gs_app_get_source_id_default (app) != NULL) return TRUE; /* open db readonly */ ts = rpmtsCreate(); rpmtsSetRootDir (ts, NULL); rc = rpmtsOpenDB (ts, O_RDONLY); if (rc != 0) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Failed to open rpmdb: %i", rc); return FALSE; } /* look for a specific file */ fn = gs_app_get_metadata_item (app, "appstream::source-file"); if (fn == NULL) return TRUE; if (!g_str_has_prefix (fn, "/usr")) return TRUE; mi = rpmtsInitIterator (ts, RPMDBI_INSTFILENAMES, fn, 0); if (mi == NULL) { g_debug ("rpm: no search results for %s", fn); return TRUE; } /* on rpm-ostree this package cannot be removed 'live' */ gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY); /* process any results */ g_debug ("rpm: querying for %s with %s", gs_app_get_id (app), fn); while ((h = rpmdbNextIterator (mi)) != NULL) { guint64 epoch; const gchar *name; const gchar *version; const gchar *arch; const gchar *release; const gchar *license; /* add default source */ name = headerGetString (h, RPMTAG_NAME); if (gs_app_get_source_default (app) == NULL) { g_debug ("rpm: setting source to %s", name); gs_app_add_source (app, name); } /* set size */ if (gs_app_get_size_download (app) == 0) gs_app_set_size_download (app, 0); if (gs_app_get_size_installed (app) == 0) { guint64 tmp; tmp = headerGetNumber (h, RPMTAG_SIZE); gs_app_set_size_installed (app, tmp); } /* set license */ license = headerGetString (h, RPMTAG_LICENSE); if (gs_app_get_license (app) == NULL && license != NULL) { g_autofree gchar *tmp = NULL; tmp = as_utils_license_to_spdx (license); gs_app_set_license (app, GS_APP_QUALITY_NORMAL, tmp); } /* add version */ version = headerGetString (h, RPMTAG_VERSION); if (gs_app_get_version (app) == NULL) { g_debug ("rpm: setting version to %s", version); gs_app_set_version (app, version); } /* add source-id */ if (gs_app_get_source_id_default (app) == NULL) { g_autofree gchar *tmp = NULL; release = headerGetString (h, RPMTAG_RELEASE); arch = headerGetString (h, RPMTAG_ARCH); epoch = headerGetNumber (h, RPMTAG_EPOCH); if (epoch > 0) { tmp = g_strdup_printf ("%s;%" G_GUINT64_FORMAT ":%s-%s;%s;installed", name, epoch, version, release, arch); } else { tmp = g_strdup_printf ("%s;%s-%s;%s;installed", name, version, release, arch); } g_debug ("rpm: setting source-id to %s", tmp); gs_app_add_source_id (app, tmp); } } return TRUE; }