1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

Add new stub download functions for use throughout the code

Add new stub functions that work by calling the existing (terrible) download
forreal function, which needs a serious overhaul. Hide the existing
functions and switch all former users to the new functions.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-01-22 22:00:12 -06:00
parent 3e8ae774bd
commit 81a2a06818
4 changed files with 45 additions and 31 deletions

View File

@ -219,7 +219,6 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
{
alpm_list_t *lp;
char path[PATH_MAX];
alpm_list_t *files = NULL;
time_t newmtime = 0, lastupdate = 0;
const char *dbpath;
int ret;
@ -252,13 +251,10 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
/* build a one-element list */
snprintf(path, PATH_MAX, "%s" DBEXT, db->treename);
files = alpm_list_add(files, strdup(path));
dbpath = alpm_option_get_dbpath();
ret = _alpm_downloadfiles_forreal(db->servers, dbpath, files, lastupdate,
&newmtime, NULL, 0);
FREELIST(files);
ret = _alpm_download_single_file(path, db->servers, dbpath, lastupdate, &newmtime);
if(ret == 1) {
/* mtimes match, do nothing */
pm_errno = 0;

View File

@ -79,24 +79,43 @@ static struct url *url_for_file(pmserver_t *server, const char *filename)
return(ret);
}
/*
* Download a list of files from a list of servers
* - if one server fails, we try the next one in the list
* - 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, 1 on error
*/
int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, int *dl_total, unsigned long totalsize)
/* TODO temporary private declaration */
int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, time_t mtime1, time_t *mtime2, int *dl_total,
unsigned long totalsize);
/* TODO implement these as real functions */
int _alpm_download_single_file(const char *filename,
alpm_list_t *servers, const char *localpath,
time_t mtimeold, time_t *mtimenew)
{
return(_alpm_downloadfiles_forreal(servers, localpath, files, 0, NULL,
dl_total, totalsize));
alpm_list_t *files = NULL;
int ret;
/* make a temp one element list */
files = alpm_list_add(files, (char*)filename);
ret = _alpm_downloadfiles_forreal(servers, localpath,
files, mtimeold, mtimenew, NULL, 0);
/* free list (data was NOT duplicated) */
alpm_list_free(files);
return(ret);
}
int _alpm_download_files(alpm_list_t *files,
alpm_list_t *servers, const char *localpath)
{
int ret;
ret = _alpm_downloadfiles_forreal(servers, localpath,
files, 0, NULL, NULL, 0);
return(ret);
}
/*
* This is the real downloadfiles, used directly by sync_synctree() to check
* modtimes on remote files.
@ -402,15 +421,13 @@ char SYMEXPORT *alpm_fetch_pkgurl(const char *url)
/* TODO this seems like needless complexity just to download one file */
alpm_list_t *servers = alpm_list_add(NULL, server);
alpm_list_t *files = alpm_list_add(NULL, filename);
/* download the file */
if(_alpm_downloadfiles(servers, cachedir, files, NULL, 0)) {
if(_alpm_download_single_file(filename, servers, cachedir, 0, NULL)) {
_alpm_log(PM_LOG_WARNING, _("failed to download %s\n"), url);
return(NULL);
}
_alpm_log(PM_LOG_DEBUG, "successfully downloaded %s\n", filename);
alpm_list_free(files);
alpm_list_free(servers);
_alpm_server_free(server);

View File

@ -27,11 +27,12 @@
#define PM_DLBUF_LEN (1024 * 10)
int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, int *dl_total, unsigned long totalsize);
int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, time_t mtime1, time_t *mtime2, int *dl_total,
unsigned long totalsize);
int _alpm_download_single_file(const char *filename,
alpm_list_t *servers, const char *localpath,
time_t mtimeold, time_t *mtimenew);
int _alpm_download_files(alpm_list_t *files,
alpm_list_t *servers, const char *localpath);
#endif /* _ALPM_DLOAD_H */

View File

@ -911,7 +911,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
pmtrans_t *tr = NULL;
int replaces = 0, retval = 0;
const char *cachedir = NULL;
int dltotal = 0, dl = 0;
int dltotal = 0;
ALPM_LOG_FUNC;
@ -992,7 +992,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(files) {
EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
if(_alpm_downloadfiles(current->servers, cachedir, files, &dl, dltotal)) {
if(_alpm_download_files(files, current->servers, cachedir)) {
_alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
current->treename);
RET_ERR(PM_ERR_RETRIEVE, -1);