From 776865b5484a8a7a0395a56bc8369c8380e7a827 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 31 May 2014 07:05:57 +0200 Subject: [PATCH] Added support for system/config virtualpkg.d directories. The system virtualpkg directory set to /usr/share/xbps/virtualpkg.d contains virtualpkg configuration files (.conf/.vpkg) that can be overrided by the admin in /etc/xbps/virtualpkg.d bearing the same file name. This obsoletes the "virtualpkgdir" keyword support from the xbps configuration file. --- NEWS | 14 +++++-- etc/xbps.conf | 13 +++---- include/xbps.h.in | 10 +---- lib/initend.c | 97 +++++++++++++++++++++++++++++------------------ 4 files changed, 79 insertions(+), 55 deletions(-) diff --git a/NEWS b/NEWS index 5b09654f..161f5e15 100644 --- a/NEWS +++ b/NEWS @@ -1,11 +1,19 @@ xbps-0.37 (???): + * Added support for system and configuration virtualpkg directories. + + The system virtualpkg directory set to /usr/share/xbps/virtualpkg.d contains + virtualpkg configuration files (.conf/.vpkg) that can be overrided by the admin + in /etc/xbps/virtualpkg.d bearing the same file name. + + This obsoletes the "virtualpkgdir" keyword support from the xbps configuration file. + * Added support for system and configuration repository directories, as explained in GH #39 (https://github.com/voidlinux/xbps/issues/39). - The system repository directory set to /share/xbps/repo.d contains - system repository configuration files (.conf) that can be overrided by the admin - in /xbps/repo.d bearing the same file name. + The system repository directory set to /usr/share/xbps/repo.d contains + repository configuration files (.conf) that can be overrided by the admin + in /etc/xbps/repo.d bearing the same file name. * xbps-create(8): new option `-t, --tags` to specify a list of tags (categories) the package should be part of. This is just for metadata diff --git a/etc/xbps.conf b/etc/xbps.conf index dca2364c..4bbfb8b5 100644 --- a/etc/xbps.conf +++ b/etc/xbps.conf @@ -60,16 +60,15 @@ syslog=true # separated by a dash, i.e 'foo-1.0_1". # - means a real package name (without any version). # +# The system virtualpkg directory is set to /usr/share/xbps/virtualpkg.d. +# The configuration virtualpkg directory is set to /etc/xbps/virtualpkg.d. +# +# Files bearing the same name in the configuration directory override the +# ones from the system directory. +# # By default we prefer the `dcron` package as default cron daemon. virtualpkg=cron-daemon-0_1:dcron -# Sets the virtual package directory looking for .vpkg files with -# virtual package settings (by using the `virtualpkg' keyword). -# -# If starts with / it's an absolute path, otherwise it's relative to rootdir. -# By default it's set to /etc/xbps/virtualpkg.d. -#virtualpkgdir=etc/xbps/virtualpkg.d - # You can also include additional files by using the "include" keyword. # This expects an absolute path to a file. #include=/path/to/another/file.conf diff --git a/include/xbps.h.in b/include/xbps.h.in index 9be73b51..47ad104d 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -48,7 +48,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20140530" +#define XBPS_API_VERSION "20140531" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -578,14 +578,6 @@ struct xbps_handle { * If unset, defaults to \a XBPS_CACHE_PATH (relative to rootdir). */ char metadir[XBPS_MAXPATH-1]; - /** - * @var virtualpkgdir - * - * Virtual packages directory, with configuration files to override - * system virtual packages. - * If unset, defaults to \a XBPS_VPKG_PATH (relative to rootdir). - */ - char virtualpkgdir[XBPS_MAXPATH-1]; /** * @var native_arch * diff --git a/lib/initend.c b/lib/initend.c index 71f1c43e..5b183c54 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -122,7 +122,6 @@ parse_option(char *buf, char **k, char **v) "cachedir", "syslog", "repository", - "virtualpkgdir", "virtualpkg", "include" }; @@ -233,10 +232,6 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested, bool vpkgconf xbps_dbg_printf(xhp, "%s: cachedir set to %s\n", path, v); snprintf(xhp->cachedir, sizeof(xhp->cachedir), "%s", v); - } else if (strcmp(k, "virtualpkgdir") == 0) { - xbps_dbg_printf(xhp, "%s: virtualpkgdir set to %s\n", - path, v); - snprintf(xhp->virtualpkgdir, sizeof(xhp->virtualpkgdir), "%s", v); } else if (strcmp(k, "syslog") == 0) { if (strcasecmp(v, "true") == 0) { xhp->syslog = true; @@ -277,33 +272,76 @@ parse_vpkgdir(struct xbps_handle *xhp) { DIR *dirp; struct dirent *dp; - char *ext; + char *ext, vpkgdir[PATH_MAX], conf[PATH_MAX]; int rv = 0; - if ((dirp = opendir(xhp->virtualpkgdir)) == NULL) - return 0; - - xbps_dbg_printf(xhp, "Processing virtualpkg directory: %s\n", xhp->virtualpkgdir); + /* + * Read all vpkg configuration files stored in the system + * virtualpkg.d directory. + */ + snprintf(vpkgdir, sizeof(vpkgdir), "%s/%s", + strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", XBPS_SYS_VPKG_PATH); + xbps_dbg_printf(xhp, "Processing system virtualpkg.d directory: %s\n", vpkgdir); + if ((dirp = opendir(vpkgdir)) == NULL) + goto stage2; while ((dp = readdir(dirp)) != NULL) { if ((strcmp(dp->d_name, "..") == 0) || (strcmp(dp->d_name, ".") == 0)) continue; - /* only process .vpkg files, ignore something else */ + /* only process .vpkg/.conf files, ignore something else */ if ((ext = strrchr(dp->d_name, '.')) == NULL) continue; - if (strcmp(ext, ".vpkg") == 0) { - char *path; - - path = xbps_xasprintf("%s/%s", xhp->virtualpkgdir, dp->d_name); - if ((rv = parse_file(xhp, path, false, true)) != 0) { - free(path); - break; - } - free(path); + if (strcmp(ext, ".conf") && strcmp(ext, ".vpkg")) { + xbps_dbg_printf(xhp, "%s: ignoring %s\n", vpkgdir, dp->d_name); + continue; + } + /* if the same file exists in configuration directory, ignore it */ + snprintf(conf, sizeof(conf), "%s/%s/%s", xhp->rootdir, XBPS_VPKG_PATH, dp->d_name); + if (access(conf, R_OK) == 0) { + xbps_dbg_printf(xhp, "%s: ignoring %s (exists in confdir)\n", vpkgdir, dp->d_name); + continue; + } + /* parse vpkg conf file */ + snprintf(conf, sizeof(conf), "%s/%s", vpkgdir, dp->d_name); + if ((rv = parse_file(xhp, conf, false, true)) != 0) { + break; } } closedir(dirp); + if (rv != 0) + return rv; + +stage2: + /* + * Read all vpkg configuration files stored in the configuration + * virtualpkg.d directory. + */ + snprintf(vpkgdir, sizeof(vpkgdir), "%s%s", + strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", XBPS_VPKG_PATH); + xbps_dbg_printf(xhp, "Processing configuration virtualpkg.d directory: %s\n", vpkgdir); + if ((dirp = opendir(vpkgdir)) == NULL) + return 0; + + while ((dp = readdir(dirp)) != NULL) { + if ((strcmp(dp->d_name, "..") == 0) || + (strcmp(dp->d_name, ".") == 0)) + continue; + /* only process .vpkg/.conf files, ignore something else */ + if ((ext = strrchr(dp->d_name, '.')) == NULL) + continue; + if (strcmp(ext, ".conf") && strcmp(ext, ".vpkg")) { + xbps_dbg_printf(xhp, "%s: ignoring %s\n", vpkgdir, dp->d_name); + continue; + } + /* parse vpkg conf file */ + snprintf(conf, sizeof(conf), "%s/%s", vpkgdir, dp->d_name); + if ((rv = parse_file(xhp, conf, false, true)) != 0) { + break; + } + } + closedir(dirp); + return rv; } @@ -361,7 +399,7 @@ stage2: 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) + if ((dirp = opendir(repodir)) == NULL) return 0; while ((dp = readdir(dirp)) != NULL) { @@ -446,23 +484,11 @@ xbps_init(struct xbps_handle *xhp) "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); free(buf); } - /* Set virtualpkgdir */ - if (xhp->virtualpkgdir[0] == '\0') { - snprintf(xhp->virtualpkgdir, sizeof(xhp->virtualpkgdir), - "%s%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", - XBPS_VPKG_PATH); - } else if (xhp->virtualpkgdir[0] != '/') { - /* relative path */ - buf = strdup(xhp->virtualpkgdir); - snprintf(xhp->virtualpkgdir, sizeof(xhp->virtualpkgdir), - "%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf); - free(buf); - } - /* parse virtualpkg */ + /* process virtualpkg.d dirs */ if ((rv = parse_vpkgdir(xhp))) return rv; - /* parse repodirs */ + /* process repo.d dirs */ if ((rv = parse_repodir(xhp)) != 0) return rv; @@ -480,7 +506,6 @@ xbps_init(struct xbps_handle *xhp) xbps_dbg_printf(xhp, "rootdir=%s\n", xhp->rootdir); xbps_dbg_printf(xhp, "metadir=%s\n", xhp->metadir); xbps_dbg_printf(xhp, "cachedir=%s\n", xhp->cachedir); - xbps_dbg_printf(xhp, "virtualpkgdir=%s\n", xhp->virtualpkgdir); xbps_dbg_printf(xhp, "syslog=%s\n", xhp->syslog ? "true" : "false"); xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->native_arch); xbps_dbg_printf(xhp, "Target Architecture: %s\n", xhp->target_arch);