summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAppadeia <uhhadd@gmail.com>2020-03-29 13:17:15 -0400
committerGitHub <noreply@github.com>2020-03-29 13:17:15 -0400
commita64ed7e64b99320741630280ad1c5a66a39f81df (patch)
treeccd9179751567776663f61c98db96970e0f0ba1e
parentad56b4efc460cc5e6677b503893ba8a6c4f847ba (diff)
parent425058be365c608334cd1d48db597cf2ab6a64a7 (diff)
Merge pull request #389 from Appadeia/issues/70
alpm: improve dlcb handling
-rw-r--r--backends/alpm/pk-alpm-transaction.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/backends/alpm/pk-alpm-transaction.c b/backends/alpm/pk-alpm-transaction.c
index ff4c1ad8c..c81380665 100644
--- a/backends/alpm/pk-alpm-transaction.c
+++ b/backends/alpm/pk-alpm-transaction.c
@@ -28,8 +28,8 @@
#include <syslog.h>
-static off_t dcomplete = 0;
-static off_t dtotal = 0;
+static off_t transaction_dcomplete = 0;
+static off_t transaction_dtotal = 0;
static alpm_pkg_t *dpkg = NULL;
static GString *dfiles = NULL;
@@ -136,11 +136,11 @@ pk_alpm_transaction_totaldlcb (off_t total)
g_assert (pkalpm_current_job);
job = pkalpm_current_job;
- if (dtotal > 0 && dpkg != NULL)
+ if (transaction_dtotal > 0 && dpkg != NULL)
pk_alpm_transaction_download_end (job);
- dcomplete = 0;
- dtotal = total;
+ transaction_dcomplete = 0;
+ transaction_dtotal = total;
}
static void
@@ -152,35 +152,48 @@ pk_alpm_transaction_dlcb (const gchar *basename, off_t complete, off_t total)
g_assert (pkalpm_current_job);
job = pkalpm_current_job;
- /* download start signal */
- if (total == -1) return;
+ g_return_if_fail(basename != NULL);
- g_return_if_fail (basename != NULL);
- g_return_if_fail (complete <= total);
+ // these conditions are documented in libalpm/dload.c
+ if (complete == 0 && total == -1) { // initialized download
+ g_debug ("downloading file %s", basename);
+ pk_backend_job_set_status (job, PK_STATUS_ENUM_DOWNLOAD);
+ pk_alpm_transaction_download_start (job, basename);
- if (total > 0)
- sub_percentage = complete * 100 / total;
+ } else if (complete == 0 && total == 0) { // doing non-download event
+ return;
- if (dtotal > 0) {
- percentage = (dcomplete + complete) * 100 / dtotal;
- } else if (dtotal < 0) {
- /* database files */
- percentage = (dcomplete * 100 + sub_percentage) / -dtotal;
+ } else if (complete > 0 && complete == total) { // download is complete
+ pk_backend_job_set_percentage(job, 100);
+ transaction_dcomplete += complete;
+
+ } else if (complete > 0 && complete < total && total > 0) { // download in progress
+ sub_percentage = (complete * 100) / (total);
+ if (transaction_dtotal > 0) {
+ // positive totals indicate packages
+ percentage = ((transaction_dcomplete + complete) * 100) / transaction_dtotal;
+
+ pk_backend_job_set_percentage (job, percentage);
+ } else if (transaction_dtotal < 0) {
+ // negative totals indicate databases
+ guint total_databases = -transaction_dtotal;
+ static off_t previous_total = 0;
+ static guint current_database = 0;
+
+ if (total != previous_total) {
+ current_database++;
+ previous_total = total;
+ }
- if (complete == total)
- complete = total = 1;
- else
- complete = total + 1;
- }
+ percentage = ((current_database-1)*100) / total_databases;
+ percentage += sub_percentage / total_databases;
- if (complete == 0) {
- g_debug ("downloading file %s", basename);
- pk_backend_job_set_status (job, PK_STATUS_ENUM_DOWNLOAD);
- pk_alpm_transaction_download_start (job, basename);
- } else if (complete == total) {
- dcomplete += complete;
+ pk_backend_job_set_percentage (job, percentage);
+ }
+
+ } else {
+ syslog (LOG_DAEMON | LOG_WARNING, "unhandled download callback case, most likely libalpm change or error");
}
- pk_backend_job_set_percentage (job, percentage);
}
static void