diff --git a/actions.c b/actions.c index 37bee4d..7c18818 100644 --- a/actions.c +++ b/actions.c @@ -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 * @@ -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); @@ -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); @@ -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; @@ -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 @@ -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); @@ -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, "", diff --git a/download.c b/download.c index d7b4e5c..acb2105 100644 --- a/download.c +++ b/download.c @@ -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 @@ -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); @@ -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) { diff --git a/messages.h b/messages.h index f7bae97..579447d 100644 --- a/messages.h +++ b/messages.h @@ -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" diff --git a/pkgin.h b/pkgin.h index 01d3d5e..8994200 100644 --- a/pkgin.h +++ b/pkgin.h @@ -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;