Add upstream patches for gs-download-utils (i#1677 and i#1679)

This commit is contained in:
Milan Crha 2022-03-10 17:34:44 +01:00
parent f3f073c56f
commit 154dca4c08
3 changed files with 233 additions and 1 deletions

182
1282.patch Normal file
View File

@ -0,0 +1,182 @@
From edbeab87ce5aa48bd9fe49dd22acfcce2b8b0fc0 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 10 Mar 2022 13:20:58 +0000
Subject: [PATCH 1/3] =?UTF-8?q?gs-download-utils:=20Don=E2=80=99t=20use=20?=
=?UTF-8?q?ETag=20when=20writing=20local=20file?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The ETag we care about for the download is the ETag returned by the
server, not the ETag of the local file. Passing the servers ETag to the
local file operations may result in the local file not being written to,
with a “The file was externally modified” error.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: #1677
---
lib/gs-download-utils.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/gs-download-utils.c b/lib/gs-download-utils.c
index f3a64479b..a6d930587 100644
--- a/lib/gs-download-utils.c
+++ b/lib/gs-download-utils.c
@@ -134,6 +134,9 @@ static void download_progress (GTask *task);
* existing content of the output stream (if its a file, for example) will not
* be overwritten.
*
+ * Note that @last_etag must be the ETag value returned by the server last time
+ * the file was downloaded, not the local file ETag generated by GLib.
+ *
* If specified, @progress_callback will be called zero or more times until
* @callback is called, providing progress updates on the download.
*
@@ -644,9 +647,20 @@ gs_download_file_async (SoupSession *soup_session,
/* Query the old ETag if the file already exists. */
data->last_etag = gs_utils_get_file_etag (output_file, cancellable);
- /* Create the output file. */
+ /* Create the output file.
+ *
+ * Note that `data->last_etag` is *not* passed in here, as the ETag from
+ * the server and the file modification ETag that GLib uses are
+ * different things. For g_file_replace_async(), GLib always uses an
+ * ETag it generates internally based on the file mtime (see
+ * _g_local_file_info_create_etag()), which will never match what the
+ * server returns in its ETag header.
+ *
+ * This is fine, as we are using the ETag to avoid an unnecessary HTTP
+ * download if possible. We dont care about tracking changes to the
+ * file on disk. */
g_file_replace_async (output_file,
- data->last_etag,
+ NULL, /* ETag */
FALSE, /* make_backup */
G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION,
io_priority,
@@ -699,7 +713,7 @@ download_file_cb (GObject *source_object,
return;
}
- /* Update the ETag. */
+ /* Update the stored HTTP ETag. */
gs_utils_set_file_etag (data->output_file, new_etag, cancellable);
g_task_return_boolean (task, TRUE);
--
GitLab
From 040e2dca3904d965450158dcdaeedfca12965682 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 10 Mar 2022 13:27:21 +0000
Subject: [PATCH 2/3] gs-utils: Add some debug messages for getting/setting
ETags
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #1677
---
lib/gs-utils.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 89349b1fe..6dc4d28a0 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1509,14 +1509,18 @@ gs_utils_get_file_etag (GFile *file,
GCancellable *cancellable)
{
g_autoptr(GFileInfo) info = NULL;
+ g_autoptr(GError) local_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- info = g_file_query_info (file, METADATA_ETAG_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, cancellable, NULL);
+ info = g_file_query_info (file, METADATA_ETAG_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, cancellable, &local_error);
- if (info == NULL)
+ if (info == NULL) {
+ g_debug ("Error getting attribute %s for file %s: %s",
+ METADATA_ETAG_ATTRIBUTE, g_file_peek_path (file), local_error->message);
return NULL;
+ }
return g_strdup (g_file_info_get_attribute_string (info, METADATA_ETAG_ATTRIBUTE));
}
@@ -1542,15 +1546,29 @@ gs_utils_set_file_etag (GFile *file,
const gchar *etag,
GCancellable *cancellable)
{
+ g_autoptr(GError) local_error = NULL;
+
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
if (etag == NULL || *etag == '\0') {
- return g_file_set_attribute (file, METADATA_ETAG_ATTRIBUTE, G_FILE_ATTRIBUTE_TYPE_INVALID,
- NULL, G_FILE_QUERY_INFO_NONE, cancellable, NULL);
+ if (!g_file_set_attribute (file, METADATA_ETAG_ATTRIBUTE, G_FILE_ATTRIBUTE_TYPE_INVALID,
+ NULL, G_FILE_QUERY_INFO_NONE, cancellable, &local_error)) {
+ g_debug ("Error clearing attribute %s on file %s: %s",
+ METADATA_ETAG_ATTRIBUTE, g_file_peek_path (file), local_error->message);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ if (!g_file_set_attribute_string (file, METADATA_ETAG_ATTRIBUTE, etag, G_FILE_QUERY_INFO_NONE, cancellable, &local_error)) {
+ g_debug ("Error setting attribute %s to %s on file %s: %s",
+ METADATA_ETAG_ATTRIBUTE, etag, g_file_peek_path (file), local_error->message);
+ return FALSE;
}
- return g_file_set_attribute_string (file, METADATA_ETAG_ATTRIBUTE, etag, G_FILE_QUERY_INFO_NONE, cancellable, NULL);
+ return TRUE;
}
/**
--
GitLab
From c46d656c51938adb994b4597c766259bf1813fe5 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 10 Mar 2022 13:27:50 +0000
Subject: [PATCH 3/3] gs-utils: Change ETag attribute namespace from metadata
to xattr
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The xattr namespace is likely to be supported on all modern Linux
distributions for local files, and doesnt require IPC with
`gvfsd-metadata`.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #1677
---
lib/gs-utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 6dc4d28a0..b8eefe36e 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1488,7 +1488,7 @@ gs_utils_get_file_size (const gchar *filename,
return size;
}
-#define METADATA_ETAG_ATTRIBUTE "metadata::etag"
+#define METADATA_ETAG_ATTRIBUTE "xattr::gnome-software::etag"
/**
* gs_utils_get_file_etag:
--
GitLab

45
1285.patch Normal file
View File

@ -0,0 +1,45 @@
From 92da7c98217856785dfea518890fa25acd3a055e Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Thu, 10 Mar 2022 14:25:05 +0000
Subject: [PATCH] =?UTF-8?q?gs-download-utils:=20Ignore=20cancellation=20er?=
=?UTF-8?q?rors=20when=20there=E2=80=99s=20a=20cache=20hit?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In order to avoid overwriting an existing cache file when the server has
said its up to date, we cancel closing the output stream.
Avoid propagating that cancellation error up to the caller; to them, the
operation should seem like a success rather than returning
`G_IO_ERROR_CANCELLED`.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: #1679
---
lib/gs-download-utils.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/gs-download-utils.c b/lib/gs-download-utils.c
index f3a64479b..4ab15c098 100644
--- a/lib/gs-download-utils.c
+++ b/lib/gs-download-utils.c
@@ -467,7 +467,13 @@ close_stream_cb (GObject *source_object,
* overwrite errors set earlier in the operation. */
if (!g_output_stream_close_finish (G_OUTPUT_STREAM (source_object),
result, &local_error)) {
- if (data->error == NULL)
+ /* If we are aborting writing the output stream (perhaps
+ * because of a cache hit), dont report the error at
+ * all. */
+ if (data->discard_output_stream &&
+ g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_clear_error (&local_error);
+ else if (data->error == NULL)
data->error = g_steal_pointer (&local_error);
else if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_debug ("Error closing output stream: %s", local_error->message);
--
GitLab

View File

@ -13,7 +13,7 @@
Name: gnome-software Name: gnome-software
Version: 42~rc Version: 42~rc
Release: 1%{?dist} Release: 2%{?dist}
Summary: A software center for GNOME Summary: A software center for GNOME
License: GPLv2+ License: GPLv2+
@ -21,6 +21,8 @@ URL: https://wiki.gnome.org/Apps/Software
Source0: https://download.gnome.org/sources/gnome-software/42/%{name}-%{tarball_version}.tar.xz Source0: https://download.gnome.org/sources/gnome-software/42/%{name}-%{tarball_version}.tar.xz
Patch01: 0001-crash-with-broken-theme.patch Patch01: 0001-crash-with-broken-theme.patch
Patch02: 1282.patch
Patch03: 1285.patch
BuildRequires: appstream-devel >= %{appstream_version} BuildRequires: appstream-devel >= %{appstream_version}
BuildRequires: gcc BuildRequires: gcc
@ -198,6 +200,9 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
%{_datadir}/gtk-doc/html/gnome-software %{_datadir}/gtk-doc/html/gnome-software
%changelog %changelog
* Thu Mar 10 2022 Milan Crha <mcrha@redhat.com> - 42.rc-2
- Add upstream patches for gs-download-utils (i#1677 and i#1679)
* Mon Mar 07 2022 Milan Crha <mcrha@redhat.com> - 42.rc-1 * Mon Mar 07 2022 Milan Crha <mcrha@redhat.com> - 42.rc-1
- Update to 42.rc - Update to 42.rc