summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-05-12 21:23:36 +0200
committerAlexander Larsson <alexl@redhat.com>2016-05-12 21:23:36 +0200
commit5407b8efc657b654da7c66d5c69c35448eb43061 (patch)
tree0aee5808fe0a91422416c19a3b448e48a045a30b
parent3964504438e5f6e0354ea6145f0e0022244ae3fc (diff)
downloadxdg-app-5407b8efc657b654da7c66d5c69c35448eb43061.tar.gz
system-helper: Support uninstall
-rw-r--r--common/flatpak-dir.c23
-rw-r--r--common/flatpak-dir.h4
-rw-r--r--data/org.freedesktop.Flatpak.xml6
-rw-r--r--system-helper/flatpak-system-helper.c67
-rw-r--r--system-helper/org.freedesktop.Flatpak.policy.in22
5 files changed, 116 insertions, 6 deletions
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index 2ba6769..06899dd 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -232,7 +232,7 @@ flatpak_dir_get_system_helper (FlatpakDir *self)
}
gboolean
-flatpak_dir_use_child_repo (FlatpakDir *self)
+flatpak_dir_use_system_helper (FlatpakDir *self)
{
FlatpakSystemHelper *system_helper;
@@ -1085,7 +1085,7 @@ flatpak_dir_update_appstream (FlatpakDir *self,
if (!flatpak_dir_ensure_repo (self, cancellable, error))
return FALSE;
- if (flatpak_dir_use_child_repo (self))
+ if (flatpak_dir_use_system_helper (self))
{
g_autoptr(OstreeRepo) child_repo = NULL;
g_auto(GLnxLockFile) child_repo_lock = GLNX_LOCK_FILE_INIT;
@@ -2945,7 +2945,7 @@ flatpak_dir_install (FlatpakDir *self,
GCancellable *cancellable,
GError **error)
{
- if (flatpak_dir_use_child_repo (self))
+ if (flatpak_dir_use_system_helper (self))
{
g_autoptr(OstreeRepo) child_repo = NULL;
g_auto(GLnxLockFile) child_repo_lock = GLNX_LOCK_FILE_INIT;
@@ -3018,7 +3018,7 @@ flatpak_dir_update (FlatpakDir *self,
GCancellable *cancellable,
GError **error)
{
- if (flatpak_dir_use_child_repo (self))
+ if (flatpak_dir_use_system_helper (self))
{
g_autoptr(OstreeRepo) child_repo = NULL;
g_auto(GLnxLockFile) child_repo_lock = GLNX_LOCK_FILE_INIT;
@@ -3116,6 +3116,21 @@ flatpak_dir_uninstall (FlatpakDir *self,
return FALSE;
name = parts[1];
+ if (flatpak_dir_use_system_helper (self))
+ {
+ FlatpakSystemHelper *system_helper;
+
+ system_helper = flatpak_dir_get_system_helper (self);
+ g_assert (system_helper != NULL);
+
+ if (!flatpak_system_helper_call_uninstall_sync (system_helper,
+ flags, ref,
+ cancellable, error))
+ return FALSE;
+
+ return TRUE;
+ }
+
if (!flatpak_dir_lock (self, &lock,
cancellable, error))
return FALSE;
diff --git a/common/flatpak-dir.h b/common/flatpak-dir.h
index 3d6b2b8..9a102be 100644
--- a/common/flatpak-dir.h
+++ b/common/flatpak-dir.h
@@ -45,13 +45,15 @@ typedef enum {
FLATPAK_HELPER_DEPLOY_FLAGS_UPDATE = 1 << 0,
} FlatpakHelperDeployFlags;
+#define FLATPAK_HELPER_DEPLOY_FLAGS_ALL (FLATPAK_HELPER_DEPLOY_FLAGS_UPDATE)
+
typedef enum {
FLATPAK_HELPER_UNINSTALL_FLAGS_NONE = 0,
FLATPAK_HELPER_UNINSTALL_FLAGS_KEEP_REF = 1 << 0,
FLATPAK_HELPER_UNINSTALL_FLAGS_FORCE_REMOVE = 1 << 1,
} FlatpakHelperUninstallFlags;
-#define FLATPAK_HELPER_DEPLOY_FLAGS_ALL (FLATPAK_HELPER_DEPLOY_FLAGS_UPDATE)
+#define FLATPAK_HELPER_UNINSTALL_FLAGS_ALL (FLATPAK_HELPER_UNINSTALL_FLAGS_KEEP_REF | FLATPAK_HELPER_UNINSTALL_FLAGS_FORCE_REMOVE)
GQuark flatpak_dir_error_quark (void);
diff --git a/data/org.freedesktop.Flatpak.xml b/data/org.freedesktop.Flatpak.xml
index 8ef52bc..cf4b027 100644
--- a/data/org.freedesktop.Flatpak.xml
+++ b/data/org.freedesktop.Flatpak.xml
@@ -45,6 +45,12 @@
<arg type='s' name='origin' direction='in'/>
<arg type='s' name='arch' direction='in'/>
</method>
+
+ <method name="Uninstall">
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='ref' direction='in'/>
+ </method>
+
</interface>
</node>
diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c
index f527499..905909b 100644
--- a/system-helper/flatpak-system-helper.c
+++ b/system-helper/flatpak-system-helper.c
@@ -296,6 +296,41 @@ handle_deploy_appstream (FlatpakSystemHelper *object,
}
static gboolean
+handle_uninstall (FlatpakSystemHelper *object,
+ GDBusMethodInvocation *invocation,
+ guint arg_flags,
+ const gchar *arg_ref)
+{
+ g_autoptr(FlatpakDir) system = flatpak_dir_get_system ();
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GMainContext) main_context = NULL;
+
+ g_debug ("Uninstall %u %s", arg_flags, arg_ref);
+
+ if ((arg_flags & ~FLATPAK_HELPER_UNINSTALL_FLAGS_ALL) != 0)
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+ "Unsupported flags enabled: 0x%x", (arg_flags & ~FLATPAK_HELPER_UNINSTALL_FLAGS_ALL));
+ return TRUE;
+ }
+
+ if (!flatpak_dir_ensure_repo (system, NULL, &error))
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ return TRUE;
+ }
+
+ if (!flatpak_dir_uninstall (system, arg_ref, arg_flags, NULL, &error))
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ return TRUE;
+ }
+
+ flatpak_system_helper_complete_uninstall (object, invocation);
+ return TRUE;
+}
+
+static gboolean
flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface,
GDBusMethodInvocation *invocation,
gpointer user_data)
@@ -368,7 +403,7 @@ flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface,
authorized = polkit_authorization_result_get_is_authorized (result);
}
- else if (g_strcmp0 (method_name, "DeployAppstream") == 0)
+ else if (g_strcmp0 (method_name, "DeployAppstream") == 0)
{
const char *arch, *origin;
@@ -394,6 +429,35 @@ flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface,
authorized = polkit_authorization_result_get_is_authorized (result);
}
+ else if (g_strcmp0 (method_name, "Uninstall") == 0)
+ {
+ const char *ref;
+ gboolean is_app;
+
+ g_variant_get_child (parameters, 1, "&s", &ref);
+
+ is_app = g_str_has_prefix (ref, "app/");
+ if (is_app)
+ action = "org.freedesktop.Flatpak.app-uninstall";
+ else
+ action = "org.freedesktop.Flatpak.runtime-uninstall";
+
+ details = polkit_details_new ();
+ polkit_details_insert (details, "ref", ref);
+
+ result = polkit_authority_check_authorization_sync (authority, subject,
+ action, details,
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
+ NULL, &error);
+ if (result == NULL)
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+ "Authorization error: %s", error->message);
+ return FALSE;
+ }
+
+ authorized = polkit_authorization_result_get_is_authorized (result);
+ }
if (!authorized)
{
@@ -424,6 +488,7 @@ on_bus_acquired (GDBusConnection *connection,
g_signal_connect (helper, "handle-deploy", G_CALLBACK (handle_deploy), NULL);
g_signal_connect (helper, "handle-deploy-appstream", G_CALLBACK (handle_deploy_appstream), NULL);
+ g_signal_connect (helper, "handle-uninstall", G_CALLBACK (handle_uninstall), NULL);
g_signal_connect (helper, "g-authorize-method",
G_CALLBACK (flatpak_authorize_method_handler),
diff --git a/system-helper/org.freedesktop.Flatpak.policy.in b/system-helper/org.freedesktop.Flatpak.policy.in
index a0a1bcc..15f8220 100644
--- a/system-helper/org.freedesktop.Flatpak.policy.in
+++ b/system-helper/org.freedesktop.Flatpak.policy.in
@@ -83,6 +83,28 @@
</defaults>
</action>
+ <action id="org.freedesktop.Flatpak.runtime-uninstall">
+ <_description>Uninstall runtime</_description>
+ <_message>Authentication is required to uninstall software</_message>
+ <icon_name>package-x-generic</icon_name>
+ <defaults>
+ <allow_any>auth_admin</allow_any>
+ <allow_inactive>auth_admin</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.freedesktop.Flatpak.app-uninstall">
+ <_description>Uninstall app</_description>
+ <_message>Authentication is required to uninstall software</_message>
+ <icon_name>package-x-generic</icon_name>
+ <defaults>
+ <allow_any>auth_admin</allow_any>
+ <allow_inactive>auth_admin</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ </action>
+
<action id="org.freedesktop.Flatpak.appstream-update">
<!-- SECURITY:
- Normal users do not require admin authentication to update