Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-01-22 22:00:12 -0600
committerDan McGee <dan@archlinux.org>2008-02-24 20:21:58 -0600
commit81a2a06818d367f8528c74311171417beb9e1592 (patch)
tree62f21bce671e41feae2a453bc36561c8cbf4449a
parent3e8ae774bdbc8572613a22988476b6b4e7ef91fd (diff)
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>
-rw-r--r--lib/libalpm/db.c8
-rw-r--r--lib/libalpm/dload.c53
-rw-r--r--lib/libalpm/dload.h11
-rw-r--r--lib/libalpm/sync.c4
4 files changed, 45 insertions, 31 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index da9b9274..9dce4aff 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -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;
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index be3d3ea9..313bbbcf 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -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);
diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h
index 8ea97a26..01ec0ba0 100644
--- a/lib/libalpm/dload.h
+++ b/lib/libalpm/dload.h
@@ -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 */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index ebc13cd3..707bc8e3 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -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);