From 8f9aa2f35f4e7aa47448f807d526e66470f49af6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 24 Sep 2018 14:38:55 -0400 Subject: [PATCH] Fix a thinko in the permission commands Better to only call g_dir_close() if dir isn't NULL. Take this opportunity to move the function to utils, instead of carrying 4 identical copies. Closes: https://github.com/flatpak/flatpak/issues/2130 Closes: #2133 Approved by: alexlarsson --- app/flatpak-builtins-permission-list.c | 28 +----------------------- app/flatpak-builtins-permission-remove.c | 28 +----------------------- app/flatpak-builtins-permission-reset.c | 28 +----------------------- app/flatpak-builtins-permission-show.c | 28 +----------------------- app/flatpak-builtins-utils.c | 26 ++++++++++++++++++++++ app/flatpak-builtins-utils.h | 4 ++++ 6 files changed, 34 insertions(+), 108 deletions(-) diff --git a/app/flatpak-builtins-permission-list.c b/app/flatpak-builtins-permission-list.c index 841a3666..7fb08f9d 100644 --- a/app/flatpak-builtins-permission-list.c +++ b/app/flatpak-builtins-permission-list.c @@ -32,6 +32,7 @@ #include "flatpak-permission-dbus-generated.h" #include "flatpak-builtins.h" +#include "flatpak-builtins-utils.h" #include "flatpak-table-printer.h" #include "flatpak-utils-private.h" #include "flatpak-run-private.h" @@ -40,33 +41,6 @@ static GOptionEntry options[] = { { NULL } }; -static char ** -get_permission_tables (XdpDbusPermissionStore *store) -{ - g_autofree char *path = NULL; - GDir *dir; - const char *name; - GPtrArray *tables = NULL; - - tables = g_ptr_array_new (); - - path = g_build_filename (g_get_user_data_dir (), "flatpak/db", NULL); - dir = g_dir_open (path, 0, NULL); - if (dir != NULL) - { - while ((name = g_dir_read_name (dir)) != NULL) - { - g_ptr_array_add (tables, g_strdup (name)); - } - } - - g_dir_close (dir); - - g_ptr_array_add (tables, NULL); - - return (char **) g_ptr_array_free (tables, FALSE); -} - static char ** get_ids_for_table (XdpDbusPermissionStore *store, const char *table) diff --git a/app/flatpak-builtins-permission-remove.c b/app/flatpak-builtins-permission-remove.c index 885679bb..62062da0 100644 --- a/app/flatpak-builtins-permission-remove.c +++ b/app/flatpak-builtins-permission-remove.c @@ -32,6 +32,7 @@ #include "flatpak-permission-dbus-generated.h" #include "flatpak-builtins.h" +#include "flatpak-builtins-utils.h" #include "flatpak-table-printer.h" #include "flatpak-utils-private.h" #include "flatpak-run-private.h" @@ -40,33 +41,6 @@ static GOptionEntry options[] = { { NULL } }; -static char ** -get_permission_tables (XdpDbusPermissionStore *store) -{ - g_autofree char *path = NULL; - GDir *dir; - const char *name; - GPtrArray *tables = NULL; - - tables = g_ptr_array_new (); - - path = g_build_filename (g_get_user_data_dir (), "flatpak/db", NULL); - dir = g_dir_open (path, 0, NULL); - if (dir != NULL) - { - while ((name = g_dir_read_name (dir)) != NULL) - { - g_ptr_array_add (tables, g_strdup (name)); - } - } - - g_dir_close (dir); - - g_ptr_array_add (tables, NULL); - - return (char **) g_ptr_array_free (tables, FALSE); -} - static char ** get_ids_for_table (XdpDbusPermissionStore *store, const char *table) diff --git a/app/flatpak-builtins-permission-reset.c b/app/flatpak-builtins-permission-reset.c index 600de7f6..2ec33e1d 100644 --- a/app/flatpak-builtins-permission-reset.c +++ b/app/flatpak-builtins-permission-reset.c @@ -32,6 +32,7 @@ #include "flatpak-permission-dbus-generated.h" #include "flatpak-builtins.h" +#include "flatpak-builtins-utils.h" #include "flatpak-table-printer.h" #include "flatpak-utils-private.h" #include "flatpak-run-private.h" @@ -40,33 +41,6 @@ static GOptionEntry options[] = { { NULL } }; -static char ** -get_permission_tables (XdpDbusPermissionStore *store) -{ - g_autofree char *path = NULL; - GDir *dir; - const char *name; - GPtrArray *tables = NULL; - - tables = g_ptr_array_new (); - - path = g_build_filename (g_get_user_data_dir (), "flatpak/db", NULL); - dir = g_dir_open (path, 0, NULL); - if (dir != NULL) - { - while ((name = g_dir_read_name (dir)) != NULL) - { - g_ptr_array_add (tables, g_strdup (name)); - } - } - - g_dir_close (dir); - - g_ptr_array_add (tables, NULL); - - return (char **) g_ptr_array_free (tables, FALSE); -} - static gboolean remove_for_app (XdpDbusPermissionStore *store, const char *table, diff --git a/app/flatpak-builtins-permission-show.c b/app/flatpak-builtins-permission-show.c index 75874d67..90fc5d95 100644 --- a/app/flatpak-builtins-permission-show.c +++ b/app/flatpak-builtins-permission-show.c @@ -32,6 +32,7 @@ #include "flatpak-permission-dbus-generated.h" #include "flatpak-builtins.h" +#include "flatpak-builtins-utils.h" #include "flatpak-table-printer.h" #include "flatpak-utils-private.h" #include "flatpak-run-private.h" @@ -40,33 +41,6 @@ static GOptionEntry options[] = { { NULL } }; -static char ** -get_permission_tables (XdpDbusPermissionStore *store) -{ - g_autofree char *path = NULL; - GDir *dir; - const char *name; - GPtrArray *tables = NULL; - - tables = g_ptr_array_new (); - - path = g_build_filename (g_get_user_data_dir (), "flatpak/db", NULL); - dir = g_dir_open (path, 0, NULL); - if (dir != NULL) - { - while ((name = g_dir_read_name (dir)) != NULL) - { - g_ptr_array_add (tables, g_strdup (name)); - } - } - - g_dir_close (dir); - - g_ptr_array_add (tables, NULL); - - return (char **) g_ptr_array_free (tables, FALSE); -} - static gboolean list_for_app (XdpDbusPermissionStore *store, const char *table, diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index f5765aa1..0b840087 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -555,3 +555,29 @@ update_appstream (GPtrArray *dirs, return TRUE; } + +char ** +get_permission_tables (XdpDbusPermissionStore *store) +{ + g_autofree char *path = NULL; + GDir *dir; + const char *name; + GPtrArray *tables = NULL; + + tables = g_ptr_array_new (); + + path = g_build_filename (g_get_user_data_dir (), "flatpak/db", NULL); + dir = g_dir_open (path, 0, NULL); + if (dir != NULL) + { + while ((name = g_dir_read_name (dir)) != NULL) + { + g_ptr_array_add (tables, g_strdup (name)); + } + g_dir_close (dir); + } + + g_ptr_array_add (tables, NULL); + + return (char **) g_ptr_array_free (tables, FALSE); +} diff --git a/app/flatpak-builtins-utils.h b/app/flatpak-builtins-utils.h index f66b21e8..000fa12c 100644 --- a/app/flatpak-builtins-utils.h +++ b/app/flatpak-builtins-utils.h @@ -25,6 +25,7 @@ #include "libglnx/libglnx.h" #include "flatpak-utils-private.h" #include "flatpak-dir-private.h" +#include "flatpak-permission-dbus-generated.h" /* Appstream data expires after a day */ #define FLATPAK_APPSTREAM_TTL 86400 @@ -63,4 +64,7 @@ gboolean update_appstream (GPtrArray *dirs, GCancellable *cancellable, GError **error); +char ** get_permission_tables (XdpDbusPermissionStore *store); + + #endif /* __FLATPAK_BUILTINS_UTILS_H__ */