Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2/.git;a=commitdiff;h=d0bb9d33ca4b7638920e02328418a8549a496118

commit d0bb9d33ca4b7638920e02328418a8549a496118
Author: Christian Hamar alias krix <[EMAIL PROTECTED]>
Date:   Tue Jul 24 17:55:21 2007 +0200

Adding package-counter to download part too \o/
* Nah here we go, i added package-counter to download part too. Like ( 1/21) 
...blabla
* Modified libftp, made a second callbackarg void* to submit over ftpcallback 
that how many files
we need to download. Modified functions in server.c to use the new method
* Added download.c the counter part. (!!! Need to 'backport' log10 stuff from 
trans.c in pacman-g2)
* make check all test passed. I tested it worked.

diff --git a/lib/libftp/ftplib.c b/lib/libftp/ftplib.c
index cbe3d70..db5e943 100644
--- a/lib/libftp/ftplib.c
+++ b/lib/libftp/ftplib.c
@@ -82,6 +82,7 @@ struct NetBuf {
struct timeval idletime;
FtpCallback idlecb;
void *idlearg;
+       void *idlearg2;
int xfered;
int cbbytes;
int xfered1;
@@ -170,7 +171,7 @@ static int socket_wait(netbuf *ctl)
break;
}
}
-       while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg)));
+       while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg, 
ctl->idlearg2)));
return rv;
}

@@ -474,6 +475,7 @@ GLOBALDEF int FtpConnect(const char *host, netbuf 
**nControl)
ctrl->idlecb = NULL;
ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
ctrl->idlearg = NULL;
+       ctrl->idlearg2 = NULL;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = 0;
@@ -520,6 +522,10 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf 
*nControl)
rv = 1;
nControl->idlearg = (void *) val;
break;
+               case FTPLIB_CALLBACKARG2:
+                       rv = 1;
+                       nControl->idlearg2 = (void *) val;
+                       break;
case FTPLIB_CALLBACKBYTES:
rv = 1;
nControl->cbbytes = (int) val;
@@ -710,6 +716,7 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, 
int mode, int dir)
ctrl->dir = dir;
ctrl->idletime = nControl->idletime;
ctrl->idlearg = nControl->idlearg;
+       ctrl->idlearg2 = nControl->idlearg2;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = nControl->cbbytes;
@@ -890,7 +897,7 @@ GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
nData->xfered1 += i;
if (nData->xfered1 > nData->cbbytes)
{
-                       if (nData->idlecb(nData, nData->xfered, nData->idlearg) 
== 0)
+                       if (nData->idlecb(nData, nData->xfered, nData->idlearg, 
nData->idlearg2) == 0)
return 0;
nData->xfered1 = 0;
}
@@ -921,7 +928,7 @@ GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
nData->xfered1 += i;
if (nData->xfered1 > nData->cbbytes)
{
-                       nData->idlecb(nData, nData->xfered, nData->idlearg);
+                       nData->idlecb(nData, nData->xfered, nData->idlearg, 
nData->idlearg2);
nData->xfered1 = 0;
}
}
@@ -1397,6 +1404,7 @@ GLOBALREF int HttpConnect(const char *host, unsigned 
short port, netbuf **nContr
ctrl->idlecb = NULL;
ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
ctrl->idlearg = NULL;
+       ctrl->idlearg2 = NULL;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = 0;
diff --git a/lib/libftp/ftplib.h b/lib/libftp/ftplib.h
index f82ed9e..efbe56f 100644
--- a/lib/libftp/ftplib.h
+++ b/lib/libftp/ftplib.h
@@ -58,13 +58,14 @@
#define FTPLIB_IDLETIME 3
#define FTPLIB_CALLBACKARG 4
#define FTPLIB_CALLBACKBYTES 5
+#define FTPLIB_CALLBACKARG2 6

#ifdef __cplusplus
extern "C" {
#endif

typedef struct NetBuf netbuf;
-typedef int (*FtpCallback)(netbuf *nControl, int xfered, void *arg);
+typedef int (*FtpCallback)(netbuf *nControl, int xfered, void *arg, void 
*arg2);

/* v1 compatibility stuff */
#if !defined(_FTPLIB_NO_COMPAT)
diff --git a/lib/libpacman/server.c b/lib/libpacman/server.c
index ce86737..10af0d4 100644
--- a/lib/libpacman/server.c
+++ b/lib/libpacman/server.c
@@ -158,7 +158,7 @@ int _pacman_downloadfiles(pmlist_t *servers, const char 
*localpath, pmlist_t *fi
int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
pmlist_t *files, const char *mtime1, char *mtime2)
{
-       int fsz;
+       int fsz, howmany;
netbuf *control = NULL;
pmlist_t *lp;
int done = 0;
@@ -168,6 +168,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
if(files == NULL) {
return(0);
}
+       howmany = _pacman_list_count(files);

pm_errno = 0;

@@ -226,6 +227,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
}
FtpOptions(FTPLIB_IDLETIME, (long)1000, control);
FtpOptions(FTPLIB_CALLBACKARG, (long)&fsz, control);
+                               FtpOptions(FTPLIB_CALLBACKARG2, (long)&howmany, 
control);
FtpOptions(FTPLIB_CALLBACKBYTES, (10*1024), control);
}
}
@@ -418,6 +420,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
}
FtpOptions(FTPLIB_IDLETIME, (long)1000, control);
FtpOptions(FTPLIB_CALLBACKARG, (long)&fsz, control);
+                                                       
FtpOptions(FTPLIB_CALLBACKARG2, (long)&howmany, control);
FtpOptions(FTPLIB_CALLBACKBYTES, (10*1024), control);
}
}
@@ -493,7 +496,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
if(!strcmp(server->protocol, "file")) {
EVENT(handle->trans, PM_TRANS_EVT_RETRIEVE_LOCAL, pm_dlfnm, server->path);
} else if(pm_dlcb) {
-                                               pm_dlcb(control, 
fsz-*pm_dloffset, &fsz);
+                                               pm_dlcb(control, 
fsz-*pm_dloffset, &fsz, &howmany);
}
complete = _pacman_list_add(complete, fn);
/* rename "output.part" file to "output" file */
diff --git a/src/pacman-g2/download.c b/src/pacman-g2/download.c
index 4df1294..34e35f0 100644
--- a/src/pacman-g2/download.c
+++ b/src/pacman-g2/download.c
@@ -45,15 +45,17 @@ struct timeval t0, t;
float rate;
int xfered1;
unsigned int eta_h, eta_m, eta_s;
+static int remain = 1;

/* pacman options */
extern config_t *config;

extern unsigned int maxcols;

-int log_progress(PM_NETBUF *ctl, int xfered, void *arg)
+int log_progress(PM_NETBUF *ctl, int xfered, void *arg, void *arg2)
{
int fsz = *(int*)arg;
+       int howmany = *(int*)arg2;
int pct = ((float)(xfered+offset) / fsz) * 100;
static int lastpct=0;
unsigned int i, cur;
@@ -103,9 +105,14 @@ int log_progress(PM_NETBUF *ctl, int xfered, void *arg)
eta_s -= eta_m * 60;
}

-       printf(" %s [", sync_fnm);
-       cur = (int)((maxcols-64)*pct/100);
-       for(i = 0; i < maxcols-64; i++) {
+       /* Need fixup :S i cant backport it from trans.c :S */
+       putchar('(');
+       for(i = 0; i<(int)log10(howmany)-(int)log10(remain); i++)
+           putchar(' ');
+
+       printf("%d/%d) %s [", remain, howmany, sync_fnm);
+       cur = (int)((maxcols-68)*pct/100);
+       for(i = 0; i < maxcols-68; i++) {
if(chomp) {
if(i < cur) {
printf("-");
@@ -140,6 +147,7 @@ int log_progress(PM_NETBUF *ctl, int xfered, void *arg)
}
if(lastpct != 100 && pct == 100) {
printf("\n");
+               remain = remain + 1;
}
lastcur = cur;
lastpct = pct;
diff --git a/src/pacman-g2/download.h b/src/pacman-g2/download.h
index b1d777d..9667767 100644
--- a/src/pacman-g2/download.h
+++ b/src/pacman-g2/download.h
@@ -21,6 +21,8 @@
#ifndef _PM_DOWNLOAD_H
#define _PM_DOWNLOAD_H

+#include <math.h>
+
extern char sync_fnm[PM_DLFNM_LEN+1];
extern int offset;
extern struct timeval t0, t;
@@ -28,7 +30,7 @@ extern float rate;
extern int xfered1;
extern unsigned int eta_h, eta_m, eta_s;

-int log_progress(PM_NETBUF *ctl, int xfered, void *arg);
+int log_progress(PM_NETBUF *ctl, int xfered, void *arg, void *arg2);

#endif /* _PM_DOWNLOAD_H */
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to