int setuser, setgroup;
int reverse, exitonerror;
int overwrite, accept, acceptdir, ignoredirmd;
+ int ops_total, ops_completed;
+ int progress; /* type of progress meter */
};
struct nitem {
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);
/* 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;
char *pkgdbfile = 0, *localdbfile = 0;
char *s;
- struct config conf;
+ struct config conf = { 0 };
conf.errabort = 1;
conf.errors = 0;
* 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;
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);
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");
}
}
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);
+ }
}
}