diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-12-18 12:27:26 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2015-12-18 12:27:26 +0100 |
commit | fdc9b62988842909a88d3c01af4d234de148abb9 (patch) | |
tree | 7f21e97d0006b0b2320d69dcea243ca4a34cc590 /lib | |
parent | feed03c284528ab81d242f6c86784e70564eadb7 (diff) | |
download | xdg-app-fdc9b62988842909a88d3c01af4d234de148abb9.tar.gz |
lib: Always initialize the repo on Installation creation
This means we can fail if the repo doesn't exist yet and we have
no write rights.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/test-lib.c | 7 | ||||
-rw-r--r-- | lib/xdg-app-installation.c | 29 | ||||
-rw-r--r-- | lib/xdg-app-installation.h | 7 |
3 files changed, 30 insertions, 13 deletions
diff --git a/lib/test-lib.c b/lib/test-lib.c index d4a55db..60ba307 100644 --- a/lib/test-lib.c +++ b/lib/test-lib.c @@ -25,7 +25,12 @@ main (int argc, char *argv[]) GError *error = NULL; int i, j; - installation = xdg_app_installation_new_user (); + installation = xdg_app_installation_new_user (&error); + if (installation == NULL) + { + g_print ("error: %s\n", error->message); + return 1; + } if (argc == 3) { diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index 3ef5f62..886f500 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -104,31 +104,42 @@ xdg_app_installation_init (XdgAppInstallation *self) } static XdgAppInstallation * -xdg_app_installation_new_for_dir (XdgAppDir *dir) +xdg_app_installation_new_for_dir (XdgAppDir *dir, + GError **error) { - XdgAppInstallation *self = g_object_new (XDG_APP_TYPE_INSTALLATION, NULL); - XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self); + XdgAppInstallation *self; + XdgAppInstallationPrivate *priv; + + if (!xdg_app_dir_ensure_repo (dir, NULL, error)) + { + g_object_unref (dir); + return NULL; + } + + self = g_object_new (XDG_APP_TYPE_INSTALLATION, NULL); + priv = xdg_app_installation_get_instance_private (self); priv->dir = dir; + return self; } XdgAppInstallation * -xdg_app_installation_new_system (void) +xdg_app_installation_new_system (GError **error) { - return xdg_app_installation_new_for_dir (xdg_app_dir_get_system ()); + return xdg_app_installation_new_for_dir (xdg_app_dir_get_system (), error); } XdgAppInstallation * -xdg_app_installation_new_user (void) +xdg_app_installation_new_user (GError **error) { - return xdg_app_installation_new_for_dir (xdg_app_dir_get_user ()); + return xdg_app_installation_new_for_dir (xdg_app_dir_get_user (), error); } XdgAppInstallation * -xdg_app_installation_new_for_path (GFile *path, gboolean user) +xdg_app_installation_new_for_path (GFile *path, gboolean user, GError **error) { - return xdg_app_installation_new_for_dir (xdg_app_dir_new (path, user)); + return xdg_app_installation_new_for_dir (xdg_app_dir_new (path, user), error); } gboolean diff --git a/lib/xdg-app-installation.h b/lib/xdg-app-installation.h index eda2440..bd33cee 100644 --- a/lib/xdg-app-installation.h +++ b/lib/xdg-app-installation.h @@ -56,10 +56,11 @@ typedef enum { G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppInstallation, g_object_unref) #endif -XDG_APP_EXTERN XdgAppInstallation *xdg_app_installation_new_system (void); -XDG_APP_EXTERN XdgAppInstallation *xdg_app_installation_new_user (void); +XDG_APP_EXTERN XdgAppInstallation *xdg_app_installation_new_system (GError **error); +XDG_APP_EXTERN XdgAppInstallation *xdg_app_installation_new_user (GError **error); XDG_APP_EXTERN XdgAppInstallation *xdg_app_installation_new_for_path (GFile *path, - gboolean user); + gboolean user, + GError **error); typedef void (*XdgAppProgressCallback)(const char *status, guint progress, |