[epiphany/mcatanzaro/webapp-profile: 10/21] web-app-utils: Delete app cache and config dirs when deleting app



commit 9681592b4abf5c4012dce3db74d2fde9a1f9a338
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 | 53 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 7 deletions(-)
---
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index cb18f4ddb..407f5f3db 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -156,6 +156,21 @@ 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;
+  g_autofree char *profile_dir = NULL;
+
+  app_dir = get_app_profile_directory_name (id);
+  if (!app_dir)
+    return NULL;
+
+  profile_dir = g_build_filename (path, app_dir, NULL);
+  return g_steal_pointer (&profile_dir);
+}
+
 /**
  * ephy_web_application_get_profile_directory:
  * @id: the application identifier
@@ -167,15 +182,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 +210,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 +236,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]