diff --git a/lib/flatpak-installation.c b/lib/flatpak-installation.c index a0cb1d74..9ed51fb7 100644 --- a/lib/flatpak-installation.c +++ b/lib/flatpak-installation.c @@ -1509,7 +1509,7 @@ flatpak_installation_install_bundle (FlatpakInstallation *self, * in @ref_file_data and returns the #FlatpakRemoteRef that can be used * to install it. * - * Note, the #FlatpakRemoteRef will not have the commit field set, to + * Note, the #FlatpakRemoteRef will not have the commit field set, or other details, to * avoid unnecessary roundtrips. If you need that you have to resolve it * explicitly with flatpak_installation_fetch_remote_ref_sync (). * @@ -1538,7 +1538,7 @@ flatpak_installation_install_ref_file (FlatpakInstallation *self, if (!flatpak_installation_drop_caches (self, cancellable, error)) return NULL; - return flatpak_remote_ref_new (ref, NULL, remote); + return flatpak_remote_ref_new (ref, NULL, remote, NULL); } /** @@ -1939,6 +1939,9 @@ flatpak_installation_uninstall (FlatpakInstallation *self, * for instance if you're doing an update then the real download size may be smaller * than what is returned here. * + * NOTE: Since 0.11.4 this information is accessible in FlatpakRemoteRef, so this + * function is not very useful anymore. + * * Returns: %TRUE, unless an error occurred */ gboolean @@ -1977,6 +1980,9 @@ flatpak_installation_fetch_remote_size_sync (FlatpakInstallation *self, * * Obtains the metadata file from a commit. * + * NOTE: Since 0.11.4 this information is accessible in FlatpakRemoteRef, so this + * function is not very useful anymore. + * * Returns: (transfer full): a #GBytes containing the flatpak metadata file, * or %NULL if an error occurred */ @@ -2053,7 +2059,7 @@ flatpak_installation_list_remote_refs_sync (FlatpakInstallation *self, const char *checksum = value; FlatpakRemoteRef *ref; - ref = flatpak_remote_ref_new (refspec, checksum, remote_name); + ref = flatpak_remote_ref_new (refspec, checksum, remote_name, state); if (ref) g_ptr_array_add (refs, ref); @@ -2120,7 +2126,7 @@ flatpak_installation_fetch_remote_ref_sync (FlatpakInstallation *self, checksum = g_hash_table_lookup (ht, ref); if (checksum != NULL) - return flatpak_remote_ref_new (ref, checksum, remote_name); + return flatpak_remote_ref_new (ref, checksum, remote_name, state); g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Reference %s doesn't exist in remote", ref); diff --git a/lib/flatpak-remote-ref-private.h b/lib/flatpak-remote-ref-private.h index 98e43f43..b98fff70 100644 --- a/lib/flatpak-remote-ref-private.h +++ b/lib/flatpak-remote-ref-private.h @@ -30,6 +30,7 @@ FlatpakRemoteRef *flatpak_remote_ref_new (const char *full_ref, const char *commit, - const char *remote_name); + const char *remote_name, + FlatpakRemoteState *remote_state); #endif /* __FLATPAK_REMOTE_REF_PRIVATE_H__ */ diff --git a/lib/flatpak-remote-ref.c b/lib/flatpak-remote-ref.c index 9a7646f9..2e69d53f 100644 --- a/lib/flatpak-remote-ref.c +++ b/lib/flatpak-remote-ref.c @@ -40,6 +40,12 @@ typedef struct _FlatpakRemoteRefPrivate FlatpakRemoteRefPrivate; struct _FlatpakRemoteRefPrivate { char *remote_name; + guint64 installed_size; + guint64 download_size; + GBytes *metadata; + char *eol; + char *eol_rebase; + }; G_DEFINE_TYPE_WITH_PRIVATE (FlatpakRemoteRef, flatpak_remote_ref, FLATPAK_TYPE_REF) @@ -48,6 +54,11 @@ enum { PROP_0, PROP_REMOTE_NAME, + PROP_INSTALLED_SIZE, + PROP_DOWNLOAD_SIZE, + PROP_METADATA, + PROP_EOL, + PROP_EOL_REBASE, }; static void @@ -77,6 +88,29 @@ flatpak_remote_ref_set_property (GObject *object, priv->remote_name = g_value_dup_string (value); break; + case PROP_INSTALLED_SIZE: + priv->installed_size = g_value_get_uint64 (value); + break; + + case PROP_DOWNLOAD_SIZE: + priv->download_size = g_value_get_uint64 (value); + break; + + case PROP_METADATA: + g_clear_pointer (&priv->metadata, g_bytes_unref); + priv->metadata = g_bytes_ref (g_value_get_boxed (value)); + break; + + case PROP_EOL: + g_clear_pointer (&priv->eol, g_free); + priv->eol = g_value_dup_string (value); + break; + + case PROP_EOL_REBASE: + g_clear_pointer (&priv->eol_rebase, g_free); + priv->eol_rebase = g_value_dup_string (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -98,6 +132,26 @@ flatpak_remote_ref_get_property (GObject *object, g_value_set_string (value, priv->remote_name); break; + case PROP_INSTALLED_SIZE: + g_value_set_uint64 (value, priv->installed_size); + break; + + case PROP_DOWNLOAD_SIZE: + g_value_set_uint64 (value, priv->installed_size); + break; + + case PROP_METADATA: + g_value_set_boxed (value, priv->metadata); + break; + + case PROP_EOL: + g_value_set_string (value, priv->eol); + break; + + case PROP_EOL_REBASE: + g_value_set_string (value, priv->eol_rebase); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -120,6 +174,41 @@ flatpak_remote_ref_class_init (FlatpakRemoteRefClass *klass) "The name of the remote", NULL, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_INSTALLED_SIZE, + g_param_spec_uint64 ("installed-size", + "Installed Size", + "The installed size of the application", + 0, G_MAXUINT64, 0, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_DOWNLOAD_SIZE, + g_param_spec_uint64 ("download-size", + "Download Size", + "The download size of the application", + 0, G_MAXUINT64, 0, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_METADATA, + g_param_spec_boxed ("metadata", + "Metadata", + "The metadata info for the application", + G_TYPE_BYTES, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_EOL, + g_param_spec_string ("end-of-life", + "End of life", + "The reason for the ref to be end of life", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_EOL_REBASE, + g_param_spec_string ("end-of-life-rebase", + "End of life rebase", + "The new ref for the end of lifeed ref", + NULL, + G_PARAM_READWRITE)); } static void @@ -143,21 +232,127 @@ flatpak_remote_ref_get_remote_name (FlatpakRemoteRef *self) return priv->remote_name; } +/** + * flatpak_remote_ref_get_installed_size: + * @self: a #FlatpakRemoteRef + * + * Returns the installed size of the ref. + * + * Returns: the installed size + */ +guint64 +flatpak_remote_ref_get_installed_size (FlatpakRemoteRef *self) +{ + FlatpakRemoteRefPrivate *priv = flatpak_remote_ref_get_instance_private (self); + + return priv->installed_size; +} + +/** + * flatpak_remote_ref_get_download_size: + * @self: a #FlatpakRemoteRef + * + * Returns the download size of the ref. + * + * Returns: the download size + */ +guint64 +flatpak_remote_ref_get_download_size (FlatpakRemoteRef *self) +{ + FlatpakRemoteRefPrivate *priv = flatpak_remote_ref_get_instance_private (self); + + return priv->download_size; +} + +/** + * flatpak_remote_ref_get_metadata: + * @self: a #FlatpakRemoteRef + * + * Returns the app metadata from the metadata cach of the ref. + * + * Returns: (transfer none): a #GBytes with the metadata file contents + */ +GBytes * +flatpak_remote_ref_get_metadata (FlatpakRemoteRef *self) +{ + FlatpakRemoteRefPrivate *priv = flatpak_remote_ref_get_instance_private (self); + + return priv->metadata; +} + +/** + * flatpak_remote_ref_get_eol: + * @self: a #FlatpakRemoteRef + * + * Returns the end-of-life reason string, or %NULL if the + * ref is not end-of-lifed. + * + * Returns: (transfer none): the end-of-life reason or %NULL + */ +const char * +flatpak_remote_ref_get_eol (FlatpakRemoteRef *self) +{ + FlatpakRemoteRefPrivate *priv = flatpak_remote_ref_get_instance_private (self); + + return priv->eol; +} + +/** + * flatpak_remote_ref_get_eol_rebase: + * @self: a #FlatpakRemoteRef + * + * Returns the end-of-life rebased ref, or %NULL if the + * ref is not end-of-lifed. + * + * Returns: (transfer none): the end-of-life rebased ref or %NULL + */ +const char * +flatpak_remote_ref_get_eol_rebase (FlatpakRemoteRef *self) +{ + FlatpakRemoteRefPrivate *priv = flatpak_remote_ref_get_instance_private (self); + + return priv->eol_rebase; +} FlatpakRemoteRef * flatpak_remote_ref_new (const char *full_ref, const char *commit, - const char *remote_name) + const char *remote_name, + FlatpakRemoteState *state) { FlatpakRefKind kind = FLATPAK_REF_KIND_APP; - + guint64 download_size = 0, installed_size = 0; + g_autofree char *metadata = NULL; + g_autoptr(GBytes) metadata_bytes = NULL; g_auto(GStrv) parts = NULL; FlatpakRemoteRef *ref; + g_autoptr(GVariant) sparse = NULL; + const char *eol = NULL; + const char *eol_rebase = NULL; parts = flatpak_decompose_ref (full_ref, NULL); if (parts == NULL) return NULL; + if (state && + !flatpak_remote_state_lookup_cache (state, full_ref, + &download_size, &installed_size, &metadata, + NULL, NULL)) + { + g_warning ("Ignoring ref %s due to lack of metadata", full_ref); + return NULL; + } + + if (metadata) + metadata_bytes = g_bytes_new_take (g_steal_pointer (&metadata), strlen (metadata)); + + sparse = flatpak_remote_state_lookup_sparse_cache (state, full_ref, NULL); + if (sparse) + { + g_variant_lookup (sparse, "eol", "&s", &eol); + g_variant_lookup (sparse, "eolr", "&s", &eol_rebase); + } + if (strcmp (parts[0], "app") != 0) kind = FLATPAK_REF_KIND_RUNTIME; @@ -168,6 +363,11 @@ flatpak_remote_ref_new (const char *full_ref, "branch", parts[3], "commit", commit, "remote-name", remote_name, + "installed-size", installed_size, + "download-size", download_size, + "metadata", metadata_bytes, + "end-of-life", eol, + "end-of-life-rebase", eol_rebase, NULL); return ref; diff --git a/lib/flatpak-remote-ref.h b/lib/flatpak-remote-ref.h index 203c6074..0c9a4e82 100644 --- a/lib/flatpak-remote-ref.h +++ b/lib/flatpak-remote-ref.h @@ -47,6 +47,11 @@ typedef struct } FlatpakRemoteRefClass; FLATPAK_EXTERN const char * flatpak_remote_ref_get_remote_name (FlatpakRemoteRef *self); +FLATPAK_EXTERN guint64 flatpak_remote_ref_get_installed_size (FlatpakRemoteRef *self); +FLATPAK_EXTERN guint64 flatpak_remote_ref_get_download_size (FlatpakRemoteRef *self); +FLATPAK_EXTERN GBytes * flatpak_remote_ref_get_metadata (FlatpakRemoteRef *self); +FLATPAK_EXTERN const char * flatpak_remote_ref_get_eol (FlatpakRemoteRef *self); +FLATPAK_EXTERN const char * flatpak_remote_ref_get_eol_rebase (FlatpakRemoteRef *self); #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakRemoteRef, g_object_unref) diff --git a/tests/testlibrary.c b/tests/testlibrary.c index f91ea551..0765b4db 100644 --- a/tests/testlibrary.c +++ b/tests/testlibrary.c @@ -362,6 +362,62 @@ test_list_refs (void) g_assert_cmpint (refs->len, ==, 0); } +static void +test_list_remote_refs (void) +{ + g_autoptr(FlatpakInstallation) inst = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(GPtrArray) refs = NULL; + int i; + + inst = flatpak_installation_new_user (NULL, &error); + g_assert_no_error (error); + + refs = flatpak_installation_list_remote_refs_sync (inst, repo_name, NULL, &error); + g_assert_no_error (error); + g_assert_nonnull (refs); + g_assert_cmpint (refs->len, ==, 2); + + + for (i = 0; i < refs->len; i++) + { + FlatpakRemoteRef *remote_ref = g_ptr_array_index (refs, i); + FlatpakRef *ref = FLATPAK_REF (remote_ref); + GBytes *metadata; + + g_assert (ref != NULL); + + if (strcmp ("org.test.Hello", flatpak_ref_get_name (ref)) == 0) + { + g_assert_cmpint (flatpak_ref_get_kind (ref), ==, FLATPAK_REF_KIND_APP); + } + else + { + g_assert_cmpstr (flatpak_ref_get_name (ref), ==, "org.test.Platform"); + g_assert_cmpint (flatpak_ref_get_kind (ref), ==, FLATPAK_REF_KIND_RUNTIME); + } + + g_assert_cmpstr (flatpak_ref_get_branch (ref), ==, "master"); + g_assert_cmpstr (flatpak_ref_get_commit (ref), !=, NULL); + g_assert_cmpstr (flatpak_ref_get_arch (ref), ==, flatpak_get_default_arch ()); + + g_assert_cmpstr (flatpak_remote_ref_get_remote_name (remote_ref), ==, repo_name); + g_assert_cmpstr (flatpak_remote_ref_get_eol (remote_ref), ==, NULL); + g_assert_cmpstr (flatpak_remote_ref_get_eol_rebase (remote_ref), ==, NULL); + + g_assert_cmpuint (flatpak_remote_ref_get_installed_size (remote_ref), >, 0); + g_assert_cmpuint (flatpak_remote_ref_get_download_size (remote_ref), >, 0); + + metadata = flatpak_remote_ref_get_metadata (remote_ref); + g_assert (metadata != NULL); + + if (strcmp ("org.test.Hello", flatpak_ref_get_name (ref)) == 0) + g_assert (g_str_has_prefix ((char *)g_bytes_get_data (metadata, NULL), "[Application]")); + else + g_assert (g_str_has_prefix ((char *)g_bytes_get_data (metadata, NULL), "[Runtime]")); + } +} + static void progress_cb (const char *status, guint progress, @@ -1036,6 +1092,7 @@ main (int argc, char *argv[]) g_test_add_func ("/library/list-remotes", test_list_remotes); g_test_add_func ("/library/remote-by-name", test_remote_by_name); g_test_add_func ("/library/remote", test_remote); + g_test_add_func ("/library/list-remote-refs", test_list_remote_refs); g_test_add_func ("/library/list-refs", test_list_refs); g_test_add_func ("/library/install-launch-uninstall", test_install_launch_uninstall); g_test_add_func ("/library/list-updates", test_list_updates);