From 17744ae701e5a543ee6fe0d752330f1bbef56a42 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Mon, 3 Dec 2018 08:16:21 +0000 Subject: [PATCH] change sync default verbosity add options for detailed file list --- zpm-syncfs.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/zpm-syncfs.c b/zpm-syncfs.c index c2ee846..aac86b5 100644 --- a/zpm-syncfs.c +++ b/zpm-syncfs.c @@ -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); + } } } -- 2.40.0