Avoid double slashes in URLs given to libdownload.

If a Server specified in pacman.conf had a trailing slash, libalpm ended up
building URLs with double slashes, and this broke libdownload with errors
like the following one :

error: failed retrieving file 'redland-1.0.8-1-i686.pkg.tar.gz'
from 192.168.0.90 : Command okay

So the public function alpm_db_set_server will make sure to remove the
trailing slash of servers.  For the private function
_alpm_download_single_file, I only added a comment.

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2008-08-04 01:16:08 +02:00 committed by Dan McGee
parent 4476598e4e
commit 72c5a298a3
2 changed files with 14 additions and 3 deletions

View File

@ -170,6 +170,8 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
{
alpm_list_t *i;
int found = 0;
char *newurl;
int len = 0;
ALPM_LOG_FUNC;
@ -186,10 +188,18 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
}
if(url && strlen(url)) {
db->servers = alpm_list_add(db->servers, strdup(url));
if(url) {
len = strlen(url);
}
if(len) {
newurl = strdup(url);
/* strip the trailing slash if one exists */
if(newurl[len - 1] == '/') {
newurl[len - 1] = '\0';
}
db->servers = alpm_list_add(db->servers, newurl);
_alpm_log(PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
db->treename, url);
db->treename, newurl);
} else {
FREELIST(db->servers);
_alpm_log(PM_LOG_DEBUG, "serverlist flushed for '%s'\n", db->treename);

View File

@ -365,6 +365,7 @@ static int download(const char *url, const char *localpath,
* than mtimeold.
* - if *mtimenew is non-NULL, it will be filled with the mtime of the remote
* file.
* - servers must be a list of urls WITHOUT trailing slashes.
*
* RETURN: 0 for successful download
* 1 if the mtimes are identical