From 387987b14638a82a0db3dcb95928a31e3f71e078 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 31 May 2014 06:44:07 +0200 Subject: [PATCH] Make system/config repo.d paths always relative to rootdir. --- etc/xbps.conf | 9 +++++---- include/Makefile | 2 +- include/xbps.h.in | 12 +++++++++--- lib/initend.c | 39 +++++++++++++++++++++------------------ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/etc/xbps.conf b/etc/xbps.conf index aebae5ea..dca2364c 100644 --- a/etc/xbps.conf +++ b/etc/xbps.conf @@ -15,13 +15,13 @@ syslog=true ## REPOSITORIES # -# The default system repository directory "/share/xbps/repo.d" +# The default system repository directory "/usr/share/xbps/repo.d" # contains the system repository configuration files. # -# Files on that system directory can be overrided in "/xbps/repo.d" +# Files on that system directory can be overrided in "/etc/xbps/repo.d" # bearing the same file name, i.e: # -# - /xbps/repo.d/main.conf overrides /share/xbps/repo.d/main.conf +# - /etc/xbps/repo.d/main.conf overrides /usr/share/xbps/repo.d/main.conf # # Local or remote repositories are accepted. # @@ -31,7 +31,8 @@ syslog=true # - Repositories are added in the order in which are specified (top->bottom). # # The "repository" keyword can be used to include additional repositories in -# addition to the files available in /xbps/repo.d/*.conf. +# addition to the files available in /etc/xbps/repo.d/*.conf and +# /usr/share/xbps/repo.d/*.conf. # #repository= diff --git a/include/Makefile b/include/Makefile index 99adb27b..4b953bc5 100644 --- a/include/Makefile +++ b/include/Makefile @@ -4,7 +4,7 @@ INCS = xbps.h .PHONY: all all: - sed -e "s|@@VERSION@@|${VERSION}|g;s|@@PREFIX@@|${PREFIX}|g" ${INCS}.in > ${INCS} + sed -e "s|@@VERSION@@|${VERSION}|g" ${INCS}.in > ${INCS} .PHONY: install install: diff --git a/include/xbps.h.in b/include/xbps.h.in index f4bd8aec..9be73b51 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -73,7 +73,7 @@ # define XBPS_SYSCONF_PATH "/etc" XBPS_SYSDIR #endif #ifndef XBPS_SYSDEFCONF_PATH -# define XBPS_SYSDEFCONF_PATH "@@PREFIX@@/share" XBPS_SYSDIR +# define XBPS_SYSDEFCONF_PATH "usr/share" XBPS_SYSDIR #endif /** @@ -88,12 +88,18 @@ */ #define XBPS_CACHE_PATH "var/cache/xbps" -/** +/** * @def XBPS_VPKG_PATH - * Default virtualpkg PATH to store virtualpkg overrides. + * Configuration virtualpkg directory to store virtualpkg configuration files. */ #define XBPS_VPKG_PATH XBPS_SYSCONF_PATH "/virtualpkg.d" +/** + * @def XBPS_SYS_VPKG_PATH + * System virtualpkg PATH to store virtualpkg configuration files. + */ +#define XBPS_SYS_VPKG_PATH XBPS_SYSDEFCONF_PATH "/virtualpkg.d" + /** * @def XBPS_REPOD_PATH * Configuration directory to store repository configuration files. diff --git a/lib/initend.c b/lib/initend.c index 72ca539e..71f1c43e 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -312,17 +312,18 @@ parse_repodir(struct xbps_handle *xhp) { DIR *dirp; struct dirent *dp; - char *ext, conf[PATH_MAX]; + char *ext, repodir[PATH_MAX], conf[PATH_MAX]; int rv = 0; /* * Read all repository configuration files stored in the system * repo.d directory. */ - if ((dirp = opendir(XBPS_SYS_REPOD_PATH)) == NULL) - return 0; - - xbps_dbg_printf(xhp, "Processing system repo.d directory: %s\n", XBPS_SYS_REPOD_PATH); + snprintf(repodir, sizeof(repodir), "%s/%s", + strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", XBPS_SYS_REPOD_PATH); + xbps_dbg_printf(xhp, "Processing system repo.d directory: %s\n", repodir); + if ((dirp = opendir(repodir)) == NULL) + goto stage2; while ((dp = readdir(dirp)) != NULL) { if ((strcmp(dp->d_name, "..") == 0) || @@ -333,17 +334,17 @@ parse_repodir(struct xbps_handle *xhp) if ((ext = strrchr(dp->d_name, '.')) == NULL) continue; if (strcmp(ext, ".conf")) { - xbps_dbg_printf(xhp, "%s: ignoring %s\n", XBPS_SYS_REPOD_PATH, dp->d_name); + xbps_dbg_printf(xhp, "%s: ignoring %s\n", repodir, dp->d_name); continue; } /* if the same file exists in configuration directory, ignore it */ - snprintf(conf, sizeof(conf), "%s/%s", XBPS_REPOD_PATH, dp->d_name); + snprintf(conf, sizeof(conf), "%s/%s/%s", xhp->rootdir, XBPS_REPOD_PATH, dp->d_name); if (access(conf, R_OK) == 0) { - xbps_dbg_printf(xhp, "%s: ignoring %s (exists in confdir)\n", XBPS_SYS_REPOD_PATH, dp->d_name); + xbps_dbg_printf(xhp, "%s: ignoring %s (exists in confdir)\n", repodir, dp->d_name); continue; } /* parse repo conf file */ - snprintf(conf, sizeof(conf), "%s/%s", XBPS_SYS_REPOD_PATH, dp->d_name); + snprintf(conf, sizeof(conf), "%s/%s", repodir, dp->d_name); if ((rv = parse_file(xhp, conf, false, false)) != 0) { break; } @@ -352,15 +353,17 @@ parse_repodir(struct xbps_handle *xhp) if (rv != 0) return rv; +stage2: /* * Read all repository configuration files stored in the configuration * repo.d directory. */ + snprintf(repodir, sizeof(repodir), "%s%s", + strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", XBPS_REPOD_PATH); + xbps_dbg_printf(xhp, "Processing configuration repo.d directory: %s\n", repodir); if ((dirp = opendir(XBPS_REPOD_PATH)) == NULL) return 0; - xbps_dbg_printf(xhp, "Processing configuration repo.d directory: %s\n", XBPS_REPOD_PATH); - while ((dp = readdir(dirp)) != NULL) { if ((strcmp(dp->d_name, "..") == 0) || (strcmp(dp->d_name, ".") == 0)) @@ -370,11 +373,11 @@ parse_repodir(struct xbps_handle *xhp) if ((ext = strrchr(dp->d_name, '.')) == NULL) continue; if (strcmp(ext, ".conf")) { - xbps_dbg_printf(xhp, "%s: ignoring %s\n", XBPS_REPOD_PATH, dp->d_name); + xbps_dbg_printf(xhp, "%s: ignoring %s\n", repodir, dp->d_name); continue; } /* parse repo conf file */ - snprintf(conf, sizeof(conf), "%s/%s", XBPS_REPOD_PATH, dp->d_name); + snprintf(conf, sizeof(conf), "%s/%s", repodir, dp->d_name); if ((rv = parse_file(xhp, conf, false, false)) != 0) { break; } @@ -397,10 +400,6 @@ xbps_init(struct xbps_handle *xhp) if (xhp->conffile == NULL) xhp->conffile = XBPS_CONF_DEF; - /* parse repository configuration files */ - if ((rv = parse_repodir(xhp)) != 0) { - xbps_dbg_printf(xhp, "failed to parse repo.d files: %s\n", strerror(rv)); - } /* parse configuration file */ if ((rv = parse_file(xhp, xhp->conffile, false, false)) != 0) { xbps_dbg_printf(xhp, "failed to read configuration file %s: %s\n", @@ -459,10 +458,14 @@ xbps_init(struct xbps_handle *xhp) "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); free(buf); } - /* parse virtualpkgdir */ + /* parse virtualpkg */ if ((rv = parse_vpkgdir(xhp))) return rv; + /* parse repodirs */ + if ((rv = parse_repodir(xhp)) != 0) + return rv; + xhp->target_arch = getenv("XBPS_TARGET_ARCH"); if ((native_arch = getenv("XBPS_ARCH")) != NULL) { strlcpy(xhp->native_arch, native_arch, sizeof(xhp->native_arch));