From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0FF73138C9D for ; Wed, 3 Jun 2015 15:44:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A471BE09EF; Wed, 3 Jun 2015 15:44:09 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 40481E09EF for ; Wed, 3 Jun 2015 15:44:09 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E091E340D81 for ; Wed, 3 Jun 2015 15:44:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 02639A24 for ; Wed, 3 Jun 2015 15:44:03 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1433346042.facaa636947ceeffce0c7a5a5dd52fee8e9175ca.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: Makefile main.c porting.h X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: facaa636947ceeffce0c7a5a5dd52fee8e9175ca X-VCS-Branch: master Date: Wed, 3 Jun 2015 15:44:03 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: f87ef7ad-ec10-47ac-9bb5-674bbc1ff576 X-Archives-Hash: 452da83502542fcd84e7a1d7a4886e93 commit: facaa636947ceeffce0c7a5a5dd52fee8e9175ca Author: Mike Frysinger gentoo org> AuthorDate: Wed Jun 3 15:40:42 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Wed Jun 3 15:40:42 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=facaa636 support repos.conf files Since the system is moving away from PORTDIR/etc... and to a more flexible repos.conf setup, make sure we support that stuff. This pulls in an external dependency which is new for us, but the iniparser library is very small (<20k on x86_64), written in pure C, and is used by big projects already (like samba). Doing an NIH thing here would be a waste of time. URL: https://bugs.gentoo.org/540620 Reported-by: Elias Probst eliasprobst.eu> Makefile | 1 + main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- porting.h | 2 ++ 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7304559..fe6092f 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ DBG_CFLAGS = -O0 -DEBUG -g3 -ggdb -fno-pie $(call check_gcc, -fsanitize=address #CFLAGS += -Os -DOPTIMIZE_FOR_SIZE=2 -falign-functions=2 -falign-jumps=2 -falign-labels=2 -falign-loops=2 #LDFLAGS := -pie LIBADD += $(shell echo | $(CC) -dM -E - | grep -q ' __FreeBSD__' && echo '-lkvm') +LIBADD += -liniparser DESTDIR := PREFIX := $(DESTDIR)/usr STRIP := strip diff --git a/main.c b/main.c index 29a889f..cb180df 100644 --- a/main.c +++ b/main.c @@ -421,6 +421,57 @@ contents_entry *contents_parse_line(char *line) return &e; } +/* Handle a single file in the repos.conf format. */ +static void read_one_repos_conf(const char *repos_conf) +{ + char *conf; + const char *repo, *path; + dictionary *dict; + + dict = iniparser_load(repos_conf); + + repo = iniparser_getstring(dict, "DEFAULT:main-repo", NULL); + if (repo) { + xasprintf(&conf, "%s:location", repo); + path = iniparser_getstring(dict, conf, NULL); + if (path) { + free(portdir); + portdir = xstrdup(path); + } + free(conf); + } + + iniparser_freedict(dict); +} + +/* Handle a possible directory of files. */ +static void read_repos_conf(const char *configroot, const char *repos_conf) +{ + char *top_conf, *sub_conf; + int i, count; + struct dirent **confs; + + xasprintf(&top_conf, "%s%s", configroot, repos_conf); + count = scandir(top_conf, &confs, NULL, alphasort); + if (count == -1) { + if (errno == ENOTDIR) + read_one_repos_conf(top_conf); + } else { + for (i = 0; i < count; ++i) { + const char *name = confs[i]->d_name; + + if (name[0] == '.' || confs[i]->d_type != DT_REG) + continue; + + xasprintf(&sub_conf, "%s/%s", top_conf, name); + read_one_repos_conf(sub_conf); + free(sub_conf); + } + scandir_free(confs, count); + } + free(top_conf); +} + static void strincr_var(const char *name, const char *s, char **value, size_t *value_len) { size_t len; @@ -715,18 +766,18 @@ void initialize_portage_env(void) } /* figure out where to find our config files */ - s = getenv("PORTAGE_CONFIGROOT"); - if (!s) - s = "/"; + const char *configroot = getenv("PORTAGE_CONFIGROOT"); + if (!configroot) + configroot = "/"; /* walk all the stacked profiles */ - read_portage_profile(s, CONFIG_EPREFIX "etc/make.profile", vars_to_read); - read_portage_profile(s, CONFIG_EPREFIX "etc/portage/make.profile", vars_to_read); + read_portage_profile(configroot, CONFIG_EPREFIX "etc/make.profile", vars_to_read); + read_portage_profile(configroot, CONFIG_EPREFIX "etc/portage/make.profile", vars_to_read); /* now read all the config files */ read_portage_env_file("", CONFIG_EPREFIX "usr/share/portage/config/make.globals", vars_to_read); - read_portage_env_file(s, CONFIG_EPREFIX "etc/make.conf", vars_to_read); - read_portage_env_file(s, CONFIG_EPREFIX "etc/portage/make.conf", vars_to_read); + read_portage_env_file(configroot, CONFIG_EPREFIX "etc/make.conf", vars_to_read); + read_portage_env_file(configroot, CONFIG_EPREFIX "etc/portage/make.conf", vars_to_read); /* finally, check the env */ for (i = 0; vars_to_read[i].name; ++i) { @@ -826,6 +877,8 @@ void initialize_portage_env(void) portroot[var->value_len + 1] = '\0'; } + read_repos_conf(configroot, CONFIG_EPREFIX "etc/portage/repos.conf"); + if (getenv("PORTAGE_QUIET") != NULL) quiet = 1; diff --git a/porting.h b/porting.h index 3235542..8045813 100644 --- a/porting.h +++ b/porting.h @@ -49,6 +49,8 @@ #include #include +#include + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr))) #ifndef BUFSIZE