[gnome-software/1296-calculate-app-space-usage-for-download-context-tile: 3/3] flatpak: Calculate cache and user data sizes for installed applications




commit c6d96d858ea7aca6941ec7ba5fc60cf40df65bda
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 28 19:45:21 2021 +0200

    flatpak: Calculate cache and user data sizes for installed applications
    
    It can be done, because the directories for the user data and the cache data
    are known.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1296

 plugins/flatpak/gs-flatpak.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 7e9c571f8..f5d7306c7 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2514,6 +2514,16 @@ gs_flatpak_prune_addons_list (GsFlatpak *self,
        return TRUE;
 }
 
+static guint64
+gs_flatpak_get_app_directory_size (GsApp *app,
+                                  const gchar *subdir_name,
+                                  GCancellable *cancellable)
+{
+       g_autofree gchar *filename = NULL;
+       filename = g_build_filename (g_get_home_dir (), ".var", "app", gs_app_get_id (app), subdir_name, 
NULL);
+       return gs_utils_get_file_size (filename, NULL, NULL, cancellable);
+}
+
 static gboolean
 gs_plugin_refine_item_size (GsFlatpak *self,
                            GsApp *app,
@@ -3007,6 +3017,21 @@ gs_flatpak_refine_app_unlocked (GsFlatpak *self,
                }
        }
 
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE_DATA) != 0 &&
+           gs_app_is_installed (app) &&
+           gs_app_get_kind (app) != AS_COMPONENT_KIND_RUNTIME) {
+               if (gs_app_get_size_cache_data (app) == GS_APP_SIZE_UNKNOWABLE)
+                       gs_app_set_size_cache_data (app, gs_flatpak_get_app_directory_size (app, "cache", 
cancellable));
+               if (gs_app_get_size_user_data (app) == GS_APP_SIZE_UNKNOWABLE)
+                       gs_app_set_size_user_data (app, gs_flatpak_get_app_directory_size (app, "config", 
cancellable) +
+                                                       gs_flatpak_get_app_directory_size (app, "data", 
cancellable));
+
+               if (g_cancellable_is_cancelled (cancellable)) {
+                       gs_app_set_size_cache_data (app, GS_APP_SIZE_UNKNOWABLE);
+                       gs_app_set_size_user_data (app, GS_APP_SIZE_UNKNOWABLE);
+               }
+       }
+
        /* origin-hostname */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME) {
                if (!gs_plugin_refine_item_origin_hostname (self, app,


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