[gnome-software/1909-external-appstream-installer-leaves-old-files-behind-in-legacy-locations] gs-external-appstream: Remove old files from legacy path



commit 99c5f85fb5a477547e783fcd5810415cdc71a588
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 20 17:58:41 2022 +0200

    gs-external-appstream: Remove old files from legacy path
    
    Since the path the external appstream data files are stored changed,
    users with old files updating gnome-sftware to a version with the changed
    path would have left the old files with no chance to have them deleted
    other than manually by themselves. This tries to delete the file in
    the legacy path first and moves the file to the new location.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1909

 lib/gs-external-appstream-utils.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-external-appstream-utils.c b/lib/gs-external-appstream-utils.c
index e9e0a12f8..24ce3a87a 100644
--- a/lib/gs-external-appstream-utils.c
+++ b/lib/gs-external-appstream-utils.c
@@ -48,8 +48,10 @@
  * Since: 42
  */
 
+#include <errno.h>
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <libsoup/soup.h>
 
 #include "gs-external-appstream-utils.h"
@@ -209,15 +211,32 @@ refresh_url_async (GSettings           *settings,
        system_wide = g_settings_get_boolean (settings, "external-appstream-system-wide");
 
        /* Check cache file age. */
-       if (system_wide)
+       if (system_wide) {
                target_file_path = gs_external_appstream_utils_get_file_cache_path (basename);
-       else
+       } else {
+               g_autofree gchar *legacy_file_path = NULL;
+
                target_file_path = g_build_filename (g_get_user_data_dir (),
                                                     "swcatalog",
                                                     "xml",
                                                     basename,
                                                     NULL);
 
+               /* Delete an old file, from a legacy location */
+               legacy_file_path = g_build_filename (g_get_user_data_dir (),
+                                                    "app-info",
+                                                    "xmls",
+                                                    basename,
+                                                    NULL);
+
+               if (g_unlink (legacy_file_path) == -1) {
+                       int errn = errno;
+                       if (errn != ENOENT)
+                               g_debug ("Failed to unlink '%s': %s", legacy_file_path, g_strerror (errn));
+
+               }
+       }
+
        target_file = g_file_new_for_path (target_file_path);
 
        if (!gs_external_appstream_check (target_file, cache_age_secs)) {


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