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

commit f6281bc320500cbde63164ee72445bb79d6fafac
Author: Miklos Vajna <[email protected]>
Date:   Wed Jan 18 00:58:49 2012 +0100

libpacman: try the next server when connection times out

diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c
index cc23407..07a6a70 100644
--- a/lib/libpacman/pacman.c
+++ b/lib/libpacman/pacman.c
@@ -352,7 +352,7 @@ int pacman_db_update(int force, PM_DB *db)

snprintf(path, PATH_MAX, "%s%s", handle->root, handle->dbpath);

-       ret = _pacman_downloadfiles_forreal(db->servers, path, files, 
lastupdate, newmtime);
+       ret = _pacman_downloadfiles_forreal(db->servers, path, files, 
lastupdate, newmtime, 0);
FREELIST(files);
if(ret != 0) {
if(ret == -1) {
diff --git a/lib/libpacman/server.c b/lib/libpacman/server.c
index c87357b..54e69b6 100644
--- a/lib/libpacman/server.c
+++ b/lib/libpacman/server.c
@@ -128,9 +128,9 @@ void _pacman_server_free(void *data)
*
* RETURN:  0 for successful download, -1 on error
*/
-int _pacman_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t 
*files)
+int _pacman_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t 
*files, int skip)
{
-       if(_pacman_downloadfiles_forreal(servers, localpath, files, NULL, NULL) 
!= 0) {
+       if(_pacman_downloadfiles_forreal(servers, localpath, files, NULL, NULL, 
skip) != 0) {
return(-1);
} else {
return(0);
@@ -151,7 +151,7 @@ int _pacman_downloadfiles(pmlist_t *servers, const char 
*localpath, pmlist_t *fi
*         -1 on error
*/
int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
-       pmlist_t *files, const char *mtime1, char *mtime2)
+       pmlist_t *files, const char *mtime1, char *mtime2, int skip)
{
int fsz;
netbuf *control = NULL;
@@ -175,7 +175,10 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
}

_pacman_log(PM_LOG_DEBUG, _("server check, %d\n"),servers);
-       for(i = servers; i && !done; i = i->next) {
+       int count;
+       for(i = servers, count = 0; i && !done; i = i->next, count++) {
+               if (count < skip)
+                       continue; /* the caller requested skip of this server */
_pacman_log(PM_LOG_DEBUG, _("server check, done? %d\n"),done);
server = (pmserver_t*)i->data;
if(!handle->xfercommand && strcmp(server->protocol, "file")) {
@@ -414,6 +417,7 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
fn, server->server, FtpLastResponse(control));
/* we leave the partially downloaded file in place so it can be resumed later */
if(!strncmp(FtpLastResponse(control), strerror(ETIMEDOUT), 254)) {
+                                                               unlink(output);
pm_errno = PM_ERR_RETRIEVE;
goto error;
}
@@ -505,8 +509,10 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
src, server->server, FtpLastResponse(control));
pm_errno = PM_ERR_RETRIEVE;
/* we leave the partially downloaded file in place so it can be resumed later */
-                                                       
if(!strncmp(FtpLastResponse(control), strerror(ETIMEDOUT), 254))
+                                                       
if(!strncmp(FtpLastResponse(control), strerror(ETIMEDOUT), 254)) {
+                                                               unlink(output);
goto error;
+                                                       }
}
} else {
if(mtime2) {
@@ -624,7 +630,7 @@ char *_pacman_fetch_pkgurl(char *target)
servers = _pacman_list_add(servers, server);

files = _pacman_list_add(NULL, fn);
-               if(_pacman_downloadfiles(servers, lcache, files)) {
+               if(_pacman_downloadfiles(servers, lcache, files, 0)) {
_pacman_log(PM_LOG_WARNING, _("failed to download %s\n"), target);
return(NULL);
}
diff --git a/lib/libpacman/server.h b/lib/libpacman/server.h
index 034a1e7..ce285e2 100644
--- a/lib/libpacman/server.h
+++ b/lib/libpacman/server.h
@@ -44,9 +44,9 @@ typedef struct __pmserver_t {

pmserver_t *_pacman_server_new(char *url);
void _pacman_server_free(void *data);
-int _pacman_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t 
*files);
+int _pacman_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t 
*files, int skip);
int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
-       pmlist_t *files, const char *mtime1, char *mtime2);
+       pmlist_t *files, const char *mtime1, char *mtime2, int skip);

char *_pacman_fetch_pkgurl(char *target);

diff --git a/lib/libpacman/sync.c b/lib/libpacman/sync.c
index 5f70310..18e8be6 100644
--- a/lib/libpacman/sync.c
+++ b/lib/libpacman/sync.c
@@ -797,6 +797,7 @@ int _pacman_trans_download_commit(pmtrans_t *trans, 
pmlist_t **data)
for(tries = 0; tries < handle->maxtries; tries++) {
retval = 0;
FREELIST(*data);
+               int done = 1;
for(i = handle->dbs_sync; i; i = i->next) {
pmdb_t *current = i->data;

@@ -860,14 +861,15 @@ int _pacman_trans_download_commit(pmtrans_t *trans, 
pmlist_t **data)
varcache = 0;
}
}
-                               if(_pacman_downloadfiles(current->servers, 
ldir, files) == -1) {
+                               if(_pacman_downloadfiles(current->servers, 
ldir, files, tries) == -1) {
_pacman_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"), 
current->treename);
-                                       trans->state = STATE_INTERRUPTED;
-                                       RET_ERR(PM_ERR_RETRIEVE, -1);
+                                       done = 0;
}
FREELIST(files);
}
}
+               if (!done)
+                       continue;
if(trans->flags & PM_TRANS_FLAG_PRINTURIS) {
return(0);
}
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to