]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Show progressbar when scanning for packages
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 14:15:28 +0000 (14:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 14:15:28 +0000 (14:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index 7abf9b6230caa88b34c3cab871510659c9be4eba..fb999b432211799ec0e002482f05b2f6b019b6dc 100644 (file)
 #include <pakfire/errno.h>
 #include <pakfire/file.h>
 #include <pakfire/filelist.h>
+#include <pakfire/i18n.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/pakfire.h>
 #include <pakfire/private.h>
+#include <pakfire/progressbar.h>
 #include <pakfire/repo.h>
 #include <pakfire/types.h>
 #include <pakfire/util.h>
@@ -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;