[gnome-software: 8/9] external-appstream: Delete empty file if not modified on server




commit e2f21d6239d26d65f9f06f9d644b32c2ee6424b4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Sep 12 14:11:09 2022 -0300

    external-appstream: Delete empty file if not modified on server
    
    On system-wide AppStream installations, if the external AppStream
    file has an ETag that matches that of the server, GNOME Software
    does not remove the temporary file which is created right before
    the download operation started.
    
    Now that we know when such cases happen, through the new error
    id GS_DOWNLOAD_ERROR_NOT_MODIFIED, remove the temporary download
    file if it's a system-wide installation.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1902

 lib/gs-external-appstream-utils.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-external-appstream-utils.c b/lib/gs-external-appstream-utils.c
index 9fcbc69ef..e22b642b0 100644
--- a/lib/gs-external-appstream-utils.c
+++ b/lib/gs-external-appstream-utils.c
@@ -329,17 +329,26 @@ download_stream_cb (GObject      *source_object,
        g_autofree gchar *new_etag = NULL;
 
        if (!gs_download_stream_finish (soup_session, result, &new_etag, NULL, &local_error)) {
-               if (!g_network_monitor_get_network_available (g_network_monitor_get_default ()))
+               if (data->system_wide && g_error_matches (local_error, GS_DOWNLOAD_ERROR, 
GS_DOWNLOAD_ERROR_NOT_MODIFIED)) {
+                       g_debug ("External AppStream file not modified, removing temporary download file %s",
+                                g_file_peek_path (data->output_file));
+
+                       /* System-wide installs should delete the empty file created when preparing to
+                        * download the external AppStream file. */
+                       g_file_delete_async (data->output_file, G_PRIORITY_LOW, NULL, NULL, NULL);
+                       g_task_return_boolean (task, TRUE);
+               } else if (!g_network_monitor_get_network_available (g_network_monitor_get_default ())) {
                        g_task_return_new_error (task,
                                                 GS_EXTERNAL_APPSTREAM_ERROR,
                                                 GS_EXTERNAL_APPSTREAM_ERROR_NO_NETWORK,
                                                 "External AppStream could not be downloaded due to being 
offline");
-               else
+               } else {
                        g_task_return_new_error (task,
                                                 GS_EXTERNAL_APPSTREAM_ERROR,
                                                 GS_EXTERNAL_APPSTREAM_ERROR_DOWNLOADING,
                                                 "Server returned no data for external AppStream file: %s",
                                                 local_error->message);
+               }
                return;
        }
 


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