[gnome-software: 18/20] gs-odrs-provider: Delete cache file if it’s invalid




commit 14e70935011d0147c4e6b5e82ccf69fe82ec52b4
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Mar 11 14:10:26 2022 +0000

    gs-odrs-provider: Delete cache file if it’s invalid
    
    This means the next time the ODRS data is refreshed, the file will be
    downloaded again, which gives a chance for it to be updated to something
    valid.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-odrs-provider.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/lib/gs-odrs-provider.c b/lib/gs-odrs-provider.c
index 40a14bcfa..b8c647e9f 100644
--- a/lib/gs-odrs-provider.c
+++ b/lib/gs-odrs-provider.c
@@ -580,10 +580,16 @@ gs_odrs_provider_refine_ratings (GsOdrsProvider  *self,
                                                              GS_UTILS_CACHE_FLAG_CREATE_DIRECTORY,
                                                              error);
 
-               if (!cache_filename ||
-                   !gs_odrs_provider_load_ratings (self, cache_filename, NULL))
+               if (!cache_filename)
                        return TRUE;
 
+               if (!gs_odrs_provider_load_ratings (self, cache_filename, NULL)) {
+                       g_autoptr(GFile) cache_file = g_file_new_for_path (cache_filename);
+                       g_debug ("Failed to load cache file ‘%s’, deleting it", cache_filename);
+                       g_file_delete (cache_file, NULL, NULL);
+                       return TRUE;
+               }
+
                locker = g_mutex_locker_new (&self->ratings_mutex);
 
                if (!self->ratings)
@@ -1380,10 +1386,14 @@ gs_odrs_provider_refresh_ratings_async (GsOdrsProvider             *self,
                if (tmp < cache_age_secs) {
                        g_debug ("%s is only %" G_GUINT64_FORMAT " seconds old, so ignoring refresh",
                                 cache_filename, tmp);
-                       if (!gs_odrs_provider_load_ratings (self, cache_filename, &error_local))
+                       if (!gs_odrs_provider_load_ratings (self, cache_filename, &error_local)) {
+                               g_debug ("Failed to load cache file ‘%s’, deleting it", cache_filename);
+                               g_file_delete (cache_file, NULL, NULL);
+
                                g_task_return_error (task, g_steal_pointer (&error_local));
-                       else
+                       } else {
                                g_task_return_boolean (task, TRUE);
+                       }
                        return;
                }
        }
@@ -1406,6 +1416,7 @@ download_ratings_cb (GObject      *source_object,
        g_autoptr(GTask) task = g_steal_pointer (&user_data);
        GsOdrsProvider *self = g_task_get_source_object (task);
        GFile *cache_file = g_task_get_task_data (task);
+       const gchar *cache_file_path = NULL;
        g_autoptr(GError) local_error = NULL;
 
        if (!gs_download_file_finish (soup_session, result, &local_error)) {
@@ -1415,12 +1426,17 @@ download_ratings_cb (GObject      *source_object,
                return;
        }
 
-       if (!gs_odrs_provider_load_ratings (self, g_file_peek_path (cache_file), &local_error))
+       cache_file_path = g_file_peek_path (cache_file);
+       if (!gs_odrs_provider_load_ratings (self, cache_file_path, &local_error)) {
+               g_debug ("Failed to load cache file ‘%s’, deleting it", cache_file_path);
+               g_file_delete (cache_file, NULL, NULL);
+
                g_task_return_new_error (task, GS_ODRS_PROVIDER_ERROR,
                                         GS_ODRS_PROVIDER_ERROR_PARSING_DATA,
                                         "%s", local_error->message);
-       else
+       } else {
                g_task_return_boolean (task, TRUE);
+       }
 }
 
 /**


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