Files in the configuration directory have preference.

This commit is contained in:
Juan RP 2014-12-09 12:05:18 +01:00
parent 395e147c6c
commit 16d2640df8
2 changed files with 32 additions and 24 deletions

View File

@ -22,6 +22,13 @@ overrides settings from files available in the
.Sy system configuration .Sy system configuration
directory, by default set to directory, by default set to
.Sy /usr/share/xbps.d . .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 Only files with the
.Em .conf .Em .conf
extension will be processed in alphabetical order. 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 A complete url or absolute path to the directory that stores the
.Em <arch>-repodata .Em <arch>-repodata
archive is expected, example: archive is expected, example:
.Pp
.Bl -tag -compact -width repository=http://repo.voidlinux.eu/current .Bl -tag -compact -width repository=http://repo.voidlinux.eu/current
.It Sy repository=http://repo.voidlinux.eu/current .It Sy repository=http://repo.voidlinux.eu/current
.It Sy repository=/hostdir/binpkgs .It Sy repository=/hostdir/binpkgs
@ -78,7 +86,7 @@ Sets the default root directory.
Enables or disables syslog logging. Enabled by default. Enables or disables syslog logging. Enabled by default.
.It Sy virtualpkg=vpkgver:pkgname .It Sy virtualpkg=vpkgver:pkgname
Declares a virtual package. A virtual package declaration is composed by two 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 .Pp
.Bl -tag -compact -width virtualpkg=cron-daemon-1.0_1:dcron .Bl -tag -compact -width virtualpkg=cron-daemon-1.0_1:dcron
.It Sy virtualpkg=cron-daemon-1.0_1:dcron .It Sy virtualpkg=cron-daemon-1.0_1:dcron

View File

@ -308,21 +308,21 @@ parse_file(struct xbps_handle *xhp, const char *cwd, const char *path, bool nest
} }
static int 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; struct dirent **namelist;
char *ext, conf[PATH_MAX]; char *ext, conf[PATH_MAX];
int i, n, rv = 0; int i, n, rv = 0;
if (dir == NULL) if (confdir == NULL)
goto stage2; goto stage2;
/* /*
* Read all configuration files stored in the system * Read all configuration files stored in the system
* foo.d directory. * 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; goto stage2;
for (i = 0; i < n; i++) { 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]); free(namelist[i]);
continue; continue;
} }
/* only process .vpkg/.conf files, ignore something else */ /* only process .conf files, ignore something else */
if ((ext = strrchr(namelist[i]->d_name, '.')) == NULL) { if ((ext = strrchr(namelist[i]->d_name, '.')) == NULL) {
free(namelist[i]); free(namelist[i]);
continue; continue;
} }
if (strcmp(ext, ".conf") && strcmp(ext, ".vpkg")) { if (strcmp(ext, ".conf")) {
xbps_dbg_printf(xhp, "%s: ignoring %s\n", dir, namelist[i]->d_name); xbps_dbg_printf(xhp, "%s: ignoring %s\n", confdir, 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);
free(namelist[i]); free(namelist[i]);
continue; continue;
} }
/* parse conf file */ /* 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) { if ((rv = parse_file(xhp, cwd, conf, false)) != 0) {
free(namelist[i]); free(namelist[i]);
break; break;
@ -360,15 +353,15 @@ parse_dir(struct xbps_handle *xhp, const char *cwd, const char *dir, const char
return rv; return rv;
stage2: stage2:
if (confdir == NULL) if (sysconfdir == NULL)
return rv; return rv;
/* /*
* Read all configuration files stored in the configuration foo.d directory. * 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; return 0;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
@ -377,18 +370,25 @@ stage2:
free(namelist[i]); free(namelist[i]);
continue; continue;
} }
/* only process .vpkg/.conf files, ignore something else */ /* only process .conf files, ignore something else */
if ((ext = strrchr(namelist[i]->d_name, '.')) == NULL) { if ((ext = strrchr(namelist[i]->d_name, '.')) == NULL) {
free(namelist[i]); free(namelist[i]);
continue; continue;
} }
if (strcmp(ext, ".conf") && strcmp(ext, ".vpkg")) { if (strcmp(ext, ".conf")) {
xbps_dbg_printf(xhp, "%s: ignoring %s\n", confdir, namelist[i]->d_name); 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]); free(namelist[i]);
continue; continue;
} }
/* parse conf file */ /* 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) { if ((rv = parse_file(xhp, cwd, conf, false)) != 0) {
free(namelist[i]); free(namelist[i]);
break; break;
@ -476,7 +476,7 @@ xbps_init(struct xbps_handle *xhp)
xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, XBPS_FETCH_CACHECONN_HOST); xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, XBPS_FETCH_CACHECONN_HOST);
/* process xbps.d */ /* 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; return rv;
xbps_dbg_printf(xhp, "rootdir=%s\n", xhp->rootdir); xbps_dbg_printf(xhp, "rootdir=%s\n", xhp->rootdir);