1 |
commit: facaa636947ceeffce0c7a5a5dd52fee8e9175ca |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 3 15:40:42 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jun 3 15:40:42 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=facaa636 |
7 |
|
8 |
support repos.conf files |
9 |
|
10 |
Since the system is moving away from PORTDIR/etc... and to a more |
11 |
flexible repos.conf setup, make sure we support that stuff. |
12 |
|
13 |
This pulls in an external dependency which is new for us, but the |
14 |
iniparser library is very small (<20k on x86_64), written in pure |
15 |
C, and is used by big projects already (like samba). Doing an NIH |
16 |
thing here would be a waste of time. |
17 |
|
18 |
URL: https://bugs.gentoo.org/540620 |
19 |
Reported-by: Elias Probst <mail <AT> eliasprobst.eu> |
20 |
|
21 |
Makefile | 1 + |
22 |
main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
23 |
porting.h | 2 ++ |
24 |
3 files changed, 63 insertions(+), 7 deletions(-) |
25 |
|
26 |
diff --git a/Makefile b/Makefile |
27 |
index 7304559..fe6092f 100644 |
28 |
--- a/Makefile |
29 |
+++ b/Makefile |
30 |
@@ -24,6 +24,7 @@ DBG_CFLAGS = -O0 -DEBUG -g3 -ggdb -fno-pie $(call check_gcc, -fsanitize=address |
31 |
#CFLAGS += -Os -DOPTIMIZE_FOR_SIZE=2 -falign-functions=2 -falign-jumps=2 -falign-labels=2 -falign-loops=2 |
32 |
#LDFLAGS := -pie |
33 |
LIBADD += $(shell echo | $(CC) -dM -E - | grep -q ' __FreeBSD__' && echo '-lkvm') |
34 |
+LIBADD += -liniparser |
35 |
DESTDIR := |
36 |
PREFIX := $(DESTDIR)/usr |
37 |
STRIP := strip |
38 |
|
39 |
diff --git a/main.c b/main.c |
40 |
index 29a889f..cb180df 100644 |
41 |
--- a/main.c |
42 |
+++ b/main.c |
43 |
@@ -421,6 +421,57 @@ contents_entry *contents_parse_line(char *line) |
44 |
return &e; |
45 |
} |
46 |
|
47 |
+/* Handle a single file in the repos.conf format. */ |
48 |
+static void read_one_repos_conf(const char *repos_conf) |
49 |
+{ |
50 |
+ char *conf; |
51 |
+ const char *repo, *path; |
52 |
+ dictionary *dict; |
53 |
+ |
54 |
+ dict = iniparser_load(repos_conf); |
55 |
+ |
56 |
+ repo = iniparser_getstring(dict, "DEFAULT:main-repo", NULL); |
57 |
+ if (repo) { |
58 |
+ xasprintf(&conf, "%s:location", repo); |
59 |
+ path = iniparser_getstring(dict, conf, NULL); |
60 |
+ if (path) { |
61 |
+ free(portdir); |
62 |
+ portdir = xstrdup(path); |
63 |
+ } |
64 |
+ free(conf); |
65 |
+ } |
66 |
+ |
67 |
+ iniparser_freedict(dict); |
68 |
+} |
69 |
+ |
70 |
+/* Handle a possible directory of files. */ |
71 |
+static void read_repos_conf(const char *configroot, const char *repos_conf) |
72 |
+{ |
73 |
+ char *top_conf, *sub_conf; |
74 |
+ int i, count; |
75 |
+ struct dirent **confs; |
76 |
+ |
77 |
+ xasprintf(&top_conf, "%s%s", configroot, repos_conf); |
78 |
+ count = scandir(top_conf, &confs, NULL, alphasort); |
79 |
+ if (count == -1) { |
80 |
+ if (errno == ENOTDIR) |
81 |
+ read_one_repos_conf(top_conf); |
82 |
+ } else { |
83 |
+ for (i = 0; i < count; ++i) { |
84 |
+ const char *name = confs[i]->d_name; |
85 |
+ |
86 |
+ if (name[0] == '.' || confs[i]->d_type != DT_REG) |
87 |
+ continue; |
88 |
+ |
89 |
+ xasprintf(&sub_conf, "%s/%s", top_conf, name); |
90 |
+ read_one_repos_conf(sub_conf); |
91 |
+ free(sub_conf); |
92 |
+ } |
93 |
+ scandir_free(confs, count); |
94 |
+ } |
95 |
+ free(top_conf); |
96 |
+} |
97 |
+ |
98 |
static void strincr_var(const char *name, const char *s, char **value, size_t *value_len) |
99 |
{ |
100 |
size_t len; |
101 |
@@ -715,18 +766,18 @@ void initialize_portage_env(void) |
102 |
} |
103 |
|
104 |
/* figure out where to find our config files */ |
105 |
- s = getenv("PORTAGE_CONFIGROOT"); |
106 |
- if (!s) |
107 |
- s = "/"; |
108 |
+ const char *configroot = getenv("PORTAGE_CONFIGROOT"); |
109 |
+ if (!configroot) |
110 |
+ configroot = "/"; |
111 |
|
112 |
/* walk all the stacked profiles */ |
113 |
- read_portage_profile(s, CONFIG_EPREFIX "etc/make.profile", vars_to_read); |
114 |
- read_portage_profile(s, CONFIG_EPREFIX "etc/portage/make.profile", vars_to_read); |
115 |
+ read_portage_profile(configroot, CONFIG_EPREFIX "etc/make.profile", vars_to_read); |
116 |
+ read_portage_profile(configroot, CONFIG_EPREFIX "etc/portage/make.profile", vars_to_read); |
117 |
|
118 |
/* now read all the config files */ |
119 |
read_portage_env_file("", CONFIG_EPREFIX "usr/share/portage/config/make.globals", vars_to_read); |
120 |
- read_portage_env_file(s, CONFIG_EPREFIX "etc/make.conf", vars_to_read); |
121 |
- read_portage_env_file(s, CONFIG_EPREFIX "etc/portage/make.conf", vars_to_read); |
122 |
+ read_portage_env_file(configroot, CONFIG_EPREFIX "etc/make.conf", vars_to_read); |
123 |
+ read_portage_env_file(configroot, CONFIG_EPREFIX "etc/portage/make.conf", vars_to_read); |
124 |
|
125 |
/* finally, check the env */ |
126 |
for (i = 0; vars_to_read[i].name; ++i) { |
127 |
@@ -826,6 +877,8 @@ void initialize_portage_env(void) |
128 |
portroot[var->value_len + 1] = '\0'; |
129 |
} |
130 |
|
131 |
+ read_repos_conf(configroot, CONFIG_EPREFIX "etc/portage/repos.conf"); |
132 |
+ |
133 |
if (getenv("PORTAGE_QUIET") != NULL) |
134 |
quiet = 1; |
135 |
|
136 |
|
137 |
diff --git a/porting.h b/porting.h |
138 |
index 3235542..8045813 100644 |
139 |
--- a/porting.h |
140 |
+++ b/porting.h |
141 |
@@ -49,6 +49,8 @@ |
142 |
#include <sys/time.h> |
143 |
#include <sys/types.h> |
144 |
|
145 |
+#include <iniparser.h> |
146 |
+ |
147 |
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr))) |
148 |
|
149 |
#ifndef BUFSIZE |