From dfc87fde603db9ad2420550da2014129a3b8fae5 Mon Sep 17 00:00:00 2001 From: youri Date: Tue, 1 Mar 2016 12:24:59 +0100 Subject: [PATCH 1/3] Add progress information during package download and install phases. --- actions.c | 15 ++++++++------- download.c | 10 +++++++--- messages.h | 1 + pkgin.h | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/actions.c b/actions.c index 37bee4d..f686c6e 100644 --- a/actions.c +++ b/actions.c @@ -58,14 +58,14 @@ verb_flag(const char *flags) #endif static int -pkg_download(Plisthead *installhead) +pkg_download(Plisthead *installhead, int downloadnum) { FILE *fp; Pkglist *pinstall; struct stat st; char pkg_fs[BUFSIZ], pkg_url[BUFSIZ], query[BUFSIZ]; ssize_t size; - int rc = EXIT_SUCCESS; + int rc = EXIT_SUCCESS, curdownload = 0; printf(MSG_DOWNLOAD_PKGS); @@ -109,7 +109,7 @@ pkg_download(Plisthead *installhead) if ((fp = fopen(pkg_fs, "w")) == NULL) err(EXIT_FAILURE, MSG_ERR_OPEN, pkg_fs); - if ((size = download_pkg(pkg_url, fp)) == -1) { + if ((size = download_pkg(pkg_url, fp, ++curdownload, downloadnum)) == -1) { fprintf(stderr, MSG_PKG_NOT_AVAIL, pinstall->depend); rc = EXIT_FAILURE; @@ -269,9 +269,9 @@ do_pkg_remove(Plisthead *removehead) * i.e. apache 1.3 */ static int -do_pkg_install(Plisthead *installhead) +do_pkg_install(Plisthead *installhead, int installnum) { - int rc = EXIT_SUCCESS; + int rc = EXIT_SUCCESS, curinstall = 0; Pkglist *pinstall; char pkgpath[BUFSIZ], preserve[BUFSIZ]; #ifndef DEBUG @@ -289,6 +289,7 @@ do_pkg_install(Plisthead *installhead) if (pinstall->file_size == -1) continue; + printf(MSG_PROGRESS, ++curinstall, installnum); printf(MSG_INSTALLING, pinstall->depend); snprintf(pkgpath, BUFSIZ, "%s/%s%s", pkgin_cache, pinstall->depend, PKG_EXT); @@ -544,7 +545,7 @@ pkgin_install(char **opkgargs, uint8_t do_inst) * before erasing anything, download packages * If there was an error while downloading, record it */ - if (pkg_download(installhead) == EXIT_FAILURE) + if (pkg_download(installhead, installnum) == EXIT_FAILURE) rc = EXIT_FAILURE; if (do_inst) { @@ -562,7 +563,7 @@ pkgin_install(char **opkgargs, uint8_t do_inst) * If there was an error while installing, * record it */ - if (do_pkg_install(installhead) == EXIT_FAILURE) + if (do_pkg_install(installhead, installnum) == EXIT_FAILURE) rc = EXIT_FAILURE; /* pure install, not called by pkgin_upgrade */ diff --git a/download.c b/download.c index d7b4e5c..38848d4 100644 --- a/download.c +++ b/download.c @@ -164,7 +164,7 @@ sum_close(struct archive *a, void *data) * Download a package to the local cache. */ ssize_t -download_pkg(char *pkg_url, FILE *fp) +download_pkg(char *pkg_url, FILE *fp, int curdownload, int downloadnum) { struct url_stat st; size_t size, wrote; @@ -173,7 +173,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 +190,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", curdownload, downloadnum, 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..2c38a2b 100644 --- a/pkgin.h +++ b/pkgin.h @@ -240,7 +240,7 @@ Sumfile *sum_open(char *, time_t *); int sum_start(struct archive *, void *); ssize_t sum_read(struct archive *, void *, const void **); int sum_close(struct archive *, void *); -ssize_t download_pkg(char *, FILE *); +ssize_t download_pkg(char *, FILE *, int, int); /* summary.c */ int update_db(int, char **, int); void split_repos(void); From 9c5984038c8962e5e959294b4fa522b35969a88e Mon Sep 17 00:00:00 2001 From: youri Date: Sun, 17 Apr 2016 18:22:34 +0200 Subject: [PATCH 2/3] Use global variables rather than function parameters. --- actions.c | 28 +++++++++++++++++++--------- download.c | 7 +++++-- pkgin.h | 5 ++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/actions.c b/actions.c index f686c6e..6bfbb13 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 * @@ -58,14 +61,14 @@ verb_flag(const char *flags) #endif static int -pkg_download(Plisthead *installhead, int downloadnum) +pkg_download(Plisthead *installhead) { FILE *fp; Pkglist *pinstall; struct stat st; char pkg_fs[BUFSIZ], pkg_url[BUFSIZ], query[BUFSIZ]; ssize_t size; - int rc = EXIT_SUCCESS, curdownload = 0; + int rc = EXIT_SUCCESS; printf(MSG_DOWNLOAD_PKGS); @@ -83,8 +86,10 @@ pkg_download(Plisthead *installhead, int downloadnum) /* already fully downloaded */ if (stat(pkg_fs, &st) == 0 && st.st_size == pinstall->file_size && - pinstall->file_size != 0 ) + pinstall->file_size != 0 ) { + total_download--; continue; + } snprintf(query, BUFSIZ, PKG_URL, pinstall->depend); /* retrieve repository for package */ @@ -109,7 +114,9 @@ pkg_download(Plisthead *installhead, int downloadnum) if ((fp = fopen(pkg_fs, "w")) == NULL) err(EXIT_FAILURE, MSG_ERR_OPEN, pkg_fs); - if ((size = download_pkg(pkg_url, fp, ++curdownload, downloadnum)) == -1) { + current_download++; + + if ((size = download_pkg(pkg_url, fp)) == -1) { fprintf(stderr, MSG_PKG_NOT_AVAIL, pinstall->depend); rc = EXIT_FAILURE; @@ -269,9 +276,9 @@ do_pkg_remove(Plisthead *removehead) * i.e. apache 1.3 */ static int -do_pkg_install(Plisthead *installhead, int installnum) +do_pkg_install(Plisthead *installhead) { - int rc = EXIT_SUCCESS, curinstall = 0; + int rc = EXIT_SUCCESS, current_install = 0; Pkglist *pinstall; char pkgpath[BUFSIZ], preserve[BUFSIZ]; #ifndef DEBUG @@ -289,7 +296,7 @@ do_pkg_install(Plisthead *installhead, int installnum) if (pinstall->file_size == -1) continue; - printf(MSG_PROGRESS, ++curinstall, installnum); + printf(MSG_PROGRESS, ++current_install, total_install); printf(MSG_INSTALLING, pinstall->depend); snprintf(pkgpath, BUFSIZ, "%s/%s%s", pkgin_cache, pinstall->depend, PKG_EXT); @@ -448,6 +455,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, "", @@ -545,7 +555,7 @@ pkgin_install(char **opkgargs, uint8_t do_inst) * before erasing anything, download packages * If there was an error while downloading, record it */ - if (pkg_download(installhead, installnum) == EXIT_FAILURE) + if (pkg_download(installhead) == EXIT_FAILURE) rc = EXIT_FAILURE; if (do_inst) { @@ -563,7 +573,7 @@ pkgin_install(char **opkgargs, uint8_t do_inst) * If there was an error while installing, * record it */ - if (do_pkg_install(installhead, installnum) == EXIT_FAILURE) + if (do_pkg_install(installhead) == EXIT_FAILURE) rc = EXIT_FAILURE; /* pure install, not called by pkgin_upgrade */ diff --git a/download.c b/download.c index 38848d4..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 @@ -164,7 +167,7 @@ sum_close(struct archive *a, void *data) * Download a package to the local cache. */ ssize_t -download_pkg(char *pkg_url, FILE *fp, int curdownload, int downloadnum) +download_pkg(char *pkg_url, FILE *fp) { struct url_stat st; size_t size, wrote; @@ -192,7 +195,7 @@ download_pkg(char *pkg_url, FILE *fp, int curdownload, int downloadnum) /* Add progress info */ snprintf(progress_and_pkg, BUFSIZ, - MSG_PROGRESS"%s", curdownload, downloadnum, pkg); + MSG_PROGRESS"%s", current_download, total_download, pkg); if (parsable) { printf(MSG_DOWNLOAD_START, pkg); diff --git a/pkgin.h b/pkgin.h index 2c38a2b..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; @@ -240,7 +243,7 @@ Sumfile *sum_open(char *, time_t *); int sum_start(struct archive *, void *); ssize_t sum_read(struct archive *, void *, const void **); int sum_close(struct archive *, void *); -ssize_t download_pkg(char *, FILE *, int, int); +ssize_t download_pkg(char *, FILE *); /* summary.c */ int update_db(int, char **, int); void split_repos(void); From 44d44364a0f894bd789fde62232f3b3eb36f06df Mon Sep 17 00:00:00 2001 From: Youri Mouton Date: Wed, 22 Jun 2016 00:10:56 +0200 Subject: [PATCH 3/3] Remove packages already in cache from download count. --- actions.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/actions.c b/actions.c index 6bfbb13..7c18818 100644 --- a/actions.c +++ b/actions.c @@ -72,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); @@ -86,10 +97,8 @@ pkg_download(Plisthead *installhead) /* already fully downloaded */ if (stat(pkg_fs, &st) == 0 && st.st_size == pinstall->file_size && - pinstall->file_size != 0 ) { - total_download--; + pinstall->file_size != 0) continue; - } snprintf(query, BUFSIZ, PKG_URL, pinstall->depend); /* retrieve repository for package */