Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress information during package download and install phases. #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ static uint8_t said = 0;
FILE *err_fp = NULL;
long int rm_filepos = -1, in_filepos = -1;
char pkgtools_flags[5];
int current_download;
int total_install;
int total_download;

#ifndef DEBUG
static char *
Expand All @@ -69,6 +72,17 @@ pkg_download(Plisthead *installhead)

printf(MSG_DOWNLOAD_PKGS);

SLIST_FOREACH(pinstall, installhead, next) {
snprintf(pkg_fs, BUFSIZ,
"%s/%s%s", pkgin_cache, pinstall->depend, PKG_EXT);

/* already fully downloaded */
if (stat(pkg_fs, &st) == 0 &&
st.st_size == pinstall->file_size &&
pinstall->file_size != 0)
total_download--;
}

SLIST_FOREACH(pinstall, installhead, next) {
snprintf(pkg_fs, BUFSIZ,
"%s/%s%s", pkgin_cache, pinstall->depend, PKG_EXT);
Expand All @@ -83,7 +97,7 @@ pkg_download(Plisthead *installhead)
/* already fully downloaded */
if (stat(pkg_fs, &st) == 0 &&
st.st_size == pinstall->file_size &&
pinstall->file_size != 0 )
pinstall->file_size != 0)
continue;

snprintf(query, BUFSIZ, PKG_URL, pinstall->depend);
Expand All @@ -109,6 +123,8 @@ pkg_download(Plisthead *installhead)
if ((fp = fopen(pkg_fs, "w")) == NULL)
err(EXIT_FAILURE, MSG_ERR_OPEN, pkg_fs);

current_download++;

if ((size = download_pkg(pkg_url, fp)) == -1) {
fprintf(stderr, MSG_PKG_NOT_AVAIL, pinstall->depend);
rc = EXIT_FAILURE;
Expand Down Expand Up @@ -271,7 +287,7 @@ do_pkg_remove(Plisthead *removehead)
static int
do_pkg_install(Plisthead *installhead)
{
int rc = EXIT_SUCCESS;
int rc = EXIT_SUCCESS, current_install = 0;
Pkglist *pinstall;
char pkgpath[BUFSIZ], preserve[BUFSIZ];
#ifndef DEBUG
Expand All @@ -289,6 +305,7 @@ do_pkg_install(Plisthead *installhead)
if (pinstall->file_size == -1)
continue;

printf(MSG_PROGRESS, ++current_install, total_install);
printf(MSG_INSTALLING, pinstall->depend);
snprintf(pkgpath, BUFSIZ,
"%s/%s%s", pkgin_cache, pinstall->depend, PKG_EXT);
Expand Down Expand Up @@ -447,6 +464,9 @@ pkgin_install(char **opkgargs, uint8_t do_inst)
removenum++;
break;
}

total_download = installnum;
total_install = installnum;
}

(void)humanize_number(h_fsize, H_BUF, (int64_t)file_size, "",
Expand Down
11 changes: 9 additions & 2 deletions download.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

int fetchTimeout = 15; /* wait 15 seconds before timeout */
size_t fetch_buffer = 1024;
int total_install;
int current_download;
int total_download;

/*
* Open a pkg_summary and if newer than local return an open libfetch
Expand Down Expand Up @@ -173,7 +176,7 @@ download_pkg(char *pkg_url, FILE *fp)
struct url *url;
fetchIO *f = NULL;
char buf[4096];
char *pkg, *ptr;
char *pkg, *ptr, progress_and_pkg[BUFSIZ];

if ((url = fetchParseURL(pkg_url)) == NULL)
errx(EXIT_FAILURE, "%s: parse failure", pkg_url);
Expand All @@ -190,12 +193,16 @@ download_pkg(char *pkg_url, FILE *fp)
else
pkg = (char *)pkg_url; /* should not happen */

/* Add progress info */
snprintf(progress_and_pkg, BUFSIZ,
MSG_PROGRESS"%s", current_download, total_download, pkg);

if (parsable) {
printf(MSG_DOWNLOAD_START, pkg);
} else {
printf(MSG_DOWNLOADING, pkg);
fflush(stdout);
start_progress_meter(pkg, st.size, &statsize);
start_progress_meter(progress_and_pkg, st.size, &statsize);
}

while (written < st.size) {
Expand Down
1 change: 1 addition & 0 deletions messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define MSG_DONT_HAVE_RIGHTS "You don't have enough rights for this operation."

/* actions.c */
#define MSG_PROGRESS "[%d/%d] "
#define MSG_REMOVING "removing %s...\n"
#define MSG_DOWNLOAD_PKGS "downloading packages...\n"
#define MSG_PKG_NO_REPO "%s has no associated repository"
Expand Down
3 changes: 3 additions & 0 deletions pkgin.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ extern uint8_t parsable;
extern uint8_t pflag;
extern int r_plistcounter;
extern int l_plistcounter;
extern int current_download;
extern int total_download;
extern int total_install;
extern char *env_repos;
extern char **pkg_repos;
extern const char *pkgin_cache;
Expand Down