[gnome-software/wip/mcrha/packagekit-download-size: 11/11] packagekit: Distinguish between download size and install size
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/mcrha/packagekit-download-size: 11/11] packagekit: Distinguish between download size and install size
- Date: Tue, 25 May 2021 16:24:21 +0000 (UTC)
commit a2789a905dde43dea87f0087a7dbe3425ac6e5a5
Author: Milan Crha <mcrha redhat com>
Date: Fri May 21 08:54:27 2021 +0200
packagekit: Distinguish between download size and install size
A PackageKit change [1] adds a new API to get both install size and
the download size, which can be used to distinguish between the two
sizes and give a better idea to the user about the size requirement.
[1] https://github.com/PackageKit/PackageKit/pull/476
meson.build | 3 +++
plugins/packagekit/packagekit-common.c | 34 +++++++++++++++++++++++-----------
2 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/meson.build b/meson.build
index d806ddc83..1f475ea18 100644
--- a/meson.build
+++ b/meson.build
@@ -199,6 +199,9 @@ if get_option('packagekit')
if meson.get_compiler('c').has_function('pk_package_get_update_severity', prefix: '#include
<packagekit-glib2/packagekit.h>', dependencies: packagekit)
conf.set('HAVE_PK_PACKAGE_GET_UPDATE_SEVERITY', '1')
endif
+ if meson.get_compiler('c').has_function('pk_details_get_download_size', prefix: '#include
<packagekit-glib2/packagekit.h>', dependencies: packagekit)
+ conf.set('HAVE_PK_DETAILS_GET_DOWNLOAD_SIZE', '1')
+ endif
endif
if get_option('eos_updater')
diff --git a/plugins/packagekit/packagekit-common.c b/plugins/packagekit/packagekit-common.c
index 8fd2cc4c5..bca5bc31c 100644
--- a/plugins/packagekit/packagekit-common.c
+++ b/plugins/packagekit/packagekit-common.c
@@ -475,7 +475,7 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
PkDetails *details;
const gchar *package_id;
guint j;
- guint64 size = 0;
+ guint64 download_size = 0, install_size = 0;
/* @source_ids can have as many as 200 elements (google-noto); typically
* it has 1 or 2
@@ -484,6 +484,9 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
* repository, on the order of 400 or 700 apps */
source_ids = gs_app_get_source_ids (app);
for (j = 0; j < source_ids->len; j++) {
+ #if HAVE_PK_DETAILS_GET_DOWNLOAD_SIZE
+ guint64 download_sz;
+ #endif
package_id = g_ptr_array_index (source_ids, j);
details = g_hash_table_lookup (details_collection, package_id);
if (details == NULL)
@@ -508,25 +511,34 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
GS_APP_QUALITY_LOWEST,
pk_details_get_description (details));
}
- size += pk_details_get_size (details);
+ install_size += pk_details_get_size (details);
+ #ifdef HAVE_PK_DETAILS_GET_DOWNLOAD_SIZE
+ download_sz = pk_details_get_download_size (details);
+ if (download_sz != G_MAXUINT64)
+ download_size += download_sz;
+ #endif
}
+ #ifndef HAVE_PK_DETAILS_GET_DOWNLOAD_SIZE
+ download_size = install_size;
+ #endif
+
/* the size is the size of all sources */
if (gs_app_get_state (app) == GS_APP_STATE_UPDATABLE) {
- if (size > 0 && gs_app_get_size_installed (app) == 0)
- gs_app_set_size_installed (app, size);
- if (size > 0 && gs_app_get_size_download (app) == 0)
- gs_app_set_size_download (app, size);
+ if (install_size > 0 && gs_app_get_size_installed (app) == 0)
+ gs_app_set_size_installed (app, install_size);
+ if (download_size > 0 && gs_app_get_size_download (app) == 0)
+ gs_app_set_size_download (app, download_size);
} else if (gs_app_is_installed (app)) {
if (gs_app_get_size_download (app) == 0)
gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
- if (size > 0 && gs_app_get_size_installed (app) == 0)
- gs_app_set_size_installed (app, size);
+ if (install_size > 0 && gs_app_get_size_installed (app) == 0)
+ gs_app_set_size_installed (app, install_size);
} else {
if (gs_app_get_size_installed (app) == 0)
- gs_app_set_size_installed (app, GS_APP_SIZE_UNKNOWABLE);
- if (size > 0 && gs_app_get_size_download (app) == 0)
- gs_app_set_size_download (app, size);
+ gs_app_set_size_installed (app, install_size > 0 ? install_size :
GS_APP_SIZE_UNKNOWABLE);
+ if (download_size > 0 && gs_app_get_size_download (app) == 0)
+ gs_app_set_size_download (app, download_size);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]