summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Leeds <matthew.leeds@endlessm.com>2019-09-01 09:27:39 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2019-09-09 10:01:15 +0000
commit1a5306360d815b845c7dbcf7af96381754f916fc (patch)
tree5521597708806f488187f3a1568fa79b8a8323df
parentaafa084bd26f74e4df723c17f1d2ddb7bdf5c02a (diff)
downloadflatpak-1a5306360d815b845c7dbcf7af96381754f916fc.tar.gz
dir: Construct default FlatpakDir with correct id
Currently the FlatpakDir object for the default system installation is constructed differently depending on where the construction is happening. In flatpak_dir_get_system_default() it's created with a NULL DirExtraData object which means flatpak_dir_get_id() returns NULL when called on it. But if constructed in flatpak_get_system_base_dir_locations(), the FlatpakDir object gets a DirExtraData object with the default values, including the id "default", so flatpak_dir_get_id() returns "default" for it. This commit changes flatpak_dir_get_system_default() so it constructs the default object consistently with the other construction. This means that in the places where the dir id is compared to "default" that check will work correctly. Practically this means for CLI transactions the "Proceed with these changes?" prompt will say "the system installation" rather than "the Default system installation". Also change flatpak_dir_get_system_by_id() so it returns the default dir when id == "default", but continue to also return it if id == NULL. This means the --installation=default CLI option will work correctly, but we can avoid breaking any software that might currently be calling flatpak_installation_new_system_with_id() with a NULL id. And finally change flatpak_dir_get_display_name() so it continues to return "Default system installation" for the default system installation. Closes: #3077 Approved by: alexlarsson
-rw-r--r--common/flatpak-dir.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index bdaea272..38241d36 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -566,6 +566,8 @@ dir_extra_data_free (DirExtraData *dir_extra_data)
g_free (dir_extra_data);
}
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (DirExtraData, dir_extra_data_free);
+
static GVariant *
variant_new_ay_bytes (GBytes *bytes)
{
@@ -1897,7 +1899,7 @@ flatpak_dir_get_display_name (FlatpakDir *self)
if (self->user)
return g_strdup (_("User installation"));
- if (self->extra_data != NULL)
+ if (self->extra_data != NULL && g_strcmp0 (self->extra_data->id, SYSTEM_DIR_DEFAULT_ID) != 0)
{
if (self->extra_data->display_name)
return g_strdup (self->extra_data->display_name);
@@ -11763,7 +11765,11 @@ FlatpakDir *
flatpak_dir_get_system_default (void)
{
g_autoptr(GFile) path = flatpak_get_system_default_base_dir_location ();
- return flatpak_dir_new_full (path, FALSE, NULL);
+ g_autoptr(DirExtraData) extra_data = dir_extra_data_new (SYSTEM_DIR_DEFAULT_ID,
+ SYSTEM_DIR_DEFAULT_DISPLAY_NAME,
+ SYSTEM_DIR_DEFAULT_PRIORITY,
+ SYSTEM_DIR_DEFAULT_STORAGE_TYPE);
+ return flatpak_dir_new_full (path, FALSE, extra_data);
}
FlatpakDir *
@@ -11776,7 +11782,7 @@ flatpak_dir_get_system_by_id (const char *id,
FlatpakDir *ret = NULL;
int i;
- if (id == NULL)
+ if (id == NULL || g_strcmp0 (id, SYSTEM_DIR_DEFAULT_ID) == 0)
return flatpak_dir_get_system_default ();
/* An error in flatpak_get_system_base_dir_locations() will still return