Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.5:Update
PackageKit.34493
505.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 505.patch of Package PackageKit.34493
From 02354c3a339b7f8d6661731f224e7ccf1fc34ddc Mon Sep 17 00:00:00 2001 From: Milan Crha <mcrha@redhat.com> Date: Mon, 13 Sep 2021 19:57:12 +0200 Subject: [PATCH] pk-offline: Add flags to D-Bus invoking methods That's currently to be able to set whether the method should be interactive or not. The old functions call the methods as non-interactive. Closes https://github.com/PackageKit/PackageKit/issues/504 --- client/pk-console.c | 4 +- docs/api/PackageKit-sections.txt | 4 + lib/packagekit-glib2/pk-offline.c | 104 ++++++++++++++++++++++++-- lib/packagekit-glib2/pk-offline.h | 31 ++++++++ lib/packagekit-glib2/pk-test-daemon.c | 4 +- 5 files changed, 138 insertions(+), 9 deletions(-) diff --git a/client/pk-console.c b/client/pk-console.c index 3d027e601..4fd620fec 100644 --- a/client/pk-console.c +++ b/client/pk-console.c @@ -2283,14 +2283,14 @@ main (int argc, char *argv[]) } else if (strcmp (mode, "offline-trigger") == 0) { run_mainloop = FALSE; - ret = pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT, NULL, &error); + ret = pk_offline_trigger_with_flags (PK_OFFLINE_ACTION_REBOOT, PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error); if (!ret) ctx->retval = error->code; } else if (strcmp (mode, "offline-cancel") == 0) { run_mainloop = FALSE; - ret = pk_offline_cancel (NULL, &error); + ret = pk_offline_cancel_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error); if (!ret) ctx->retval = error->code; diff --git a/docs/api/PackageKit-sections.txt b/docs/api/PackageKit-sections.txt index ead052f92..2020bd65d 100644 --- a/docs/api/PackageKit-sections.txt +++ b/docs/api/PackageKit-sections.txt @@ -525,9 +525,13 @@ pk_offline_get_action_monitor pk_offline_get_results pk_offline_get_results_mtime pk_offline_cancel +pk_offline_cancel_with_flags pk_offline_clear_results +pk_offline_clear_results_with_flags pk_offline_trigger +pk_offline_trigger_with_flags pk_offline_trigger_upgrade +pk_offline_trigger_upgrade_with_flags </SECTION> <SECTION> diff --git a/lib/packagekit-glib2/pk-offline.c b/lib/packagekit-glib2/pk-offline.c index 2e3870580..9030be293 100644 --- a/lib/packagekit-glib2/pk-offline.c +++ b/lib/packagekit-glib2/pk-offline.c @@ -95,6 +95,14 @@ pk_offline_action_from_string (const gchar *action) return PK_OFFLINE_ACTION_UNKNOWN; } +static GDBusCallFlags +pk_offline_flags_to_gdbus_call_flags (PkOfflineFlags flags) +{ + if ((flags & PK_OFFLINE_FLAGS_INTERACTIVE) != 0) + return G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION; + return G_DBUS_CALL_FLAGS_NONE; +} + /** * pk_offline_cancel: * @cancellable: A #GCancellable or %NULL @@ -102,6 +110,8 @@ pk_offline_action_from_string (const gchar *action) * * Cancels the offline operation that has been scheduled. If there is no * scheduled offline operation then this method returns with success. + * The function always allows user interaction. To change the behavior, + * use pk_offline_cancel_with_flags(). * * Return value: %TRUE for success, else %FALSE and @error set * @@ -109,6 +119,25 @@ pk_offline_action_from_string (const gchar *action) **/ gboolean pk_offline_cancel (GCancellable *cancellable, GError **error) +{ + return pk_offline_cancel_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error); +} + +/** + * pk_offline_cancel_with_flags: + * @flags: bit-or of #PkOfflineFlags + * @cancellable: A #GCancellable or %NULL + * @error: A #GError or %NULL + * + * Cancels the offline operation that has been scheduled. If there is no + * scheduled offline operation then this method returns with success. + * + * Return value: %TRUE for success, else %FALSE and @error set + * + * Since: 1.2.5 + **/ +gboolean +pk_offline_cancel_with_flags (PkOfflineFlags flags, GCancellable *cancellable, GError **error) { g_autoptr(GDBusConnection) connection = NULL; g_autoptr(GVariant) res = NULL; @@ -125,7 +154,7 @@ pk_offline_cancel (GCancellable *cancellable, GError **error) "Cancel", NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, + pk_offline_flags_to_gdbus_call_flags (flags), -1, cancellable, error); @@ -139,8 +168,10 @@ pk_offline_cancel (GCancellable *cancellable, GError **error) * @cancellable: A #GCancellable or %NULL * @error: A #GError or %NULL * - * Crears the last offline operation report, which may be success or failure. + * Clears the last offline operation report, which may be success or failure. * If the report does not exist then this method returns success. + * The function always allows user interaction. To change the behavior, + * use pk_offline_clear_results_with_flags(). * * Return value: %TRUE for success, else %FALSE and @error set * @@ -148,6 +179,25 @@ pk_offline_cancel (GCancellable *cancellable, GError **error) **/ gboolean pk_offline_clear_results (GCancellable *cancellable, GError **error) +{ + return pk_offline_clear_results_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error); +} + +/** + * pk_offline_clear_results_with_flags: + * @flags: bit-or of #PkOfflineFlags + * @cancellable: A #GCancellable or %NULL + * @error: A #GError or %NULL + * + * Clears the last offline operation report, which may be success or failure. + * If the report does not exist then this method returns success. + * + * Return value: %TRUE for success, else %FALSE and @error set + * + * Since: 1.2.5 + **/ +gboolean +pk_offline_clear_results_with_flags (PkOfflineFlags flags, GCancellable *cancellable, GError **error) { g_autoptr(GDBusConnection) connection = NULL; g_autoptr(GVariant) res = NULL; @@ -164,7 +214,7 @@ pk_offline_clear_results (GCancellable *cancellable, GError **error) "ClearResults", NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, + pk_offline_flags_to_gdbus_call_flags (flags), -1, cancellable, error); @@ -181,6 +231,8 @@ pk_offline_clear_results (GCancellable *cancellable, GError **error) * * Triggers the offline update so that the next reboot will perform the * pending transaction. + * The function always allows user interaction. To change the behavior, + * use pk_offline_trigger_with_flags(). * * Return value: %TRUE for success, else %FALSE and @error set * @@ -188,6 +240,26 @@ pk_offline_clear_results (GCancellable *cancellable, GError **error) **/ gboolean pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError **error) +{ + return pk_offline_trigger_with_flags (action, PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error); +} + +/** + * pk_offline_trigger_with_flags: + * @action: a #PkOfflineAction, e.g. %PK_OFFLINE_ACTION_REBOOT + * @flags: bit-or of #PkOfflineFlags + * @cancellable: A #GCancellable or %NULL + * @error: A #GError or %NULL + * + * Triggers the offline update so that the next reboot will perform the + * pending transaction. + * + * Return value: %TRUE for success, else %FALSE and @error set + * + * Since: 1.2.5 + **/ +gboolean +pk_offline_trigger_with_flags (PkOfflineAction action, PkOfflineFlags flags, GCancellable *cancellable, GError **error) { const gchar *tmp; g_autoptr(GDBusConnection) connection = NULL; @@ -206,7 +278,7 @@ pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError ** "Trigger", g_variant_new ("(s)", tmp), NULL, - G_DBUS_CALL_FLAGS_NONE, + pk_offline_flags_to_gdbus_call_flags (flags), -1, cancellable, error); @@ -223,6 +295,8 @@ pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError ** * * Triggers the offline system upgrade so that the next reboot will perform the * pending transaction. + * The function always allows user interaction. To change the behavior, + * use pk_offline_trigger_upgrade_with_flags(). * * Return value: %TRUE for success, else %FALSE and @error set * @@ -230,6 +304,26 @@ pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError ** **/ gboolean pk_offline_trigger_upgrade (PkOfflineAction action, GCancellable *cancellable, GError **error) +{ + return pk_offline_trigger_upgrade_with_flags (action, PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error); +} + +/** + * pk_offline_trigger_upgrade_with_flags: + * @action: a #PkOfflineAction, e.g. %PK_OFFLINE_ACTION_REBOOT + * @flags: bit-or of #PkOfflineFlags + * @cancellable: A #GCancellable or %NULL + * @error: A #GError or %NULL + * + * Triggers the offline system upgrade so that the next reboot will perform the + * pending transaction. + * + * Return value: %TRUE for success, else %FALSE and @error set + * + * Since: 1.2.5 + **/ +gboolean +pk_offline_trigger_upgrade_with_flags (PkOfflineAction action, PkOfflineFlags flags, GCancellable *cancellable, GError **error) { const gchar *tmp; g_autoptr(GDBusConnection) connection = NULL; @@ -248,7 +342,7 @@ pk_offline_trigger_upgrade (PkOfflineAction action, GCancellable *cancellable, G "TriggerUpgrade", g_variant_new ("(s)", tmp), NULL, - G_DBUS_CALL_FLAGS_NONE, + pk_offline_flags_to_gdbus_call_flags (flags), -1, cancellable, error); diff --git a/lib/packagekit-glib2/pk-offline.h b/lib/packagekit-glib2/pk-offline.h index e85179823..943e9a13b 100644 --- a/lib/packagekit-glib2/pk-offline.h +++ b/lib/packagekit-glib2/pk-offline.h @@ -71,6 +71,21 @@ typedef enum PK_OFFLINE_ERROR_LAST } PkOfflineError; +/** + * PkOfflineFlags: + * @PK_OFFLINE_FLAGS_NONE: No specific flag + * @PK_OFFLINE_FLAGS_INTERACTIVE: Run the action in an interactive mode, allowing polkit authentication dialogs + * + * Flags to be used for the method invocations. + * + * Since: 1.2.5 + */ +typedef enum +{ + PK_OFFLINE_FLAGS_NONE = 0, + PK_OFFLINE_FLAGS_INTERACTIVE = 1 << 0 +} PkOfflineFlags; + GQuark pk_offline_error_quark (void); const gchar *pk_offline_action_to_string (PkOfflineAction action); PkOfflineAction pk_offline_action_from_string (const gchar *action); @@ -92,14 +107,30 @@ PkResults *pk_offline_get_results (GError **error); guint64 pk_offline_get_results_mtime (GError **error); gboolean pk_offline_cancel (GCancellable *cancellable, GError **error); +gboolean pk_offline_cancel_with_flags (PkOfflineFlags flags, + GCancellable *cancellable, + GError **error); gboolean pk_offline_clear_results (GCancellable *cancellable, GError **error); +gboolean pk_offline_clear_results_with_flags + (PkOfflineFlags flags, + GCancellable *cancellable, + GError **error); gboolean pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError **error); +gboolean pk_offline_trigger_with_flags (PkOfflineAction action, + PkOfflineFlags flags, + GCancellable *cancellable, + GError **error); gboolean pk_offline_trigger_upgrade (PkOfflineAction action, GCancellable *cancellable, GError **error); +gboolean pk_offline_trigger_upgrade_with_flags + (PkOfflineAction action, + PkOfflineFlags flags, + GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/lib/packagekit-glib2/pk-test-daemon.c b/lib/packagekit-glib2/pk-test-daemon.c index efa762077..b2917b07d 100644 --- a/lib/packagekit-glib2/pk-test-daemon.c +++ b/lib/packagekit-glib2/pk-test-daemon.c @@ -154,7 +154,7 @@ pk_test_offline_func (void) g_assert_cmpstr (data, ==, "powertop;1.8-1.fc8;i386;fedora"); /* trigger */ - ret = pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT, NULL, &error); + ret = pk_offline_trigger_with_flags (PK_OFFLINE_ACTION_REBOOT, PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error); g_assert_no_error (error); g_assert (ret); g_assert (g_file_test (PK_OFFLINE_PREPARED_FILENAME, G_FILE_TEST_EXISTS)); @@ -163,7 +163,7 @@ pk_test_offline_func (void) g_assert (!g_file_test (PK_OFFLINE_RESULTS_FILENAME, G_FILE_TEST_EXISTS)); /* cancel the trigger */ - ret = pk_offline_cancel (NULL, &error); + ret = pk_offline_cancel_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error); g_assert_no_error (error); g_assert (ret); g_assert (g_file_test (PK_OFFLINE_PREPARED_FILENAME, G_FILE_TEST_EXISTS));
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor