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.
tingping/wmclass
Alexander Larsson 2015-12-18 12:27:26 +01:00
parent feed03c284
commit fdc9b62988
3 changed files with 30 additions and 13 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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,