Blame SOURCES/core-Always-refresh-authorization-when-creating-stre.patch

3247c5
From 62a30455c32bdfb2a113d4708ba8dba57decc9e5 Mon Sep 17 00:00:00 2001
3247c5
From: Ondrej Holy <oholy@redhat.com>
3247c5
Date: Mon, 20 Jan 2020 13:51:20 +0100
3247c5
Subject: [PATCH] core: Always refresh authorization when creating streams
3247c5
3247c5
Non-resumable upload streams quite often fail with authorization errors
3247c5
as we are probably hitting some limits. The only way currently to deal
3247c5
with them is to refresh authorization manually and upload everything
3247c5
again as it is not possible to resume the transfer. This is big issue
3247c5
for streaming operations provided by GVfs. I have made several tests
3247c5
and realized that if we explicitely refresh the authorization before
3247c5
the transfer, then those authorization errors doesn't occur. So let's
3247c5
always refresh the authorization when constructing the streams and do
3247c5
the same for upload streams as well as they are also affected. In theory,
3247c5
the resumable streams could solve this better, however they currently
3247c5
require content size to be specified at the beginning, which is not
3247c5
usable for the streaming operations in GVfs.
3247c5
3247c5
Fixes: https://gitlab.gnome.org/GNOME/libgdata/issues/23
3247c5
---
3247c5
 gdata/gdata-download-stream.c | 13 +++++++++++++
3247c5
 gdata/gdata-upload-stream.c   | 14 ++++++++++++++
3247c5
 2 files changed, 27 insertions(+)
3247c5
3247c5
diff --git a/gdata/gdata-download-stream.c b/gdata/gdata-download-stream.c
3247c5
index 5bfd7048..a797de68 100644
3247c5
--- a/gdata/gdata-download-stream.c
3247c5
+++ b/gdata/gdata-download-stream.c
3247c5
@@ -855,11 +855,24 @@ static gpointer
3247c5
 download_thread (GDataDownloadStream *self)
3247c5
 {
3247c5
 	GDataDownloadStreamPrivate *priv = self->priv;
3247c5
+	GDataAuthorizer *authorizer;
3247c5
 
3247c5
 	g_object_ref (self);
3247c5
 
3247c5
 	g_assert (priv->network_cancellable != NULL);
3247c5
 
3247c5
+	/* FIXME: Refresh authorization before sending message in order to prevent authorization errors during transfer.
3247c5
+	 * See: https://gitlab.gnome.org/GNOME/libgdata/issues/23 */
3247c5
+	authorizer = gdata_service_get_authorizer (priv->service);
3247c5
+	if (authorizer) {
3247c5
+		g_autoptr(GError) error = NULL;
3247c5
+
3247c5
+		gdata_authorizer_refresh_authorization (authorizer, priv->cancellable, &error);
3247c5
+		if (error != NULL)
3247c5
+			g_debug ("Error returned when refreshing authorization: %s", error->message);
3247c5
+		else
3247c5
+			gdata_authorizer_process_request (authorizer, priv->authorization_domain, priv->message);
3247c5
+	}
3247c5
 	/* Connect to the got-headers signal so we can notify clients of the values of content-type and content-length */
3247c5
 	g_signal_connect (priv->message, "got-headers", (GCallback) got_headers_cb, self);
3247c5
 	g_signal_connect (priv->message, "got-chunk", (GCallback) got_chunk_cb, self);
3247c5
diff --git a/gdata/gdata-upload-stream.c b/gdata/gdata-upload-stream.c
3247c5
index 85807fec..85738fd3 100644
3247c5
--- a/gdata/gdata-upload-stream.c
3247c5
+++ b/gdata/gdata-upload-stream.c
3247c5
@@ -1147,9 +1147,23 @@ static gpointer
3247c5
 upload_thread (GDataUploadStream *self)
3247c5
 {
3247c5
 	GDataUploadStreamPrivate *priv = self->priv;
3247c5
+	GDataAuthorizer *authorizer;
3247c5
 
3247c5
 	g_assert (priv->cancellable != NULL);
3247c5
 
3247c5
+	/* FIXME: Refresh authorization before sending message in order to prevent authorization errors during transfer.
3247c5
+	 * See: https://gitlab.gnome.org/GNOME/libgdata/issues/23 */
3247c5
+	authorizer = gdata_service_get_authorizer (priv->service);
3247c5
+	if (authorizer) {
3247c5
+		g_autoptr(GError) error = NULL;
3247c5
+
3247c5
+		gdata_authorizer_refresh_authorization (authorizer, priv->cancellable, &error);
3247c5
+		if (error != NULL)
3247c5
+			g_debug ("Error returned when refreshing authorization: %s", error->message);
3247c5
+		else
3247c5
+			gdata_authorizer_process_request (authorizer, priv->authorization_domain, priv->message);
3247c5
+	}
3247c5
+
3247c5
 	while (TRUE) {
3247c5
 		GDataServiceClass *klass;
3247c5
 		gulong wrote_headers_signal, wrote_body_data_signal;
3247c5
-- 
3247c5
2.36.0
3247c5