summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-21 21:32:49 +0200
committerAlexander Larsson <alexl@redhat.com>2016-04-22 08:55:41 +0200
commit4261057e2a0531db759b0e29292b352ae2f43634 (patch)
tree3ecc8970ce968e524e5a33d9f4ba2f8761139070
parent7d509ab93a83a9d6662ee201f3657e2f584b7eda (diff)
downloadxdg-app-4261057e2a0531db759b0e29292b352ae2f43634.tar.gz
common: Don't use singletons for the system/user XdgAppDirs
Without this we never finalize them and can't e.g. remote temporary files.
-rw-r--r--app/xdg-app-builtins-list.c35
-rw-r--r--common/xdg-app-dir.c22
2 files changed, 23 insertions, 34 deletions
diff --git a/app/xdg-app-builtins-list.c b/app/xdg-app-builtins-list.c
index 921e03e..9c8423c 100644
--- a/app/xdg-app-builtins-list.c
+++ b/app/xdg-app-builtins-list.c
@@ -81,33 +81,31 @@ print_installed_refs (gboolean app, gboolean runtime, gboolean print_system, gbo
g_auto(GStrv) user = NULL;
g_auto(GStrv) user_app = NULL;
g_auto(GStrv) user_runtime = NULL;
+ g_autoptr(XdgAppDir) user_dir = NULL;
+ g_autoptr(XdgAppDir) system_dir = NULL;
int s, u;
if (print_user)
{
- g_autoptr(XdgAppDir) dir = NULL;
+ user_dir = xdg_app_dir_get (TRUE);
- dir = xdg_app_dir_get (TRUE);
-
- if (xdg_app_dir_ensure_repo (dir, cancellable, NULL))
+ if (xdg_app_dir_ensure_repo (user_dir, cancellable, NULL))
{
- if (app && !xdg_app_dir_list_refs (dir, "app", &user_app, cancellable, error))
+ if (app && !xdg_app_dir_list_refs (user_dir, "app", &user_app, cancellable, error))
return FALSE;
- if (runtime && !xdg_app_dir_list_refs (dir, "runtime", &user_runtime, cancellable, error))
+ if (runtime && !xdg_app_dir_list_refs (user_dir, "runtime", &user_runtime, cancellable, error))
return FALSE;
}
}
if (print_system)
{
- g_autoptr(XdgAppDir) dir = NULL;
-
- dir = xdg_app_dir_get (FALSE);
- if (xdg_app_dir_ensure_repo (dir, cancellable, NULL))
+ system_dir = xdg_app_dir_get (FALSE);
+ if (xdg_app_dir_ensure_repo (system_dir, cancellable, NULL))
{
- if (app && !xdg_app_dir_list_refs (dir, "app", &system_app, cancellable, error))
+ if (app && !xdg_app_dir_list_refs (system_dir, "app", &system_app, cancellable, error))
return FALSE;
- if (runtime && !xdg_app_dir_list_refs (dir, "runtime", &system_runtime, cancellable, error))
+ if (runtime && !xdg_app_dir_list_refs (system_dir, "runtime", &system_runtime, cancellable, error))
return FALSE;
}
}
@@ -123,7 +121,7 @@ print_installed_refs (gboolean app, gboolean runtime, gboolean print_system, gbo
g_auto(GStrv) parts = NULL;
g_autofree char *repo = NULL;
gboolean is_user;
- g_autoptr(XdgAppDir) dir = NULL;
+ XdgAppDir *dir = NULL;
if (system[s] == NULL)
is_user = TRUE;
@@ -135,14 +133,19 @@ print_installed_refs (gboolean app, gboolean runtime, gboolean print_system, gbo
is_user = TRUE;
if (is_user)
- ref = user[u++];
+ {
+ ref = user[u++];
+ dir = user_dir;
+ }
else
- ref = system[s++];
+ {
+ ref = system[s++];
+ dir = system_dir;
+ }
parts = g_strsplit (ref, "/", -1);
partial_ref = strchr(ref, '/') + 1;
- dir = xdg_app_dir_get (is_user);
repo = xdg_app_dir_get_origin (dir, ref, NULL, NULL);
if (opt_show_details)
diff --git a/common/xdg-app-dir.c b/common/xdg-app-dir.c
index 05d7f87..d6704ae 100644
--- a/common/xdg-app-dir.c
+++ b/common/xdg-app-dir.c
@@ -2934,29 +2934,15 @@ xdg_app_dir_clone (XdgAppDir *self)
XdgAppDir *
xdg_app_dir_get_system (void)
{
- static XdgAppDir *system = NULL;
-
- if (system == NULL)
- {
- g_autoptr(GFile) path = xdg_app_get_system_base_dir_location ();
- system = xdg_app_dir_new (path, FALSE);
- }
-
- return g_object_ref (system);
+ g_autoptr(GFile) path = xdg_app_get_system_base_dir_location ();
+ return xdg_app_dir_new (path, FALSE);
}
XdgAppDir *
xdg_app_dir_get_user (void)
{
- static XdgAppDir *user = NULL;
-
- if (user == NULL)
- {
- g_autoptr(GFile) path = xdg_app_get_user_base_dir_location ();
- user = xdg_app_dir_new (path, TRUE);
- }
-
- return g_object_ref (user);
+ g_autoptr(GFile) path = xdg_app_get_user_base_dir_location ();
+ return xdg_app_dir_new (path, TRUE);
}
XdgAppDir *