From 16d2640df85816a3d4b4a9eb7fe3592194013b00 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 9 Dec 2014 12:05:18 +0100 Subject: [PATCH] Files in the configuration directory have preference. --- data/xbps.d.5 | 10 +++++++++- lib/initend.c | 46 +++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/data/xbps.d.5 b/data/xbps.d.5 index a8ebc112..7643da43 100644 --- a/data/xbps.d.5 +++ b/data/xbps.d.5 @@ -22,6 +22,13 @@ overrides settings from files available in the .Sy system configuration directory, by default set to .Sy /usr/share/xbps.d . +.Pp +Files in the +.Sy configuration +directory have preference over files in the +.Sy system configuration +directory. +.Pp Only files with the .Em .conf extension will be processed in alphabetical order. @@ -68,6 +75,7 @@ argument accepts local and remote repositories. A complete url or absolute path to the directory that stores the .Em -repodata archive is expected, example: +.Pp .Bl -tag -compact -width repository=http://repo.voidlinux.eu/current .It Sy repository=http://repo.voidlinux.eu/current .It Sy repository=/hostdir/binpkgs @@ -78,7 +86,7 @@ Sets the default root directory. Enables or disables syslog logging. Enabled by default. .It Sy virtualpkg=vpkgver:pkgname Declares a virtual package. A virtual package declaration is composed by two -components delimited by a colon, i.e: +components delimited by a colon, example: .Pp .Bl -tag -compact -width virtualpkg=cron-daemon-1.0_1:dcron .It Sy virtualpkg=cron-daemon-1.0_1:dcron diff --git a/lib/initend.c b/lib/initend.c index d8f670af..99ee2462 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -308,21 +308,21 @@ parse_file(struct xbps_handle *xhp, const char *cwd, const char *path, bool nest } static int -parse_dir(struct xbps_handle *xhp, const char *cwd, const char *dir, const char *confdir) +parse_dir(struct xbps_handle *xhp, const char *cwd, const char *confdir, const char *sysconfdir) { struct dirent **namelist; char *ext, conf[PATH_MAX]; int i, n, rv = 0; - if (dir == NULL) + if (confdir == NULL) goto stage2; /* * Read all configuration files stored in the system * foo.d directory. */ - xbps_dbg_printf(xhp, "Processing system directory: %s\n", dir); + xbps_dbg_printf(xhp, "Processing configuration directory: %s\n", confdir); - if ((n = scandir(dir, &namelist, 0, alphasort)) < 0) + if ((n = scandir(confdir, &namelist, 0, alphasort)) < 0) goto stage2; for (i = 0; i < n; i++) { @@ -331,25 +331,18 @@ parse_dir(struct xbps_handle *xhp, const char *cwd, const char *dir, const char free(namelist[i]); continue; } - /* only process .vpkg/.conf files, ignore something else */ + /* only process .conf files, ignore something else */ if ((ext = strrchr(namelist[i]->d_name, '.')) == NULL) { free(namelist[i]); continue; } - if (strcmp(ext, ".conf") && strcmp(ext, ".vpkg")) { - xbps_dbg_printf(xhp, "%s: ignoring %s\n", dir, namelist[i]->d_name); - free(namelist[i]); - continue; - } - /* if the same file exists in configuration directory, ignore it */ - snprintf(conf, sizeof(conf), "%s/%s", confdir, namelist[i]->d_name); - if (access(conf, R_OK) == 0) { - xbps_dbg_printf(xhp, "%s: ignoring %s (exists in confdir)\n", dir, namelist[i]->d_name); + if (strcmp(ext, ".conf")) { + xbps_dbg_printf(xhp, "%s: ignoring %s\n", confdir, namelist[i]->d_name); free(namelist[i]); continue; } /* parse conf file */ - snprintf(conf, sizeof(conf), "%s/%s", dir, namelist[i]->d_name); + snprintf(conf, sizeof(conf), "%s/%s", confdir, namelist[i]->d_name); if ((rv = parse_file(xhp, cwd, conf, false)) != 0) { free(namelist[i]); break; @@ -360,15 +353,15 @@ parse_dir(struct xbps_handle *xhp, const char *cwd, const char *dir, const char return rv; stage2: - if (confdir == NULL) + if (sysconfdir == NULL) return rv; /* * Read all configuration files stored in the configuration foo.d directory. */ - xbps_dbg_printf(xhp, "Processing configuration directory: %s\n", confdir); + xbps_dbg_printf(xhp, "Processing system configuration directory: %s\n", sysconfdir); - if ((n = scandir(confdir, &namelist, 0, alphasort)) < 0) + if ((n = scandir(sysconfdir, &namelist, 0, alphasort)) < 0) return 0; for (i = 0; i < n; i++) { @@ -377,18 +370,25 @@ stage2: free(namelist[i]); continue; } - /* only process .vpkg/.conf files, ignore something else */ + /* only process .conf files, ignore something else */ if ((ext = strrchr(namelist[i]->d_name, '.')) == NULL) { free(namelist[i]); continue; } - if (strcmp(ext, ".conf") && strcmp(ext, ".vpkg")) { - xbps_dbg_printf(xhp, "%s: ignoring %s\n", confdir, namelist[i]->d_name); + if (strcmp(ext, ".conf")) { + xbps_dbg_printf(xhp, "%s: ignoring %s\n", sysconfdir, namelist[i]->d_name); + free(namelist[i]); + continue; + } + /* if the same file exists in configuration directory, ignore it */ + snprintf(conf, sizeof(conf), "%s/%s", confdir, namelist[i]->d_name); + if (access(conf, R_OK) == 0) { + xbps_dbg_printf(xhp, "%s: ignoring %s (exists in confdir)\n", confdir, namelist[i]->d_name); free(namelist[i]); continue; } /* parse conf file */ - snprintf(conf, sizeof(conf), "%s/%s", confdir, namelist[i]->d_name); + snprintf(conf, sizeof(conf), "%s/%s", sysconfdir, namelist[i]->d_name); if ((rv = parse_file(xhp, cwd, conf, false)) != 0) { free(namelist[i]); break; @@ -476,7 +476,7 @@ xbps_init(struct xbps_handle *xhp) xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, XBPS_FETCH_CACHECONN_HOST); /* process xbps.d */ - if ((rv = parse_dir(xhp, cwd, sysconfdir, xhp->confdir)) != 0) + if ((rv = parse_dir(xhp, cwd, xhp->confdir, sysconfdir)) != 0) return rv; xbps_dbg_printf(xhp, "rootdir=%s\n", xhp->rootdir);