From: Michael Tremer Date: Tue, 6 Apr 2021 14:15:28 +0000 (+0000) Subject: repo: Show progressbar when scanning for packages X-Git-Tag: 0.9.28~1285^2~435 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d61f393fb83a0e29006d481c9b1b3b34d2fb9b64;p=pakfire.git repo: Show progressbar when scanning for packages Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 7abf9b623..fb999b432 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -38,10 +38,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -760,6 +762,8 @@ static int pakfire_repo_scan_file(PakfireRepo repo, const char* path) { } PAKFIRE_EXPORT int pakfire_repo_scan(PakfireRepo repo, int flags) { + struct pakfire_progressbar* progressbar = NULL; + char* path = pakfire_repo_get_path(repo); if (!path) return EINVAL; @@ -779,9 +783,37 @@ PAKFIRE_EXPORT int pakfire_repo_scan(PakfireRepo repo, int flags) { // Fetch how many files have been found const size_t num_files = pakfire_filelist_size(filelist); + // Create progressbar + r = pakfire_progressbar_create(&progressbar, repo->pakfire, NULL); + if (r) + goto ERROR; + + const char* name = pakfire_repo_get_name(repo); + + // Add title to progressbar + r = pakfire_progressbar_add_string(progressbar, _("Scanning %s"), name); + if (r) + goto ERROR; + + // Add the bar + r = pakfire_progressbar_add_bar(progressbar); + if (r) + goto ERROR; + + // Add a counter + r = pakfire_progressbar_add_counter(progressbar); + if (r) + goto ERROR; + + // Start progress bar + r = pakfire_progressbar_start(progressbar, num_files); + for (unsigned int i = 0; i < num_files; i++) { PakfireFile file = pakfire_filelist_get(filelist, i); + // Increment progress bar + pakfire_progressbar_increment(progressbar); + // Skip anything that isn't a regular file int type = pakfire_file_get_type(file); if (type != S_IFREG) { @@ -801,7 +833,17 @@ PAKFIRE_EXPORT int pakfire_repo_scan(PakfireRepo repo, int flags) { pakfire_file_unref(file); } + // Finish the progress bar + r = pakfire_progressbar_finish(progressbar); + if (r) + goto ERROR; + + // Success + r = 0; + ERROR: + if (progressbar) + pakfire_progressbar_unref(progressbar); pakfire_filelist_unref(filelist); return r;