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

commit ec72af45d43df6e480339d9160fa9c7afefc5224
Author: Michel Hermier <herm...@frugalware.org>
Date:   Fri Nov 15 17:55:12 2013 +0100

libpacman: Add pacman_downloadstate_tell and pacman_downloadstate_xfered, 
remove pacman_trans_cb_download 'xfered' argument.

diff --git a/doc/libpacman-changes.txt b/doc/libpacman-changes.txt
index 218890b..99ddc6e 100644
--- a/doc/libpacman-changes.txt
+++ b/doc/libpacman-changes.txt
@@ -32,6 +32,8 @@ pacman_trans_cb_download:

* Changed the not usable PM_NETBUF *ctl to a const pmdownloadstate_t 
*downloadstates (thougt only one supported for now).

+* Removed the 'xfered' parameter in favor of pacman_downloadstate_xfered.
+
* Removed the old abused 'arg' parameter.

pacman_trans_cb_progress: Make 'pkgname' argument a constant.
@@ -42,7 +44,13 @@ pmconflict_t: is now public and deprecate PM_CONFLICT.

pmdb_t: is now public and deprecate PM_DB.

-pacman_downloadstate_size: Access to a download final size.
+pacman_downloadstate_resume: Access to resume download size.
+
+pacman_downloadstate_size: Access to final download size.
+
+pacman_downloadstate_tell: Access to current download size.
+
+pacman_downloadstate_xfered: Access to a xfered download size.

pmdepmissing_t: is now public and deprecate PM_DEPMISS.

diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c
index f6838aa..1ee8327 100644
--- a/lib/libpacman/pacman.c
+++ b/lib/libpacman/pacman.c
@@ -439,6 +439,28 @@ off_t pacman_downloadstate_size(const pmdownloadstate_t 
*downloadstate)
return downloadstate->dst_size;
}

+/** Get the current size of the download
+ * @param downloadstate pointer to the download state to get the informations 
from.
+ * @return the current size of the file or ((off_t) -1) in case of error.
+ */
+off_t pacman_downloadstate_tell(const pmdownloadstate_t *downloadstate)
+{
+       ASSERT(downloadstate != NULL, return((off_t) -1));
+
+       return downloadstate->dst_tell;
+}
+
+/** Get the xfered size of the download
+ * @param downloadstate pointer to the download state to get the informations 
from.
+ * @return the xfered size of the file or ((off_t) -1) in case of error.
+ */
+off_t pacman_downloadstate_xfered(const pmdownloadstate_t *downloadstate)
+{
+       ASSERT(downloadstate != NULL, return((off_t) -1));
+
+       return downloadstate->dst_tell - downloadstate->dst_resume;
+}
+
/** @} */

/** @defgroup pacman_packages Package Functions
diff --git a/lib/libpacman/pacman.h b/lib/libpacman/pacman.h
index aac0d46..17dd85b 100644
--- a/lib/libpacman/pacman.h
+++ b/lib/libpacman/pacman.h
@@ -175,6 +175,8 @@ pmlist_t *pacman_db_test(pmdb_t *db);

off_t pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate);
off_t pacman_downloadstate_size(const pmdownloadstate_t *downloadstate);
+off_t pacman_downloadstate_tell(const pmdownloadstate_t *downloadstate);
+off_t pacman_downloadstate_xfered(const pmdownloadstate_t *downloadstate);

/*
* Packages
@@ -357,7 +359,7 @@ typedef void (*pacman_trans_cb_conv)(unsigned char, void *, 
void *, void *, int
typedef void (*pacman_trans_cb_progress)(unsigned char, const char *, int, int, 
int);

/* Download Progress callback */
-typedef int (*pacman_trans_cb_download)(const pmdownloadstate_t 
*downloadstates, int xfered);
+typedef int (*pacman_trans_cb_download)(const pmdownloadstate_t 
*downloadstates);

/* Info parameters */
enum {
diff --git a/lib/libpacman/server.c b/lib/libpacman/server.c
index f85b35a..cdfe5f4 100644
--- a/lib/libpacman/server.c
+++ b/lib/libpacman/server.c
@@ -146,7 +146,8 @@ int _pacman_ftplib_download_cb(netbuf *control, int xfered, 
void *arg)
{
pmdownloadstate_t *downloadstate = arg;

-       return pm_dlcb(downloadstate, xfered);
+       downloadstate->dst_tell = downloadstate->dst_resume + xfered;
+       return pm_dlcb(downloadstate);
}

/*
@@ -531,7 +532,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(&downloadstate, 
downloadstate.dst_size - downloadstate.dst_resume);
+                                               pm_dlcb(&downloadstate);
}
complete = _pacman_list_add(complete, fn);
/* rename "output.part" file to "output" file */
diff --git a/lib/libpacman/server.h b/lib/libpacman/server.h
index d461db5..188f303 100644
--- a/lib/libpacman/server.h
+++ b/lib/libpacman/server.h
@@ -47,6 +47,7 @@ struct __pmdownloadstate_t {
// FIXME: change int to off_t when the download backend will permit that.
int dst_resume;
int dst_size;
+       int dst_tell;
};

pmserver_t *_pacman_server_new(char *url);
diff --git a/src/pacman-g2/download.c b/src/pacman-g2/download.c
index 79f058f..d88f08d 100644
--- a/src/pacman-g2/download.c
+++ b/src/pacman-g2/download.c
@@ -52,10 +52,11 @@ extern config_t *config;
extern unsigned int maxcols;

/* FIXME: log10() want float */
-int log_progress(const pmdownloadstate_t *downloadstate, int xfered)
+int log_progress(const pmdownloadstate_t *downloadstate)
{
int offset = pacman_downloadstate_resume(downloadstate);
int fsz = pacman_downloadstate_size(downloadstate);
+       int xfered = pacman_downloadstate_xfered(downloadstate);
int pct = ((float)(xfered+offset) / fsz) * 100;
static int lastpct=0;
unsigned int i, cur;
diff --git a/src/pacman-g2/download.h b/src/pacman-g2/download.h
index b85a14c..ddbd58b 100644
--- a/src/pacman-g2/download.h
+++ b/src/pacman-g2/download.h
@@ -30,7 +30,7 @@ extern float rate;
extern int xfered1;
extern unsigned int eta_h, eta_m, eta_s, remain, howmany;

-int log_progress(const pmdownloadstate_t *downloadstate, int xfered);
+int log_progress(const pmdownloadstate_t *downloadstate);

#endif /* _PM_DOWNLOAD_H */
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to