]> pd.if.org Git - zpackage/commitdiff
change sync default verbosity
authorNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 08:16:21 +0000 (08:16 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 08:16:21 +0000 (08:16 +0000)
add options for detailed file list

zpm-syncfs.c

index c2ee8463b9eeeef7cd522b13ceb544616dec414f..aac86b576c4a0dc33fa942fc742eb89a3d93e579 100644 (file)
@@ -31,6 +31,8 @@ struct config {
        int setuser, setgroup;
        int reverse, exitonerror;
        int overwrite, accept, acceptdir, ignoredirmd;
+       int ops_total, ops_completed;
+       int progress; /* type of progress meter */
 };
 
 struct nitem {
@@ -939,8 +941,27 @@ static int install_files(void *f, int ncols, char **vals, char **cols) {
        fprintf(stderr, "memory = %ld MB / %ld MB\n", used, high);
 #endif
        if (conf->verbose && !conf->dryrun) {
-               fprintf(stderr, "%s '%c' %s\n", nitem.opstr, nitem.ftype,
-                               nitem.dest);
+               if (conf->progress == 2) {
+                       fprintf(stderr, "%s '%c' %s\n", nitem.opstr, nitem.ftype,
+                                       nitem.dest);
+               } else if (conf->progress == 1) {
+                       /* overwrite */
+                       /* one dot per 2% */
+                       int was = 50 * conf->ops_completed / conf->ops_total;
+                       int now = 50 * (conf->ops_completed+1) / conf->ops_total;
+                       while (was++ < now) {
+                               fprintf(stderr, ".");
+                       }
+                       conf->ops_completed++;
+               } else {
+                       /* one dot per 2% */
+                       int was = 50 * conf->ops_completed / conf->ops_total;
+                       int now = 50 * (conf->ops_completed+1) / conf->ops_total;
+                       while (was++ < now) {
+                               fprintf(stderr, ".");
+                       }
+                       conf->ops_completed++;
+               }
        }
 
        unsigned int diffs = file_compare(&nitem, &existing);
@@ -1300,6 +1321,10 @@ static void runstage(struct config *conf, char *stage,
        /* TODO final report function in conf var */
 }
 
+static int count_ops(struct config *conf) {
+       return zpm_db_int(conf->log, "select count(*) from syncinfo where op in ('remove', 'update', 'new')");
+}
+
 int main(int ac, char **av) {
        struct zpm localdb;
        struct zpm pkgdb;
@@ -1307,7 +1332,7 @@ int main(int ac, char **av) {
        char *pkgdbfile = 0, *localdbfile = 0;
        char *s;
 
-       struct config conf;
+       struct config conf = { 0 };
 
        conf.errabort = 1;
        conf.errors = 0;
@@ -1349,7 +1374,7 @@ int main(int ac, char **av) {
         *  args are pkgid triple, but will do a pkg find on the pkgdb
         */
 
-       while ((opt = getopt(ac, av, "f:d:c:nCR:vOAMD")) != -1) {
+       while ((opt = getopt(ac, av, "f:d:c:nCR:vOAMDp")) != -1) {
                switch (opt) {
                        case 'd': localdbfile = optarg; break;
                        case 'f': pkgdbfile = optarg; break;
@@ -1362,6 +1387,7 @@ int main(int ac, char **av) {
                        case 'A': conf.accept = 1; break;
                        case 'M': conf.ignoredirmd = 1;
                        case 'D': conf.acceptdir = 0;
+                       case 'p': conf.progress++;
                        default:
                                  usage();
                                  exit(EXIT_FAILURE);
@@ -1427,6 +1453,8 @@ int main(int ac, char **av) {
                        conf.exitonerror = conf.dryrun ? 0 : 1;
                        conf.errabort = conf.dryrun ? 0 : 1;
                        conf.reverse = 1;
+                       conf.ops_total = count_ops(&conf);
+                       fprintf(stderr, "file ops: %d\n", conf.ops_total);
                        if (conf.verbose) {
                                fprintf(stderr, "removing old files\n");
                        }
@@ -1437,9 +1465,13 @@ int main(int ac, char **av) {
                        }
                        runstage(&conf, "update", install_files);
                        if (conf.verbose) {
-                               fprintf(stderr, "installing files\n");
+                               fprintf(stderr, "installing %d files\n", conf.ops_total);
                        }
                        runstage(&conf, "new", install_files);
+                       if (conf.verbose && conf.progress < 2) {
+                               fprintf(stderr, " done\n");
+                               fflush(stderr);
+                       }
                }
        }