[epiphany/gnome-3-32] web-app-utils: Delete app cache and config dirs when deleting app



commit 795f115cb495cdb1944297c1d1ba2eeaa1c29f25
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sat Mar 16 13:02:22 2019 -0500

    web-app-utils: Delete app cache and config dirs when deleting app
    
    Currently we only remove the profile dir and desktop file, but since
    3.32 we have separate cache and config dirs that need to be removed too.

 lib/ephy-web-app-utils.c | 51 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 7 deletions(-)
---
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index cb18f4ddb..a1eab2668 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -156,6 +156,19 @@ get_app_id_from_profile_directory (const char *profile_dir)
   return program_name ? get_app_id_from_program_name (program_name) : NULL;
 }
 
+static char *
+ephy_web_application_get_directory_under (const char *id,
+                                          const char *path)
+{
+  g_autofree char *app_dir = NULL;
+
+  app_dir = get_app_profile_directory_name (id);
+  if (!app_dir)
+    return NULL;
+
+  return g_build_filename (path, app_dir, NULL);
+}
+
 /**
  * ephy_web_application_get_profile_directory:
  * @id: the application identifier
@@ -167,15 +180,19 @@ get_app_id_from_profile_directory (const char *profile_dir)
 char *
 ephy_web_application_get_profile_directory (const char *id)
 {
-  g_autofree char *app_dir = NULL;
-  g_autofree char *profile_dir = NULL;
+  return ephy_web_application_get_directory_under (id, g_get_user_data_dir ());
+}
 
-  app_dir = get_app_profile_directory_name (id);
-  if (!app_dir)
-    return NULL;
+static char *
+ephy_web_application_get_cache_directory (const char *id)
+{
+  return ephy_web_application_get_directory_under (id, g_get_user_cache_dir ());
+}
 
-  profile_dir = g_build_filename (g_get_user_data_dir (), app_dir, NULL);
-  return g_steal_pointer (&profile_dir);
+static char *
+ephy_web_application_get_config_directory (const char *id)
+{
+  return ephy_web_application_get_directory_under (id, g_get_user_config_dir ());
 }
 
 /**
@@ -191,6 +208,8 @@ gboolean
 ephy_web_application_delete (const char *id)
 {
   g_autofree char *profile_dir = NULL;
+  g_autofree char *cache_dir = NULL;
+  g_autofree char *config_dir = NULL;
   g_autofree char *desktop_file = NULL;
   g_autofree char *desktop_path = NULL;
   g_autoptr(GFile) launcher = NULL;
@@ -215,6 +234,24 @@ ephy_web_application_delete (const char *id)
   }
   LOG ("Deleted application profile.\n");
 
+  cache_dir = ephy_web_application_get_cache_directory (id);
+  if (g_file_test (cache_dir, G_FILE_TEST_IS_DIR)) {
+    if (!ephy_file_delete_dir_recursively (cache_dir, &error)) {
+      g_warning ("Failed to recursively delete %s: %s", cache_dir, error->message);
+      return FALSE;
+    }
+    LOG ("Deleted application cache directory.\n");
+  }
+
+  config_dir = ephy_web_application_get_config_directory (id);
+  if (g_file_test (config_dir, G_FILE_TEST_IS_DIR)) {
+    if (!ephy_file_delete_dir_recursively (config_dir, &error)) {
+      g_warning ("Failed to recursively delete %s: %s", config_dir, error->message);
+      return FALSE;
+    }
+    LOG ("Deleted application config directory.\n");
+  }
+
   desktop_file = get_app_desktop_filename (id);
   if (!desktop_file) {
     g_warning ("Failed to compute desktop filename for app %s", id);


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