All pastes #415956 Raw Edit

Unnamed

public text v1 · immutable
#415956 ·published 2007-03-29 23:36 UTC
rendered paste body
Index: lib/libalpm/alpm.c
===================================================================
RCS file: /home/cvs-pacman/pacman-lib/lib/libalpm/alpm.c,v
retrieving revision 1.127
diff -u -r1.127 alpm.c
--- lib/libalpm/alpm.c	11 Mar 2007 21:10:03 -0000	1.127
+++ lib/libalpm/alpm.c	29 Mar 2007 23:27:11 -0000
@@ -871,6 +871,68 @@
 	return(_alpm_fetch_pkgurl(url));
 }
 
+
+/** Create a list of mirrors
+ * @param url a generic url for a mirror, like this : "ftp://ftp.archlinux.org/$repo/os/i686"
+ * @param repolist a list of repository, separated by espace, like this : "current extra"
+ * return the list of mirrors generated
+ */
+alpm_list_t *create_mirror_list(char *url, char *repolist) {
+	char *repo = NULL;
+	char *s1 = NULL;
+	char *s2 = NULL;
+	char var[] = "$repo";
+	int length;
+
+	alpm_list_t *list = alpm_list_new();
+	repo = malloc(strlen(repolist)+1);
+	strcpy(repo, repolist);
+	length = strlen(repo)+strlen(url)+2;
+
+	if (strchr(repo, ' ') == NULL) {
+		char *mirror = malloc(length);
+		*mirror = '\0';
+		mirror = strcat(mirror, repo);
+		mirror = strcat(mirror, "=");
+		mirror = strcat(mirror, url);
+
+		list = alpm_list_add(list, mirror);
+		return list;
+	}
+
+	repo = strtok(repo, " ");
+	s1 = strstr(url, var);
+	if (s1 != NULL) {
+		*s1 = '\0';
+		s1 += strlen(var);
+		s2 = malloc(strlen(s1)+1);
+		s2 = strcpy(s2, s1);
+		s1 = malloc(strlen(url)+1);
+		s1 = strcpy(s1, url);
+	}
+	while (repo != NULL) {
+		if (s1 != NULL) {
+			*url = '\0';
+			url = strcat(url, s1);
+			url = strcat(url, repo);
+			url = strcat(url, s2);
+		}
+
+		char *mirror = malloc(length);
+		*mirror = '\0';
+		mirror = strcat(mirror, repo);
+		mirror = strcat(mirror, "=");
+		mirror = strcat(mirror, url);
+
+		list = alpm_list_add(list, mirror);
+
+		repo = strtok(NULL, " ");
+	}
+
+	return list;
+
+}
+
 /** Parses a configuration file.
  * @param file path to the config file.
  * @param callback a function to be called upon new database creation
@@ -899,9 +961,6 @@
 		if(!strcmp(section, "local")) {
 			RET_ERR(PM_ERR_CONF_LOCAL, -1);
 		}
-		if(strcmp(section, "options")) {
-			db = _alpm_db_register(section, callback);
-		}
 	}
 
 	while(fgets(line, PATH_MAX, fp)) {
@@ -923,13 +982,6 @@
 			if(!strcmp(section, "local")) {
 				RET_ERR(PM_ERR_CONF_LOCAL, -1);
 			}
-			if(strcmp(section, "options")) {
-				db = _alpm_db_register(section, callback);
-				if(db == NULL) {
-					/* pm_errno is set by alpm_db_register */
-					return(-1);
-				}
-			}
 		} else {
 			/* directive */
 			ptr = line;
@@ -1048,11 +1100,23 @@
 					}
 				} else {
 					if(!strcmp(key, "SERVER")) {
-						/* add to the list */
-						if(alpm_db_setserver(db, ptr) != 0) {
-							/* pm_errno is set by alpm_db_setserver */
-							return(-1);
+						alpm_list_t *mirrorlist = create_mirror_list(ptr, section);
+
+						for (; mirrorlist != NULL; mirrorlist = mirrorlist->next) {
+							char *url = mirrorlist->data;
+							char *repo = strsep(&url, "=");
+							db = _alpm_db_register(repo, callback);
+							if(db == NULL) {
+								/* pm_errno is set by alpm_db_register */
+								return(-1);
+							}
+							/* add to the list */
+							if(alpm_db_setserver(db, url) != 0) {
+								/* pm_errno is set by alpm_db_setserver */
+								return(-1);
+							}
 						}
+
 					} else {
 						RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
 					}