[pacman-dev] [PATCH 3/3] Allow $arch to be used in Server

Xavier Chantry shiningxc at gmail.com
Wed Aug 19 16:23:46 EDT 2009


similarly to the $repo variable, Server can now contain $arch, which will be
automatically replaced by the appropriate architecture.

This allows us to have one universal mirrorlist file, for both i686 and x86_64,
woohoo!

TODO : doc

Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
---
 doc/pacman.conf.5.txt     |    6 ++++--
 etc/pacman.conf.in        |    3 ++-
 scripts/rankmirrors.py.in |    2 ++
 src/pacman/pacman.c       |   17 ++++++++++++++++-
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index 51c5188..bfb69b5 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -181,10 +181,12 @@ Include = /etc/pacman.d/mirrorlist
 
 During parsing, pacman will define the `$repo` variable to the name of the
 current section. This is often utilized in files specified using the 'Include'
-directive so all repositories can use the same mirrorfile.
+directive so all repositories can use the same mirrorfile. pacman also defines
+the `$arch` variable to the value of `Architecture`, so the same mirrorfile can
+even be used for different architectures.
 
 --------
-Server = ftp://ftp.archlinux.org/$repo/os/arch
+Server = ftp://ftp.archlinux.org/$repo/os/$arch
 --------
 
 The order of repositories in the configuration files matters; repositories
diff --git a/etc/pacman.conf.in b/etc/pacman.conf.in
index 929d38b..fc841b7 100644
--- a/etc/pacman.conf.in
+++ b/etc/pacman.conf.in
@@ -42,6 +42,7 @@ Architecture = auto
 #   - repositories listed first will take precedence when packages
 #     have identical names, regardless of version number
 #   - URLs will have $repo replaced by the name of the current repo
+#   - URLs will have $arch replaced by the name of the architecture
 #
 # Repository entries are of the format:
 #       [repo-name]
@@ -57,7 +58,7 @@ Architecture = auto
 # servers immediately after the header and they will be used before the
 # default mirrors.
 #[core]
-#Server = ftp://ftp.example.com/foobar/$repo/os/i686/
+#Server = ftp://ftp.example.com/foobar/$repo/os/$arch/
 # The file referenced here should contain a list of 'Server = ' lines.
 #Include = @sysconfdir@/pacman.d/mirrorlist
 
diff --git a/scripts/rankmirrors.py.in b/scripts/rankmirrors.py.in
index 4b253b6..6bfa661 100644
--- a/scripts/rankmirrors.py.in
+++ b/scripts/rankmirrors.py.in
@@ -156,6 +156,8 @@ if __name__ == "__main__":
 
         # if the $repo var is used in the url, replace it by core
         tempUrl = Template(serverUrl).safe_substitute(repo='core')
+        # if the $arch var is used in the url, replace it by i686
+        tempUrl = Template(tempUrl).safe_substitute(arch='i686')
 
         # add @DBEXT@ to server name. the repo name is parsed
         # from the mirror url; it is the third (or fourth) dir
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 5fab247..6e5147c 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -897,7 +897,22 @@ static int _parseconfig(const char *file, const char *givensection,
 					}
 				} else if(strcmp(key, "Server") == 0) {
 					/* let's attempt a replacement for the current repo */
-					char *server = strreplace(ptr, "$repo", section);
+					char *temp = strreplace(ptr, "$repo", section);
+					/* let's attempt a replacement for the arch */
+					const char *arch = alpm_option_get_arch();
+					char *server;
+					if(arch) {
+						server = strreplace(temp, "$arch", arch);
+						free(temp);
+					} else {
+						if(strstr(temp, "$arch")) {
+							pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch"
+										" variable, but no Architecture is defined.\n"), ptr);
+							ret = 1;
+							goto cleanup;
+						}
+						server = temp;
+					}
 
 					if(alpm_db_setserver(db, server) != 0) {
 						/* pm_errno is set by alpm_db_setserver */
-- 
1.6.4



More information about the pacman-dev mailing list