Created
November 6, 2019 22:56
-
-
Save ptomato/e20d0a8592fa0d38fde1efc5fb9a55ac to your computer and use it in GitHub Desktop.
bad fallback patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/flatpak-builtins-build-commit-from.c b/app/flatpak-builtins-build-commit-from.c | |
index 4b125bc3..fd6aae88 100644 | |
--- a/app/flatpak-builtins-build-commit-from.c | |
+++ b/app/flatpak-builtins-build-commit-from.c | |
@@ -391,7 +391,10 @@ flatpak_builtin_build_commit_from (int argc, char **argv, GCancellable *cancella | |
glnx_console_lock (&console); | |
if (console.is_tty) | |
- progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); | |
+ { | |
+ progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); | |
+ flatpak_progress_ensure_default_state (progress); | |
+ } | |
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); | |
g_variant_builder_add (&builder, "{s@v}", "flags", | |
diff --git a/app/flatpak-builtins-create-usb.c b/app/flatpak-builtins-create-usb.c | |
index 7d814ca6..82ff2739 100644 | |
--- a/app/flatpak-builtins-create-usb.c | |
+++ b/app/flatpak-builtins-create-usb.c | |
@@ -320,7 +320,10 @@ ostree_create_usb (GOptionContext *context, | |
glnx_console_lock (&console); | |
if (console.is_tty) | |
- progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); | |
+ { | |
+ progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); | |
+ flatpak_progress_ensure_default_state (progress); | |
+ } | |
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); | |
diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c | |
index 62cec51d..30c654d7 100644 | |
--- a/app/flatpak-builtins-utils.c | |
+++ b/app/flatpak-builtins-utils.c | |
@@ -698,6 +698,7 @@ update_appstream (GPtrArray *dirs, | |
} | |
} | |
progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (progress); | |
if (!flatpak_dir_update_appstream (dir, remotes[i], arch, &changed, | |
progress, cancellable, &local_error)) | |
{ | |
@@ -735,6 +736,7 @@ update_appstream (GPtrArray *dirs, | |
g_debug ("%s:%s appstream age %" G_GUINT64_FORMAT " is greater than ttl %" G_GUINT64_FORMAT, remote, arch, ts_file_age, ttl); | |
progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (progress); | |
res = flatpak_dir_update_appstream (dir, remote, arch, &changed, | |
progress, cancellable, error); | |
ostree_async_progress_finish (progress); | |
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c | |
index d3ae1e82..8729e24e 100644 | |
--- a/common/flatpak-dir.c | |
+++ b/common/flatpak-dir.c | |
@@ -13400,6 +13400,8 @@ _flatpak_dir_fetch_remote_state_metadata_branch (FlatpakDir *self, | |
g_assert (state->collection_id != NULL); | |
+ flatpak_progress_ensure_default_state (progress); | |
+ | |
/* We can only fetch metadata if we’re going to verify it with GPG. */ | |
if (!ostree_repo_remote_get_gpg_verify (self->repo, state->remote_name, | |
&gpg_verify, error)) | |
diff --git a/common/flatpak-installation.c b/common/flatpak-installation.c | |
index d6935b1d..df2038f3 100644 | |
--- a/common/flatpak-installation.c | |
+++ b/common/flatpak-installation.c | |
@@ -2045,9 +2045,14 @@ flatpak_installation_install_full (FlatpakInstallation *self, | |
main_context = flatpak_main_context_new_default (); | |
if (progress) | |
- ostree_progress = flatpak_progress_new (progress, progress_data); | |
+ { | |
+ ostree_progress = flatpak_progress_new (progress, progress_data); | |
+ } | |
else | |
- ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ { | |
+ ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
+ } | |
if (!flatpak_dir_install (dir_clone, | |
(flags & FLATPAK_INSTALL_FLAGS_NO_PULL) != 0, | |
@@ -2216,9 +2221,14 @@ flatpak_installation_update_full (FlatpakInstallation *self, | |
main_context = flatpak_main_context_new_default (); | |
if (progress) | |
- ostree_progress = flatpak_progress_new (progress, progress_data); | |
+ { | |
+ ostree_progress = flatpak_progress_new (progress, progress_data); | |
+ } | |
else | |
- ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ { | |
+ ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
+ } | |
if (!flatpak_dir_update (dir_clone, | |
(flags & FLATPAK_UPDATE_FLAGS_NO_PULL) != 0, | |
@@ -2831,9 +2841,14 @@ flatpak_installation_update_appstream_full_sync (FlatpakInstallation *self, | |
main_context = flatpak_main_context_new_default (); | |
if (progress) | |
- ostree_progress = flatpak_progress_new (progress, progress_data); | |
+ { | |
+ ostree_progress = flatpak_progress_new (progress, progress_data); | |
+ } | |
else | |
- ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ { | |
+ ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
+ } | |
res = flatpak_dir_update_appstream (dir_clone, | |
remote_name, | |
diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h | |
index 4d52b037..aaaa3904 100644 | |
--- a/common/flatpak-utils-private.h | |
+++ b/common/flatpak-utils-private.h | |
@@ -821,6 +821,8 @@ flatpak_progress_unchain (OstreeAsyncProgress *chained_progress) | |
ostree_async_progress_finish (chained_progress); | |
} | |
+void flatpak_progress_ensure_default_state (OstreeAsyncProgress *progress); | |
+ | |
typedef OstreeAsyncProgress FlatpakAsyncProgressChained; | |
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakAsyncProgressChained, flatpak_progress_unchain); | |
diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c | |
index 22de70a7..3ceffddf 100644 | |
--- a/common/flatpak-utils.c | |
+++ b/common/flatpak-utils.c | |
@@ -6286,6 +6286,15 @@ progress_cb (OstreeAsyncProgress *progress, gpointer user_data) | |
"downloading-extra-data", "u", &downloading_extra_data, | |
NULL); | |
+#if !OSTREE_CHECK_VERSION(2019, 6) | |
+ if (start_time == 0) | |
+ { | |
+ /* Spurious callback invocation due to initialization or copying */ | |
+ g_string_free (buf, TRUE); | |
+ return; | |
+ } | |
+#endif | |
+ | |
elapsed_time = (g_get_monotonic_time () - start_time) / G_USEC_PER_SEC; | |
/* When we receive the status, it means that the ostree pull operation is | |
@@ -6416,9 +6425,94 @@ flatpak_progress_new (FlatpakProgressCallback progress, | |
g_object_set_data (G_OBJECT (ostree_progress), "last_total", GUINT_TO_POINTER (0)); | |
g_object_set_data (G_OBJECT (ostree_progress), "chained_from", NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
+ | |
return ostree_progress; | |
} | |
+#if !OSTREE_CHECK_VERSION(2019, 6) | |
+ | |
+/* Copy all the OstreeAsyncProgress state that's relevant for progress_cb() | |
+ * above. Note that this locks and unlocks twice, triggers a spurious callback | |
+ * invocation, and is not robust to more keys being added to the | |
+ * OstreeAsyncProgress hash table. */ | |
+static void | |
+copy_state_fallback (OstreeAsyncProgress *source, | |
+ OstreeAsyncProgress *dest) | |
+{ | |
+ guint outstanding_fetches; | |
+ guint outstanding_metadata_fetches; | |
+ guint outstanding_writes; | |
+ gboolean scanning; | |
+ guint n_scanned_metadata; | |
+ guint fetched_delta_parts; | |
+ guint total_delta_parts; | |
+ guint fetched_delta_part_fallbacks; | |
+ guint total_delta_part_fallbacks; | |
+ guint64 fetched_delta_part_size; | |
+ guint64 total_delta_part_size; | |
+ guint64 bytes_transferred; | |
+ guint fetched; | |
+ guint metadata_fetched; | |
+ guint requested; | |
+ guint64 start_time; | |
+ g_autofree char *status = NULL; | |
+ guint64 outstanding_extra_data; | |
+ guint64 total_extra_data_bytes; | |
+ guint64 transferred_extra_data_bytes; | |
+ gboolean downloading_extra_data; | |
+ | |
+ ostree_async_progress_get (source, | |
+ "outstanding-fetches", "u", &outstanding_fetches, | |
+ "outstanding-metadata-fetches", "u", &outstanding_metadata_fetches, | |
+ "outstanding-writes", "u", &outstanding_writes, | |
+ "scanning", "u", &scanning, | |
+ "scanned-metadata", "u", &n_scanned_metadata, | |
+ "fetched-delta-parts", "u", &fetched_delta_parts, | |
+ "total-delta-parts", "u", &total_delta_parts, | |
+ "fetched-delta-fallbacks", "u", &fetched_delta_part_fallbacks, | |
+ "total-delta-fallbacks", "u", &total_delta_part_fallbacks, | |
+ "fetched-delta-part-size", "t", &fetched_delta_part_size, | |
+ "total-delta-part-size", "t", &total_delta_part_size, | |
+ "bytes-transferred", "t", &bytes_transferred, | |
+ "fetched", "u", &fetched, | |
+ "metadata-fetched", "u", &metadata_fetched, | |
+ "requested", "u", &requested, | |
+ "start-time", "t", &start_time, | |
+ "status", "s", &status, | |
+ "outstanding-extra-data", "t", &outstanding_extra_data, | |
+ "total-extra-data-bytes", "t", &total_extra_data_bytes, | |
+ "transferred-extra-data-bytes", "t", &transferred_extra_data_bytes, | |
+ "downloading-extra-data", "u", &downloading_extra_data, | |
+ NULL); | |
+ | |
+ ostree_async_progress_set (dest, | |
+ "outstanding-fetches", "u", outstanding_fetches, | |
+ "outstanding-metadata-fetches", "u", outstanding_metadata_fetches, | |
+ "outstanding-writes", "u", outstanding_writes, | |
+ "scanning", "u", scanning, | |
+ "scanned-metadata", "u", n_scanned_metadata, | |
+ "fetched-delta-parts", "u", fetched_delta_parts, | |
+ "total-delta-parts", "u", total_delta_parts, | |
+ "fetched-delta-fallbacks", "u", fetched_delta_part_fallbacks, | |
+ "total-delta-fallbacks", "u", total_delta_part_fallbacks, | |
+ "fetched-delta-part-size", "t", fetched_delta_part_size, | |
+ "total-delta-part-size", "t", total_delta_part_size, | |
+ "bytes-transferred", "t", bytes_transferred, | |
+ "fetched", "u", fetched, | |
+ "metadata-fetched", "u", metadata_fetched, | |
+ "requested", "u", requested, | |
+ "start-time", "t", start_time, | |
+ "status", "s", status, | |
+ "outstanding-extra-data", "t", outstanding_extra_data, | |
+ "total-extra-data-bytes", "t", total_extra_data_bytes, | |
+ "transferred-extra-data-bytes", "t", transferred_extra_data_bytes, | |
+ "downloading-extra-data", "u", downloading_extra_data, | |
+ NULL); | |
+} | |
+ | |
+#endif /* libostree < 2019.6 */ | |
+ | |
static void | |
handle_chained_progress (OstreeAsyncProgress *chained_progress, | |
gpointer user_data) | |
@@ -6428,7 +6522,11 @@ handle_chained_progress (OstreeAsyncProgress *chained_progress, | |
/* Sync the chained progress's state back to the original instance, to take | |
* into account any updates received while a different GMainContext was | |
* active */ | |
+#if OSTREE_CHECK_VERSION(2019, 6) | |
ostree_async_progress_copy_state (chained_progress, original_progress); | |
+#else | |
+ copy_state_fallback (chained_progress, original_progress); | |
+#endif | |
OstreeAsyncProgress *chained_from = | |
OSTREE_ASYNC_PROGRESS (g_object_get_data (G_OBJECT (original_progress), "chained_from")); | |
@@ -6504,7 +6602,11 @@ flatpak_progress_chain (OstreeAsyncProgress *progress) | |
OstreeAsyncProgress *chained_progress = ostree_async_progress_new (); | |
/* Copy the OstreeAsyncProgress's state to the chained instance */ | |
+#if OSTREE_CHECK_VERSION(2019, 6) | |
ostree_async_progress_copy_state (progress, chained_progress); | |
+#else | |
+ copy_state_fallback (progress, chained_progress); | |
+#endif | |
g_signal_connect (chained_progress, "changed", | |
G_CALLBACK (handle_chained_progress), progress); | |
@@ -6520,6 +6622,46 @@ flatpak_progress_chain (OstreeAsyncProgress *progress) | |
return chained_progress; | |
} | |
+/* | |
+ * flatpak_progress_ensure_default_state: | |
+ * @progress: the object to initialize | |
+ * | |
+ * As a temporary workaround until https://github.com/ostreedev/ostree/pull/1968 | |
+ * is available, call this on every instance of #OstreeAsyncProgress not created | |
+ * with flatpak_progress_new() created inside libflatpak. | |
+ * | |
+ * This is a no-op if the libostree version is new enough. | |
+ */ | |
+void | |
+flatpak_progress_ensure_default_state (OstreeAsyncProgress *progress) | |
+{ | |
+#if !OSTREE_CHECK_VERSION(2019, 6) | |
+ ostree_async_progress_set (progress, | |
+ "outstanding-fetches", "u", 0, | |
+ "outstanding-metadata-fetches", "u", 0, | |
+ "outstanding-writes", "u", 0, | |
+ "scanning", "u", 0, | |
+ "scanned-metadata", "u", 0, | |
+ "fetched-delta-parts", "u", 0, | |
+ "total-delta-parts", "u", 0, | |
+ "fetched-delta-fallbacks", "u", 0, | |
+ "total-delta-fallbacks", "u", 0, | |
+ "fetched-delta-part-size", "t", (guint64) 0, | |
+ "total-delta-part-size", "t", (guint64) 0, | |
+ "bytes-transferred", "t", (guint64) 0, | |
+ "fetched", "u", 0, | |
+ "metadata-fetched", "u", 0, | |
+ "requested", "u", 0, | |
+ "start-time", "t", (guint64) 0, | |
+ "status", "s", "", | |
+ "outstanding-extra-data", "t", (guint64) 0, | |
+ "total-extra-data-bytes", "t", (guint64) 0, | |
+ "transferred-extra-data-bytes", "t", (guint64) 0, | |
+ "downloading-extra-data", "u", 0, | |
+ NULL); | |
+#endif /* libostree < 2019.6 */ | |
+} | |
+ | |
void | |
flatpak_log_dir_access (FlatpakDir *dir) | |
{ | |
diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c | |
index b6b484a8..dcefbc57 100644 | |
--- a/system-helper/flatpak-system-helper.c | |
+++ b/system-helper/flatpak-system-helper.c | |
@@ -612,6 +612,7 @@ handle_deploy (FlatpakSystemHelper *object, | |
main_context = flatpak_main_context_new_default (); | |
ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
if (!flatpak_dir_pull_untrusted_local (system, arg_repo_path, | |
arg_origin, | |
@@ -658,6 +659,7 @@ handle_deploy (FlatpakSystemHelper *object, | |
main_context = flatpak_main_context_new_default (); | |
ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
if (!flatpak_dir_pull (system, state, arg_ref, NULL, NULL, (const char **) arg_subpaths, NULL, | |
FLATPAK_PULL_FLAGS_NONE, OSTREE_REPO_PULL_FLAGS_UNTRUSTED, ostree_progress, | |
@@ -839,6 +841,7 @@ handle_deploy_appstream (FlatpakSystemHelper *object, | |
main_context = flatpak_main_context_new_default (); | |
ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
if (!flatpak_dir_pull_untrusted_local (system, arg_repo_path, | |
arg_origin, | |
@@ -898,6 +901,7 @@ handle_deploy_appstream (FlatpakSystemHelper *object, | |
main_context = flatpak_main_context_new_default (); | |
ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); | |
+ flatpak_progress_ensure_default_state (ostree_progress); | |
if (!flatpak_dir_pull (system, state, new_branch, NULL, NULL, NULL, NULL, | |
FLATPAK_PULL_FLAGS_NONE, OSTREE_REPO_PULL_FLAGS_UNTRUSTED, ostree_progress, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment