Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=9b2af5f223283e037a9ee1279d9fa1d28e795987
commit 9b2af5f223283e037a9ee1279d9fa1d28e795987 Author: Michel Hermier <herm...@frugalware.org> Date: Fri Nov 15 13:28:53 2013 +0100 libpacman Add pacman_downloadstate_resume and remove PM_OPT_DLOFFSET. diff --git a/doc/libpacman-changes.txt b/doc/libpacman-changes.txt index 6277825..218890b 100644 --- a/doc/libpacman-changes.txt +++ b/doc/libpacman-changes.txt @@ -20,6 +20,8 @@ None. pacman_cb_log: Make 'message' argument a constant. +pacman_downloadstate_resume, pacman_downloadstate_size: Access to the various pmdownloadstate_t data. + pacman_logaction: Now returns a void instead of a int to reflect success. Logging should allways success and not be intrusive. pacman_parse_config: Make 'file' argument a constant. Remove 'this_section' argument, it is internal and should not have been exposed publicly. @@ -56,7 +58,7 @@ PM_PKG_TRIGGERS: Access to package triggers list. ==== Symbols removed: -PM_NETBUF: Remove due to code refactor so public API does not try to hide that it use libftp internal callback. See pacman_trans_cb_download changes. +PM_NETBUF, PM_OPT_DLOFFSET: Remove due to code refactor so public API does not try to hide that it use libftp internal callback. See pacman_trans_cb_download changes. PM_TRANS: Unused in the public API. diff --git a/lib/libpacman/handle.c b/lib/libpacman/handle.c index e8987f7..49ff507 100644 --- a/lib/libpacman/handle.c +++ b/lib/libpacman/handle.c @@ -234,9 +234,6 @@ int _pacman_handle_set_option(pmhandle_t *ph, unsigned char val, unsigned long d case PM_OPT_DLFNM: pm_dlfnm = (char *)data; break; - case PM_OPT_DLOFFSET: - pm_dloffset = (int *)data; - break; case PM_OPT_DLT0: pm_dlt0 = (struct timeval *)data; break; @@ -352,7 +349,6 @@ int _pacman_handle_get_option(pmhandle_t *ph, unsigned char val, long *data) case PM_OPT_OLDDELAY: *data = (long)ph->olddelay; break; case PM_OPT_LOGMASK: *data = pm_logmask; break; case PM_OPT_DLFNM: *data = (long)pm_dlfnm; break; - case PM_OPT_DLOFFSET: *data = (long)pm_dloffset; break; case PM_OPT_DLT0: *data = (long)pm_dlt0; break; case PM_OPT_DLT: *data = (long)pm_dlt; break; case PM_OPT_DLRATE: *data = (long)pm_dlrate; break; diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c index 289246d..f6838aa 100644 --- a/lib/libpacman/pacman.c +++ b/lib/libpacman/pacman.c @@ -417,6 +417,17 @@ pmlist_t *pacman_db_getgrpcache(pmdb_t *db) * @{ */ +/** Get the size at the start of the download resume + * @param downloadstate pointer to the download state to get the informations from. + * @return the size of the file at the start of download resume of the file or ((off_t) -1) in case of error. + */ +off_t pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate) +{ + ASSERT(downloadstate != NULL, return((off_t) -1)); + + return downloadstate->dst_resume; +} + /** Get the final size of the download * @param downloadstate pointer to the download state to get the informations from. * @return the size of the file or ((off_t) -1) in case of error. diff --git a/lib/libpacman/pacman.h b/lib/libpacman/pacman.h index ac133e0..aac0d46 100644 --- a/lib/libpacman/pacman.h +++ b/lib/libpacman/pacman.h @@ -118,7 +118,6 @@ enum { PM_OPT_NOPASSIVEFTP, PM_OPT_DLCB, PM_OPT_DLFNM, - PM_OPT_DLOFFSET, PM_OPT_DLT0, PM_OPT_DLT, PM_OPT_DLRATE, @@ -174,6 +173,7 @@ pmlist_t *pacman_db_test(pmdb_t *db); * Download states */ +off_t pacman_downloadstate_resume(const pmdownloadstate_t *downloadstate); off_t pacman_downloadstate_size(const pmdownloadstate_t *downloadstate); /* diff --git a/lib/libpacman/server.c b/lib/libpacman/server.c index f5d942a..a200466 100644 --- a/lib/libpacman/server.c +++ b/lib/libpacman/server.c @@ -48,7 +48,6 @@ pacman_trans_cb_download pm_dlcb = NULL; /* progress bar */ char *pm_dlfnm=NULL; -int *pm_dloffset=NULL; struct timeval *pm_dlt0=NULL, *pm_dlt=NULL; float *pm_dlrate=NULL; int *pm_dlxfered1=NULL; @@ -374,9 +373,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath, } pm_dlfnm[PM_DLFNM_LEN] = '\0'; } - if(pm_dloffset) { - *pm_dloffset = 0; - } + downloadstate.dst_resume = 0; /* ETA setup */ if(pm_dlt0 && pm_dlt && pm_dlrate && pm_dlxfered1 && pm_dleta_h && pm_dleta_m && pm_dleta_s) { @@ -420,10 +417,8 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath, } if(!filedone) { if(!stat(output, &st)) { - if(pm_dloffset) { - *pm_dloffset = (int)st.st_size; - } - if(!pm_dloffset || !FtpRestart(*pm_dloffset, control)) { + downloadstate.dst_resume = st.st_size; + if(!FtpRestart(&downloadstate.dst_resume, control)) { _pacman_log(PM_LOG_WARNING, _("failed to resume download -- restarting\n")); /* can't resume: */ /* unlink the file in order to restart download from scratch */ @@ -484,9 +479,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath, } if(!stat(output, &st)) { - if (pm_dloffset) { - *pm_dloffset = (int)st.st_size; - } + downloadstate.dst_resume = st.st_size; } if(!handle->proxyhost) { snprintf(src, PATH_MAX, "%s%s", server->path, fn); @@ -496,7 +489,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath, if(mtime1 && *mtime1 != PM_TIME_INVALID) { fmtime1 = *gmtime(mtime1); } - if(!HttpGet(server->server, output, src, &downloadstate.dst_size, control, (pm_dloffset ? *pm_dloffset:0), + if(!HttpGet(server->server, output, src, &downloadstate.dst_size, control, &downloadstate.dst_resume, (mtime1) ? &fmtime1 : NULL, (mtime2) ? &fmtime2 : NULL)) { if(strstr(FtpLastResponse(control), "304")) { _pacman_log(PM_LOG_DEBUG, _("mtimes are identical, skipping %s\n"), fn); @@ -538,7 +531,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-*pm_dloffset); + pm_dlcb(&downloadstate, downloadstate.dst_size - downloadstate.dst_resume); } 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 597448d..d461db5 100644 --- a/lib/libpacman/server.h +++ b/lib/libpacman/server.h @@ -45,6 +45,7 @@ typedef struct __pmserver_t { struct __pmdownloadstate_t { // FIXME: change int to off_t when the download backend will permit that. + int dst_resume; int dst_size; }; @@ -60,7 +61,6 @@ extern pacman_trans_cb_download pm_dlcb; /* progress bar */ extern char *pm_dlfnm; -extern int *pm_dloffset; extern struct timeval *pm_dlt0, *pm_dlt; extern float *pm_dlrate; extern int *pm_dlxfered1; diff --git a/src/pacman-g2/download.c b/src/pacman-g2/download.c index c57e223..79f058f 100644 --- a/src/pacman-g2/download.c +++ b/src/pacman-g2/download.c @@ -41,7 +41,6 @@ /* progress bar */ char sync_fnm[PM_DLFNM_LEN+1]; -int offset; struct timeval t0, t; float rate; int xfered1; @@ -55,6 +54,7 @@ extern unsigned int maxcols; /* FIXME: log10() want float */ int log_progress(const pmdownloadstate_t *downloadstate, int xfered) { + int offset = pacman_downloadstate_resume(downloadstate); int fsz = pacman_downloadstate_size(downloadstate); int pct = ((float)(xfered+offset) / fsz) * 100; static int lastpct=0; diff --git a/src/pacman-g2/pacman-g2.c b/src/pacman-g2/pacman-g2.c index 8429842..2cbd6ab 100644 --- a/src/pacman-g2/pacman-g2.c +++ b/src/pacman-g2/pacman-g2.c @@ -575,10 +575,6 @@ int main(int argc, char *argv[]) ERR(NL, _("failed to set option DLFNM (%s)\n"), pacman_strerror(pm_errno)); cleanup(1); } - if(pacman_set_option(PM_OPT_DLOFFSET, (long)&offset) == -1) { - ERR(NL, _("failed to set option DLOFFSET (%s)\n"), pacman_strerror(pm_errno)); - cleanup(1); - } if(pacman_set_option(PM_OPT_DLT0, (long)&t0) == -1) { ERR(NL, _("failed to set option DLT0 (%s)\n"), pacman_strerror(pm_errno)); cleanup(1); _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git