[gnome-software: 3/9] download-utils: Return new NOT_MODIFIED error if ETags match
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 3/9] download-utils: Return new NOT_MODIFIED error if ETags match
- Date: Fri, 16 Sep 2022 07:41:08 +0000 (UTC)
commit 56a9d3b4239c0841c3be5bc3b49db3d86321adbd
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Sep 12 13:56:35 2022 -0300
download-utils: Return new NOT_MODIFIED error if ETags match
The downloading routines of GNOME Software treat matching ETags
as not errors, however, there are circumstances where it'll be
important to react to this result differently from other error
paths.
Add the GS_DOWNLOAD_ERROR quark, and GS_DOWNLOAD_ERROR_NOT_MODIFIED
to represent that case. Next commits will adjust the error paths of
consumers of this API to not do anything, or react appropriately,
if that error is reported.
lib/gs-download-utils.c | 18 +++++++++++++++---
lib/gs-download-utils.h | 15 +++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/lib/gs-download-utils.c b/lib/gs-download-utils.c
index 0a0a316a1..494906483 100644
--- a/lib/gs-download-utils.c
+++ b/lib/gs-download-utils.c
@@ -28,6 +28,8 @@
#include "gs-download-utils.h"
#include "gs-utils.h"
+G_DEFINE_QUARK (gs-download-error-quark, gs_download_error)
+
/**
* gs_build_soup_session:
*
@@ -348,7 +350,11 @@ open_input_stream_cb (GObject *source_object,
data->discard_output_stream = TRUE;
data->new_etag = g_strdup (data->last_etag);
data->new_last_modified_date = (data->last_modified_date != NULL) ? g_date_time_ref
(data->last_modified_date) : NULL;
- finish_download (task, NULL);
+ finish_download (task,
+ g_error_new (GS_DOWNLOAD_ERROR,
+ GS_DOWNLOAD_ERROR_NOT_MODIFIED,
+ "Skipped downloading ā%sā: %s",
+ data->uri, soup_status_get_phrase (status_code)));
return;
} else if (status_code != SOUP_STATUS_OK) {
g_autoptr(GString) str = g_string_new (NULL);
@@ -491,6 +497,12 @@ write_bytes_cb (GObject *source_object,
}
}
+static inline gboolean
+is_not_modidifed_error (GError *error)
+{
+ return g_error_matches (error, GS_DOWNLOAD_ERROR, GS_DOWNLOAD_ERROR_NOT_MODIFIED);
+}
+
/* error is (transfer full) */
static void
finish_download (GTask *task,
@@ -500,7 +512,7 @@ finish_download (GTask *task,
GCancellable *cancellable = g_task_get_cancellable (task);
/* Final progress update. */
- if (error == NULL) {
+ if (error == NULL || is_not_modidifed_error (error)) {
data->expected_stream_size_bytes = data->total_read_bytes;
download_progress (task);
}
@@ -520,7 +532,7 @@ finish_download (GTask *task,
* output stream (perhaps because of a cache hit), close the
* output stream but cancel the close operation so that the old
* output file is not overwritten. */
- if (data->error != NULL || data->discard_output_stream) {
+ if ((data->error != NULL && !is_not_modidifed_error (data->error)) ||
data->discard_output_stream) {
output_cancellable = g_cancellable_new ();
g_cancellable_cancel (output_cancellable);
} else if (g_task_get_cancellable (task) != NULL) {
diff --git a/lib/gs-download-utils.h b/lib/gs-download-utils.h
index 6ab568579..cd9dd46cd 100644
--- a/lib/gs-download-utils.h
+++ b/lib/gs-download-utils.h
@@ -40,6 +40,21 @@ typedef void (*GsDownloadProgressCallback) (gsize bytes_downloaded,
gsize total_download_size,
gpointer user_data);
+/**
+ * GsExternalAppstreamError:
+ * @GS_DOWNLOAD_ERROR_NOT_MODIFIED: The ETag matches that of the server file.
+ *
+ * Error codes for download operations.
+ *
+ * Since: 44
+ */
+typedef enum {
+ GS_DOWNLOAD_ERROR_NOT_MODIFIED,
+} GsDownloadError;
+
+#define GS_DOWNLOAD_ERROR gs_download_error_quark ()
+GQuark gs_download_error_quark (void);
+
void gs_download_stream_async (SoupSession *soup_session,
const gchar *uri,
GOutputStream *output_stream,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]