[gnome-software: 1/2] gs-download-utils: Ignore cancellation errors when there’s a cache hit




commit 92da7c98217856785dfea518890fa25acd3a055e
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Mar 10 14:25:05 2022 +0000

    gs-download-utils: Ignore cancellation errors when there’s a cache hit
    
    In order to avoid overwriting an existing cache file when the server has
    said it’s 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), don’t 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]