Add internal API: flatpak_dir_get_system_by_id()

It will return a FlatpakDir by ID, according to the configuration.
tingping/wmclass
Mario Sanchez Prada 2016-12-16 19:17:26 +00:00
parent 1858b8987d
commit 9d97382f82
2 changed files with 46 additions and 0 deletions

View File

@ -5864,6 +5864,49 @@ flatpak_dir_get_system_default (void)
return flatpak_dir_new_with_id (path, FALSE, NULL);
}
FlatpakDir *
flatpak_dir_get_system_by_id (const char *id,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GError) local_error = NULL;
GPtrArray *locations = NULL;
FlatpakDir *ret = NULL;
int i;
if (id == NULL)
return flatpak_dir_get_system_default ();
/* An error in flatpak_get_system_base_dir_locations() will still return
* return an empty array with the GError set, but we want to return NULL.
*/
locations = flatpak_get_system_base_dir_locations (cancellable, &local_error);
if (local_error != NULL)
{
g_propagate_error (error, g_steal_pointer (&local_error));
return NULL;
}
for (i = 0; i < locations->len; i++)
{
GFile *path = g_ptr_array_index (locations, i);
char *install_id = g_object_get_data (G_OBJECT (path), "installation-id");
if (g_strcmp0 (install_id, id) == 0)
{
ret = flatpak_dir_new_with_id (path, FALSE, id);
break;
}
}
if (ret == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
_("Could not find installation %s"), id);
}
return ret;
}
GPtrArray *
flatpak_dir_get_system_list (GCancellable *cancellable,
GError **error)

View File

@ -148,6 +148,9 @@ FlatpakDir *flatpak_dir_get_user (void);
FlatpakDir *flatpak_dir_get_system_default (void);
GPtrArray *flatpak_dir_get_system_list (GCancellable *cancellable,
GError **error);
FlatpakDir *flatpak_dir_get_system_by_id (const char *id,
GCancellable *cancellable,
GError **error);
gboolean flatpak_dir_is_user (FlatpakDir *self);
void flatpak_dir_set_no_system_helper (FlatpakDir *self,
gboolean no_system_helper);