dir: flatpak_dir_get_by_path()

This automatically picks up whether the path is a system or user installation.
We'll need this in the update portal.
This commit is contained in:
Alexander Larsson
2019-09-12 09:57:55 +02:00
committed by Alexander Larsson
parent 32ec943adf
commit ae574f2a14
2 changed files with 30 additions and 0 deletions

View File

@@ -396,6 +396,7 @@ GPtrArray *flatpak_dir_get_system_list (GCancellable *cancellable,
FlatpakDir *flatpak_dir_get_system_by_id (const char *id,
GCancellable *cancellable,
GError **error);
FlatpakDir *flatpak_dir_get_by_path (GFile *path);
gboolean flatpak_dir_is_user (FlatpakDir *self);
void flatpak_dir_set_no_system_helper (FlatpakDir *self,
gboolean no_system_helper);

View File

@@ -11828,6 +11828,35 @@ flatpak_dir_get_system_default (void)
return flatpak_dir_new_full (path, FALSE, extra_data);
}
/* This figures out if it is a user or system dir automatically */
FlatpakDir *
flatpak_dir_get_by_path (GFile *path)
{
GPtrArray *locations = flatpak_get_system_base_dir_locations (NULL, NULL);
int i;
if (locations)
{
for (i = 0; i < locations->len; i++)
{
GFile *system_path = g_ptr_array_index (locations, i);
if (g_file_equal (system_path, path))
{
DirExtraData *extra_data = g_object_get_data (G_OBJECT (path), "extra-data");
return flatpak_dir_new_full (path, FALSE, extra_data);
}
}
}
/* If its not configured as a system installation it will not have
an installation id and we can't use the system helper, so assume
user (and fail later with permission issues if its not owned by
the caller) */
return flatpak_dir_new (path, TRUE);
}
FlatpakDir *
flatpak_dir_get_system_by_id (const char *id,
GCancellable *cancellable,