1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Start removing some junk from the function template

I screwed up originally when I accepted the TotalDownload patch,
8ec27835f4. I didn't realize how deeply it
modified libalpm and I probably shouldn't have let it do what it did. This
commit reverts much of what that patch added in order to clean up our
internal function calls. We can find another way to do it right down the
road here but for now it has to go.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-01-22 23:11:31 -06:00
parent 4fe7eb66eb
commit c2dbbd60bc
4 changed files with 28 additions and 72 deletions

View File

@ -78,8 +78,7 @@ int alpm_logaction(char *fmt, ...);
* Downloading * Downloading
*/ */
typedef void (*alpm_cb_download)(const char *filename, int file_xfered, typedef void (*alpm_cb_download)(const char *filename, int xfered, int total);
int file_total, int list_xfered, int list_total);
/* /*
* Options * Options

View File

@ -70,8 +70,7 @@ static struct url *url_for_file(const char *url, const char *filename)
/* TODO temporary private declaration */ /* TODO temporary private declaration */
int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, time_t mtime1, time_t *mtime2, int *dl_total, alpm_list_t *files, time_t mtime1, time_t *mtime2);
unsigned long totalsize);
/* TODO implement these as real functions */ /* TODO implement these as real functions */
@ -86,7 +85,7 @@ int _alpm_download_single_file(const char *filename,
files = alpm_list_add(files, (char*)filename); files = alpm_list_add(files, (char*)filename);
ret = _alpm_downloadfiles_forreal(servers, localpath, ret = _alpm_downloadfiles_forreal(servers, localpath,
files, mtimeold, mtimenew, NULL, 0); files, mtimeold, mtimenew);
/* free list (data was NOT duplicated) */ /* free list (data was NOT duplicated) */
alpm_list_free(files); alpm_list_free(files);
@ -99,7 +98,7 @@ int _alpm_download_files(alpm_list_t *files,
int ret; int ret;
ret = _alpm_downloadfiles_forreal(servers, localpath, ret = _alpm_downloadfiles_forreal(servers, localpath,
files, 0, NULL, NULL, 0); files, 0, NULL);
return(ret); return(ret);
} }
@ -112,19 +111,13 @@ int _alpm_download_files(alpm_list_t *files,
* than mtime1. * than mtime1.
* - if *mtime2 is non-NULL, it will be filled with the mtime of the remote * - if *mtime2 is non-NULL, it will be filled with the mtime of the remote
* file. * file.
* - if *dl_total is non-NULL, then it will be used as the starting
* download amount when TotalDownload is set. It will also be
* set to the final download amount for the calling function to use.
* - totalsize is the total download size for use when TotalDownload
* is set. Use 0 if the total download size is not known.
* *
* RETURN: 0 for successful download * RETURN: 0 for successful download
* 1 if the mtimes are identical * 1 if the mtimes are identical
* -1 on error * -1 on error
*/ */
int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, time_t mtime1, time_t *mtime2, int *dl_total, alpm_list_t *files, time_t mtime1, time_t *mtime2)
unsigned long totalsize)
{ {
int dl_thisfile = 0; int dl_thisfile = 0;
alpm_list_t *lp; alpm_list_t *lp;
@ -177,9 +170,6 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
_alpm_log(PM_LOG_DEBUG, "existing file found, using it\n"); _alpm_log(PM_LOG_DEBUG, "existing file found, using it\n");
fileurl->offset = (off_t)st.st_size; fileurl->offset = (off_t)st.st_size;
dl_thisfile = st.st_size; dl_thisfile = st.st_size;
if (dl_total != NULL) {
*dl_total += st.st_size;
}
localf = fopen(output, "a"); localf = fopen(output, "a");
chk_resume = 1; chk_resume = 1;
} else { } else {
@ -256,8 +246,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
/* Progress 0 - initialize */ /* Progress 0 - initialize */
if(handle->dlcb) { if(handle->dlcb) {
handle->dlcb(pkgname, 0, ust.size, dl_total ? *dl_total : 0, handle->dlcb(pkgname, 0, ust.size);
totalsize);
} }
int nread = 0; int nread = 0;
@ -289,13 +278,9 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
} }
dl_thisfile += nread; dl_thisfile += nread;
if (dl_total != NULL) {
*dl_total += nread;
}
if(handle->dlcb) { if(handle->dlcb) {
handle->dlcb(pkgname, dl_thisfile, ust.size, handle->dlcb(pkgname, dl_thisfile, ust.size);
dl_total ? *dl_total : 0, totalsize);
} }
} }

View File

@ -83,17 +83,14 @@ static float get_update_timediff(int first_call)
} }
/* refactored from cb_trans_progress */ /* refactored from cb_trans_progress */
static void fill_progress(const int graph_percent, const int display_percent, static void fill_progress(const int percent, const int proglen)
const int proglen)
{ {
const unsigned int hashlen = proglen - 8; const unsigned int hashlen = proglen - 8;
const unsigned int hash = graph_percent * hashlen / 100; const unsigned int hash = percent * hashlen / 100;
static unsigned int lasthash = 0, mouth = 0; static unsigned int lasthash = 0, mouth = 0;
unsigned int i; unsigned int i;
/* printf("\ndebug: proglen: %i\n", proglen); DEBUG*/ if(percent == 0) {
if(graph_percent == 0) {
lasthash = 0; lasthash = 0;
mouth = 0; mouth = 0;
} }
@ -138,10 +135,10 @@ static void fill_progress(const int graph_percent, const int display_percent,
} }
/* print percent after progress bar */ /* print percent after progress bar */
if(proglen > 5) { if(proglen > 5) {
printf(" %3d%%", display_percent); printf(" %3d%%", percent);
} }
if(graph_percent == 100) { if(percent == 100) {
printf("\n"); printf("\n");
} else { } else {
printf("\r"); printf("\r");
@ -388,7 +385,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
free(wcstr); free(wcstr);
/* call refactored fill progress function */ /* call refactored fill progress function */
fill_progress(percent, percent, getcols() - infolen); fill_progress(percent, getcols() - infolen);
if(percent == 100) { if(percent == 100) {
alpm_list_t *i = NULL; alpm_list_t *i = NULL;
@ -404,8 +401,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
} }
/* callback to handle display of download progress */ /* callback to handle display of download progress */
void cb_dl_progress(const char *filename, int file_xfered, int file_total, void cb_dl_progress(const char *filename, int xfered, int total)
int list_xfered, int list_total)
{ {
const int infolen = 50; const int infolen = 50;
const int filenamelen = infolen - 27; const int filenamelen = infolen - 27;
@ -416,43 +412,22 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total,
float rate = 0.0, timediff = 0.0, f_xfered = 0.0; float rate = 0.0, timediff = 0.0, f_xfered = 0.0;
unsigned int eta_h = 0, eta_m = 0, eta_s = 0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0;
int graph_percent = 0, display_percent = 0; int percent;
char rate_size = 'K', xfered_size = 'K'; char rate_size = 'K', xfered_size = 'K';
int xfered = 0, total = 0;
/* Need this variable when TotalDownload is set to know if we should
* reset xfered_last and rate_last. */
static int has_init = 0;
if(config->noprogressbar) { if(config->noprogressbar) {
return; return;
} }
/* Choose how to display the amount downloaded, rate, ETA, and
* percentage depending on the TotalDownload option. */
if (config->totaldownload && list_total > 0) {
xfered = list_xfered;
total = list_total;
} else {
xfered = file_xfered;
total = file_total;
}
/* this is basically a switch on file_xferred: 0, file_total, and /* this is basically a switch on file_xferred: 0, file_total, and
* anything else */ * anything else */
if(file_xfered == 0) { if(xfered == 0) {
/* set default starting values, but only once for TotalDownload */ /* set default starting values */
if (!(config->totaldownload && list_total > 0) || gettimeofday(&initial_time, NULL);
(config->totaldownload && list_total > 0 && !has_init)) { xfered_last = 0;
gettimeofday(&initial_time, NULL); rate_last = 0.0;
timediff = get_update_timediff(1); timediff = get_update_timediff(1);
xfered_last = 0; } else if(xfered == total) {
rate_last = 0.0;
has_init = 1;
}
rate = 0.0;
eta_s = 0;
} else if(file_xfered == file_total) {
/* compute final values */ /* compute final values */
struct timeval current_time; struct timeval current_time;
float diff_sec, diff_usec; float diff_sec, diff_usec;
@ -461,7 +436,7 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total,
diff_sec = current_time.tv_sec - initial_time.tv_sec; diff_sec = current_time.tv_sec - initial_time.tv_sec;
diff_usec = current_time.tv_usec - initial_time.tv_usec; diff_usec = current_time.tv_usec - initial_time.tv_usec;
timediff = diff_sec + (diff_usec / 1000000.0); timediff = diff_sec + (diff_usec / 1000000.0);
rate = xfered / (timediff * 1024.0); rate = total / (timediff * 1024.0);
/* round elapsed time to the nearest second */ /* round elapsed time to the nearest second */
eta_s = (int)(timediff + 0.5); eta_s = (int)(timediff + 0.5);
@ -475,12 +450,14 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total,
} }
rate = (xfered - xfered_last) / (timediff * 1024.0); rate = (xfered - xfered_last) / (timediff * 1024.0);
/* average rate to reduce jumpiness */ /* average rate to reduce jumpiness */
rate = (rate + 2*rate_last) / 3; rate = (rate + 2 * rate_last) / 3;
eta_s = (total - xfered) / (rate * 1024.0); eta_s = (total - xfered) / (rate * 1024.0);
rate_last = rate; rate_last = rate;
xfered_last = xfered; xfered_last = xfered;
} }
percent = (int)((float)xfered) / ((float)total) * 100;
/* fix up time for display */ /* fix up time for display */
eta_h = eta_s / 3600; eta_h = eta_s / 3600;
eta_s -= eta_h * 3600; eta_s -= eta_h * 3600;
@ -552,11 +529,7 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total,
free(fname); free(fname);
free(wcfname); free(wcfname);
/* The progress bar is based on the file percent regardless of the fill_progress(percent, getcols() - infolen);
* TotalDownload option. */
graph_percent = (int)((float)file_xfered) / ((float)file_total) * 100;
display_percent = (int)((float)xfered) / ((float)total) * 100;
fill_progress(graph_percent, display_percent, getcols() - infolen);
return; return;
} }

View File

@ -33,8 +33,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
int howmany, int remain); int howmany, int remain);
/* callback to handle display of download progress */ /* callback to handle display of download progress */
void cb_dl_progress(const char *filename, int file_xfered, int file_total, void cb_dl_progress(const char *filename, int file_xfered, int file_total);
int list_xfered, int list_total);
/* callback to handle messages/notifications from pacman library */ /* callback to handle messages/notifications from pacman library */
void cb_log(pmloglevel_t level, char *fmt, va_list args); void cb_log(pmloglevel_t level, char *fmt, va_list args);