diff --git a/NEWS b/NEWS index 3f4e28fe..0d6c841c 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ xbps-0.18 (???): + * The virtual package configuration files are now read dynamically + by libxbps at initialization time from default configuration directory: + /etc/xbps/virtualpkg.d. Only files that end in ".conf" will + be processed by libxbps. + + * The rootdir (with -r, --rootdir) can now be specified as relative path. + * Structured pkg metadata stored on disk, and added new functionality: - A single plist containing pkg properties, files and diff --git a/include/xbps_api.h.in b/include/xbps_api.h.in index 9b61a754..0503cb5c 100644 --- a/include/xbps_api.h.in +++ b/include/xbps_api.h.in @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.5" -#define XBPS_API_VERSION "20121119" +#define XBPS_API_VERSION "20121119-1" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" diff --git a/lib/initend.c b/lib/initend.c index 6b180bb8..767ea650 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -23,12 +23,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include #include #include #include -#include +#include #include "xbps_api_impl.h" @@ -69,6 +71,51 @@ set_metadir(struct xbps_handle *xh) } } +static void +config_inject_vpkgs(struct xbps_handle *xh) +{ + DIR *dirp; + struct dirent *dp; + char *ext, *vpkgdir; + FILE *fp; + + if (strcmp(xh->rootdir, "/")) + vpkgdir = xbps_xasprintf("%s/etc/xbps/virtualpkg.d", + xh->rootdir); + else + vpkgdir = strdup("/etc/xbps/virtualpkg.d"); + + if ((dirp = opendir(vpkgdir)) == NULL) { + xbps_dbg_printf(xh, "config: failed to open %s: %s\n", + vpkgdir, strerror(errno)); + return; + } + + while ((dp = readdir(dirp)) != NULL) { + if ((strcmp(dp->d_name, "..") == 0) || + (strcmp(dp->d_name, ".") == 0)) + continue; + /* only process .conf files, ignore something else */ + if ((ext = strrchr(dp->d_name, '.')) == NULL) + continue; + if (strcmp(ext, ".conf") == 0) { + char *path; + + path = xbps_xasprintf("%s/%s", vpkgdir, dp->d_name); + fp = fopen(path, "r"); + assert(fp); + free(path); + if (cfg_parse_fp(xh->cfg, fp) != 0) { + xbps_error_printf("Failed to parse " + "vpkg conf file %s:\n", dp->d_name); + } + fclose(fp); + } + } + closedir(dirp); + free(vpkgdir); +} + static int cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt) { @@ -156,6 +203,7 @@ xbps_init(struct xbps_handle *xhp) return ENOTSUP; } } + xbps_dbg_printf(xhp, "Configuration file: %s\n", xhp->conffile ? xhp->conffile : "not found"); /* @@ -216,6 +264,9 @@ xbps_init(struct xbps_handle *xhp) if (xhp->flags & XBPS_FLAG_SYSLOG) syslog_enabled = true; + /* Inject virtual packages from virtualpkg.d files */ + config_inject_vpkgs(xhp); + xbps_fetch_set_cache_connection(cc, cch); xbps_dbg_printf(xhp, "Rootdir=%s\n", xhp->rootdir);