Subject: progress meter in pkg_add
To: None <current-users@netbsd.org>
From: Zafer Aydogan <zafer@gmx.org>
List: current-users
Date: 06/22/2005 11:48:18
Hello List,

I was thinking about, how comfortable it would be, to have a progress 
meter, while installing packages with PKG_ADD, especially, when 
installing large ones.

As we have the "progress" command, normally invoked as:
progress -zf filename.tgz tar xepf -
to show a progress bar.
I thought about integrating it in pkg_add, as the main function of it is 
to exctract a tarball aswell.
I'm not a coder, but is this possible ?


#define TAR_ARGS	" cf - "
#define TARX_CMD	"|" TAR_CMD " xpf - -C "


#define TOOBIG(str) ((strlen(str) + 3 + strlen(TARX_CMD) + 
strlen(Directory) + where_count  >= maxargs) \
		|| (strlen(str) + 3 + perm_count >= maxargs))

#define PUSHOUT(todir) /* push out string */				\
         if (where_count > sizeof(TAR_CMD) + sizeof(TAR_ARGS)-1) {		\
		    strlcat(where_args, TARX_CMD, maxargs);		\
		    strlcat(where_args, todir, maxargs);		\
		    if (system(where_args)) {				\
			cleanup(0);					\
			errx(2, "can not invoke %lu byte %s pipeline: %s", \
				(u_long)strlen(where_args), TAR_CMD,	\
				where_args);				\
		    }							\
		    strlcpy(where_args, TAR_CMD TAR_ARGS, maxargs);	\
		    where_count = strlen(where_args);			\
	}								\
	if (perm_count) {						\
		    apply_perms(todir, perm_args);			\
		    perm_args[0] = 0;					\
		    perm_count = 0;					\
	}


static void
rollback(char *name, char *home, plist_t *start, plist_t *stop)
{
	plist_t *q;
	char    try[MaxPathSize], bup[MaxPathSize], *dir;

	dir = home;
	for (q = start; q != stop; q = q->next) {
		if (q->type == PLIST_FILE) {
			(void) snprintf(try, sizeof(try), "%s/%s", dir, q->name);
			if (make_preserve_name(bup, sizeof(bup), name, try) && fexists(bup)) {
				(void) chflags(try, 0);
				(void) unlink(try);
				if (rename(bup, try))
					warnx("rollback: unable to rename %s back to %s", bup, try);
			}
		} else if (q->type == PLIST_CWD) {
			if (strcmp(q->name, "."))
				dir = q->name;
			else
				dir = home;
		}
	}
}


/*